From 8763d2e0eb9155bf7b45645163ac01acef3f25ad Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Thu, 26 Oct 2017 22:40:21 +0200 Subject: Use std::mutex and std::condition_variable instead of FastOS_Cond. --- searchlib/src/tests/postinglistbm/andstress.cpp | 20 ++++++++++++-------- 1 file 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 #include #include +#include +#include #include LOG_SETUP(".andstress"); @@ -51,7 +53,8 @@ private: std::vector > _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 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 taskGuard(_taskLock); + while (_workersDone < _workers.size()) + _taskCond.wait(taskGuard); + } tv.SetNow(); after = tv.Secs(); LOG(info, -- cgit v1.2.3