diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2017-10-26 22:40:21 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2017-10-27 08:50:16 +0000 |
commit | 8763d2e0eb9155bf7b45645163ac01acef3f25ad (patch) | |
tree | c16d83d8ff5a07957dfbe7c14dfe1253eca54265 /searchlib | |
parent | 617a80d8da9d7714f13512b3f93c3b23de17a42f (diff) |
Use std::mutex and std::condition_variable instead of FastOS_Cond.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/postinglistbm/andstress.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/searchlib/src/tests/postinglistbm/andstress.cpp b/searchlib/src/tests/postinglistbm/andstress.cpp index d28efb9c0e2..736d53508b4 100644 --- a/searchlib/src/tests/postinglistbm/andstress.cpp +++ b/searchlib/src/tests/postinglistbm/andstress.cpp @@ -13,6 +13,8 @@ #include <vespa/searchlib/test/fakedata/fakezcbfilterocc.h> #include <vespa/searchlib/test/fakedata/fpfactory.h> #include <vespa/fastos/thread.h> +#include <mutex> +#include <condition_variable> #include <vespa/log/log.h> LOG_SETUP(".andstress"); @@ -51,7 +53,8 @@ private: std::vector<std::vector<FakePosting::SP> > _postings; - FastOS_Cond _taskCond; + std::mutex _taskLock; + std::condition_variable _taskCond; unsigned int _taskIdx; uint32_t _numTasks; @@ -135,6 +138,7 @@ AndStressMaster::AndStressMaster(search::Rand48 &rnd, _workersDone(0), _wordSet(wordSet), _postings(FakeWordSet::NUM_WORDCLASSES), + _taskLock(), _taskCond(), _taskIdx(0), _numTasks(numTasks), @@ -276,16 +280,15 @@ AndStressMaster::Task * AndStressMaster::getTask() { Task *result = NULL; - _taskCond.Lock(); + std::unique_lock<std::mutex> taskGuard(_taskLock); if (_taskIdx < _tasks.size()) { result = &_tasks[_taskIdx]; ++_taskIdx; } else { _workersDone++; if (_workersDone == _workers.size()) - _taskCond.Broadcast(); + _taskCond.notify_all(); } - _taskCond.Unlock(); return result; } @@ -329,10 +332,11 @@ AndStressMaster::runWorkers(const std::string &postingFormat) for (unsigned int i = 0; i < _workers.size(); ++i) _threadPool->NewThread(_workers[i]); - _taskCond.Lock(); - while (_workersDone < _workers.size()) - _taskCond.Wait(); - _taskCond.Unlock(); + { + std::unique_lock<std::mutex> taskGuard(_taskLock); + while (_workersDone < _workers.size()) + _taskCond.wait(taskGuard); + } tv.SetNow(); after = tv.Secs(); LOG(info, |