Skip to content

Commit

Permalink
add blocking_queue::wait_for_empty for blocking until done
Browse files Browse the repository at this point in the history
  • Loading branch information
longjon committed Mar 20, 2015
1 parent 910197c commit 61e7216
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/caffe/util/blocking_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -44,6 +54,7 @@ class blocking_queue {
std::queue<T> queue_;
mutable boost::mutex mutex_;
boost::condition_variable cond_push_;
boost::condition_variable cond_empty_;

DISABLE_COPY_AND_ASSIGN(blocking_queue);
};
Expand Down

0 comments on commit 61e7216

Please sign in to comment.