]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[pzstd] Fix latent bug in WorkQueue
authorNick Terrell <terrelln@fb.com>
Thu, 6 Oct 2016 22:51:58 +0000 (15:51 -0700)
committerNick Terrell <terrelln@fb.com>
Thu, 6 Oct 2016 22:51:58 +0000 (15:51 -0700)
contrib/pzstd/utils/WorkQueue.h

index 538213500425cf16e35171be27fa2220d85e0fb0..c46e6cbcf2749200d771cf1e3b57e353f27b1b94 100644 (file)
@@ -28,6 +28,7 @@ class WorkQueue {
   std::mutex mutex_;
   std::condition_variable readerCv_;
   std::condition_variable writerCv_;
+  std::condition_variable finishCv_;
 
   std::queue<T> queue_;
   bool done_;
@@ -124,19 +125,14 @@ class WorkQueue {
     }
     readerCv_.notify_all();
     writerCv_.notify_all();
+    finishCv_.notify_all();
   }
 
   /// Blocks until `finish()` has been called (but the queue may not be empty).
   void waitUntilFinished() {
     std::unique_lock<std::mutex> lock(mutex_);
     while (!done_) {
-      readerCv_.wait(lock);
-      // If we were woken by a push, we need to wake a thread waiting on pop().
-      if (!done_) {
-        lock.unlock();
-        readerCv_.notify_one();
-        lock.lock();
-      }
+      finishCv_.wait(lock);
     }
   }
 };