From 72c78d0164e85b44148349b1bf21220d2fc9fb27 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Thu, 18 Mar 2021 11:02:07 +0200 Subject: [PATCH] ConcurrentQueue: remove redundant checks The C++ standard specifies `std::condition_variable::wait(lock, pred)` as equivalent to `while (!pred()) wait(lock);`. It is implemented exactly so in libstdc++, libc++ and MSVC. --- common/concurrent_queue.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/common/concurrent_queue.cpp b/common/concurrent_queue.cpp index 28a0efe1..fa8eba24 100644 --- a/common/concurrent_queue.cpp +++ b/common/concurrent_queue.cpp @@ -62,11 +62,7 @@ std::size_t ConcurrentQueue::cancelPending() void ConcurrentQueue::waitAll() { std::unique_lock lock(jobsLeftMutex); - if (jobsLeft > 0) { - _waitVar.wait(lock, [this] { - return jobsLeft == 0; - }); - } + _waitVar.wait(lock, [this] { return jobsLeft == 0; }); } void ConcurrentQueue::nextJob() @@ -77,10 +73,6 @@ void ConcurrentQueue::nextJob() { std::unique_lock lock(queueMutex); - if (bailout) { - return; - } - jobAvailableVar.wait(lock, [this] { return _queue.size() > 0 || bailout; });