diff options
author | Tor Brede Vekterli <vekterli@oath.com> | 2019-01-10 14:55:39 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@oath.com> | 2019-01-10 14:55:39 +0000 |
commit | 7e25bca7899370ee5aeb7bc9f6a5877fe0c8d281 (patch) | |
tree | 997747637e6f23b58a4960774d562ad459925c59 /slobrok | |
parent | 19852a059409d9f02ec4d967beb2e88b7dce1d44 (diff) |
Make slobrok RegisterAPI busy flag polling data race free
Diffstat (limited to 'slobrok')
-rw-r--r-- | slobrok/src/vespa/slobrok/sbregister.cpp | 8 | ||||
-rw-r--r-- | slobrok/src/vespa/slobrok/sbregister.h | 5 |
2 files changed, 7 insertions, 6 deletions
diff --git a/slobrok/src/vespa/slobrok/sbregister.cpp b/slobrok/src/vespa/slobrok/sbregister.cpp index a1346feeece..72be5f69538 100644 --- a/slobrok/src/vespa/slobrok/sbregister.cpp +++ b/slobrok/src/vespa/slobrok/sbregister.cpp @@ -102,7 +102,7 @@ RegisterAPI::registerName(vespalib::stringref name) return; } } - _busy = true; + _busy.store(true, std::memory_order_relaxed); _names.push_back(name); _pending.push_back(name); discard(_unreg, name); @@ -114,7 +114,7 @@ void RegisterAPI::unregisterName(vespalib::stringref name) { std::lock_guard<std::mutex> guard(_lock); - _busy = true; + _busy.store(true, std::memory_order_relaxed); discard(_names, name); discard(_pending, name); _unreg.push_back(name); @@ -137,7 +137,7 @@ RegisterAPI::handleReqDone() _target->SubRef(); } _target = 0; - _busy = true; + _busy.store(true, std::memory_order_relaxed); } else { LOG(warning, "%s(%s -> %s) failed: %s", _req->GetMethodName(), @@ -241,7 +241,7 @@ RegisterAPI::handlePending() std::lock_guard<std::mutex> guard(_lock); _pending = _names; LOG(debug, "done, reschedule in 30s"); - _busy = false; + _busy.store(false, std::memory_order_relaxed); Schedule(30.0); } } diff --git a/slobrok/src/vespa/slobrok/sbregister.h b/slobrok/src/vespa/slobrok/sbregister.h index 234e6c076d4..8e8614fdf0a 100644 --- a/slobrok/src/vespa/slobrok/sbregister.h +++ b/slobrok/src/vespa/slobrok/sbregister.h @@ -6,6 +6,7 @@ #include "cfg.h" #include <vespa/fnet/frt/invoker.h> #include <vespa/fnet/frt/invokable.h> +#include <atomic> class FRT_Target; @@ -53,7 +54,7 @@ public: * * @return true if there are outstanding registration requests **/ - bool busy() const { return _busy; } + bool busy() const { return _busy.load(std::memory_order_relaxed); } private: class RPCHooks: public FRT_Invokable @@ -86,7 +87,7 @@ private: RPCHooks _hooks; std::mutex _lock; bool _reqDone; - bool _busy; + std::atomic<bool> _busy; SlobrokList _slobrokSpecs; Configurator::UP _configurator; vespalib::string _currSlobrok; |