From 72dabacbd1b69f29b8a92c5d6a9a51128d85a705 Mon Sep 17 00:00:00 2001 From: Jonathan L Long Date: Thu, 19 Mar 2015 22:29:25 -0700 Subject: [PATCH] add blocking_queue::wait_for_empty for blocking until done --- include/caffe/util/blocking_queue.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/caffe/util/blocking_queue.hpp b/include/caffe/util/blocking_queue.hpp index 298ffc74163..09ee035d1cc 100644 --- a/include/caffe/util/blocking_queue.hpp +++ b/include/caffe/util/blocking_queue.hpp @@ -24,10 +24,20 @@ class blocking_queue { return queue_.empty(); } + void wait_for_empty() { + boost::mutex::scoped_lock lock(mutex_); + while (!queue_.empty()) { + cond_empty_.wait(lock); + } + } + T pop() { T t = peek(); boost::mutex::scoped_lock lock(mutex_); queue_.pop(); + if (queue_.empty()) { + cond_empty_.notify_all(); + } return t; } @@ -44,6 +54,7 @@ class blocking_queue { std::queue queue_; mutable boost::mutex mutex_; boost::condition_variable cond_push_; + boost::condition_variable cond_empty_; DISABLE_COPY_AND_ASSIGN(blocking_queue); };