summaryrefslogtreecommitdiffstats
path: root/slobrok
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2017-10-27 20:42:27 +0000
committerTor Egge <Tor.Egge@oath.com>2017-10-27 20:42:27 +0000
commit7e0ce424c29f5ee4a89c5c4a989fe2538cc9078d (patch)
tree480e467c684d1b6d9639d40ec589c73c0367e5f4 /slobrok
parent86730de554af723ffd5e4d57b7e3e4d54cb61c0f (diff)
Use std::mutex instead of FastOS_Mutex in slobrok and vespalog modules.
Diffstat (limited to 'slobrok')
-rw-r--r--slobrok/src/tests/oldapi/mirror.cpp12
-rw-r--r--slobrok/src/tests/oldapi/mirror.h2
-rw-r--r--slobrok/src/vespa/slobrok/sbregister.cpp47
-rw-r--r--slobrok/src/vespa/slobrok/sbregister.h2
4 files changed, 30 insertions, 33 deletions
diff --git a/slobrok/src/tests/oldapi/mirror.cpp b/slobrok/src/tests/oldapi/mirror.cpp
index e0904fe3a00..2004620d57b 100644
--- a/slobrok/src/tests/oldapi/mirror.cpp
+++ b/slobrok/src/tests/oldapi/mirror.cpp
@@ -54,14 +54,13 @@ MirrorOld::SpecList
MirrorOld::lookup(const std::string & pattern) const
{
SpecList ret;
- _lock.Lock();
+ std::lock_guard<std::mutex> guard(_lock);
SpecList::const_iterator end = _specs.end();
for (SpecList::const_iterator it = _specs.begin(); it != end; ++it) {
if (match(it->first.c_str(), pattern.c_str())) {
ret.push_back(*it);
}
}
- _lock.Unlock();
return ret;
}
@@ -119,10 +118,11 @@ MirrorOld::PerformTask()
std::string(s[idx]._str)));
}
- _lock.Lock();
- std::swap(specs, _specs);
- _updates.add();
- _lock.Unlock();
+ {
+ std::lock_guard<std::mutex> guard(_lock);
+ std::swap(specs, _specs);
+ _updates.add();
+ }
_specsGen.setFromInt(answer[2]._intval32);
}
_backOff.reset();
diff --git a/slobrok/src/tests/oldapi/mirror.h b/slobrok/src/tests/oldapi/mirror.h
index de680641c89..fb150b5d64f 100644
--- a/slobrok/src/tests/oldapi/mirror.h
+++ b/slobrok/src/tests/oldapi/mirror.h
@@ -111,7 +111,7 @@ private:
void RequestDone(FRT_RPCRequest *req) override;
FRT_Supervisor &_orb;
- mutable FastOS_Mutex _lock;
+ mutable std::mutex _lock;
bool _reqDone;
SpecList _specs;
vespalib::GenCnt _specsGen;
diff --git a/slobrok/src/vespa/slobrok/sbregister.cpp b/slobrok/src/vespa/slobrok/sbregister.cpp
index 748ec198bc3..a2ec4a4a7b2 100644
--- a/slobrok/src/vespa/slobrok/sbregister.cpp
+++ b/slobrok/src/vespa/slobrok/sbregister.cpp
@@ -96,10 +96,9 @@ RegisterAPI::~RegisterAPI()
void
RegisterAPI::registerName(const vespalib::stringref & name)
{
- _lock.Lock();
+ std::lock_guard<std::mutex> guard(_lock);
for (uint32_t i = 0; i < _names.size(); ++i) {
if (_names[i] == name) {
- _lock.Unlock();
return;
}
}
@@ -108,20 +107,18 @@ RegisterAPI::registerName(const vespalib::stringref & name)
_pending.push_back(name);
discard(_unreg, name);
ScheduleNow();
- _lock.Unlock();
}
void
RegisterAPI::unregisterName(const vespalib::stringref & name)
{
- _lock.Lock();
+ std::lock_guard<std::mutex> guard(_lock);
_busy = true;
discard(_names, name);
discard(_pending, name);
_unreg.push_back(name);
ScheduleNow();
- _lock.Unlock();
}
// handle any request that completed
@@ -176,11 +173,12 @@ RegisterAPI::handleReconnect()
// try next possible server.
_target = _orb.GetTarget(_currSlobrok.c_str());
}
- _lock.Lock();
- // now that we have a new connection, we need to
- // immediately re-register everything.
- _pending = _names;
- _lock.Unlock();
+ {
+ std::lock_guard<std::mutex> guard(_lock);
+ // now that we have a new connection, we need to
+ // immediately re-register everything.
+ _pending = _names;
+ }
if (_target == 0) {
// we have tried all possible servers.
// start from the top after a delay,
@@ -206,18 +204,19 @@ RegisterAPI::handlePending()
bool unreg = false;
bool reg = false;
vespalib::string name;
- _lock.Lock();
- // pop off the todo stack, unregister has priority
- if (_unreg.size() > 0) {
- name = _unreg.back();
- _unreg.pop_back();
- unreg = true;
- } else if (_pending.size() > 0) {
- name = _pending.back();
- _pending.pop_back();
- reg = true;
+ {
+ std::lock_guard<std::mutex> guard(_lock);
+ // pop off the todo stack, unregister has priority
+ if (_unreg.size() > 0) {
+ name = _unreg.back();
+ _unreg.pop_back();
+ unreg = true;
+ } else if (_pending.size() > 0) {
+ name = _pending.back();
+ _pending.pop_back();
+ reg = true;
+ }
}
- _lock.Unlock();
if (unreg) {
// start a new unregister request
@@ -239,12 +238,11 @@ RegisterAPI::handlePending()
} else {
// nothing more to do right now; schedule to re-register all
// names after a long delay.
- _lock.Lock();
+ std::lock_guard<std::mutex> guard(_lock);
_pending = _names;
LOG(debug, "done, reschedule in 30s");
_busy = false;
Schedule(30.0);
- _lock.Unlock();
}
}
@@ -301,12 +299,11 @@ void
RegisterAPI::RPCHooks::rpc_listNamesServed(FRT_RPCRequest *req)
{
FRT_Values &dst = *req->GetReturn();
- _owner._lock.Lock();
+ std::lock_guard<std::mutex> guard(_owner._lock);
FRT_StringValue *names = dst.AddStringArray(_owner._names.size());
for (uint32_t i = 0; i < _owner._names.size(); ++i) {
dst.SetString(&names[i], _owner._names[i].c_str());
}
- _owner._lock.Unlock();
}
diff --git a/slobrok/src/vespa/slobrok/sbregister.h b/slobrok/src/vespa/slobrok/sbregister.h
index de9f8ed8923..d8812c0f3d0 100644
--- a/slobrok/src/vespa/slobrok/sbregister.h
+++ b/slobrok/src/vespa/slobrok/sbregister.h
@@ -84,7 +84,7 @@ private:
FRT_Supervisor &_orb;
RPCHooks _hooks;
- FastOS_Mutex _lock;
+ std::mutex _lock;
bool _reqDone;
bool _busy;
SlobrokList _slobrokSpecs;