Commit 6e0b8159 authored by zhujiashun's avatar zhujiashun

revived_from_all_failed: optimize lock

parent 6cb4475a
...@@ -42,8 +42,7 @@ public: ...@@ -42,8 +42,7 @@ public:
struct GetNamingServiceThreadOptions { struct GetNamingServiceThreadOptions {
GetNamingServiceThreadOptions() GetNamingServiceThreadOptions()
: succeed_without_server(false) : succeed_without_server(false)
, log_succeed_without_server(true) , log_succeed_without_server(true) {}
, minimum_working_instances(-1) {}
bool succeed_without_server; bool succeed_without_server;
bool log_succeed_without_server; bool log_succeed_without_server;
......
...@@ -45,19 +45,17 @@ void DefaultRevivePolicy::StartReviving() { ...@@ -45,19 +45,17 @@ void DefaultRevivePolicy::StartReviving() {
} }
bool DefaultRevivePolicy::StopRevivingIfNecessary() { bool DefaultRevivePolicy::StopRevivingIfNecessary() {
int64_t now_ms = butil::gettimeofday_ms();
if (!_reviving) { if (!_reviving) {
return false; return false;
} }
{ int64_t now_ms = butil::gettimeofday_ms();
std::unique_lock<butil::Mutex> mu(_mutex); std::unique_lock<butil::Mutex> mu(_mutex);
if (_last_usable_change_time_ms != 0 && _last_usable != 0 && if (_last_usable_change_time_ms != 0 && _last_usable != 0 &&
(now_ms - _last_usable_change_time_ms > _hold_time_ms)) { (now_ms - _last_usable_change_time_ms > _hold_time_ms)) {
_reviving = false; _reviving = false;
_last_usable_change_time_ms = 0; _last_usable_change_time_ms = 0;
mu.unlock(); mu.unlock();
return false; return false;
}
} }
return true; return true;
} }
...@@ -76,9 +74,11 @@ int DefaultRevivePolicy::GetUsableServerCount( ...@@ -76,9 +74,11 @@ int DefaultRevivePolicy::GetUsableServerCount(
usable++; usable++;
} }
} }
std::unique_lock<butil::Mutex> mu(_mutex); {
_usable_cache = usable; std::unique_lock<butil::Mutex> mu(_mutex);
_usable_cache_time_ms = now_ms; _usable_cache = usable;
_usable_cache_time_ms = now_ms;
}
return _usable_cache; return _usable_cache;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment