Merge remote-tracking branch 'upstream/master'

pull/388/head
Vijay Pai 10 years ago
commit 47ef2f8b6a
  1. 7
      src/cpp/server/thread_pool.cc

@ -41,7 +41,10 @@ ThreadPool::ThreadPool(int num_threads) {
for (;;) {
std::unique_lock<std::mutex> lock(mu_);
// Wait until work is available or we are shutting down.
cv_.wait(lock, [=]() { return shutdown_ || !callbacks_.empty(); });
auto have_work = [=]() { return shutdown_ || !callbacks_.empty(); };
if (!have_work()) {
cv_.wait(lock, have_work);
}
// Drain callbacks before considering shutdown to ensure all work
// gets completed.
if (!callbacks_.empty()) {
@ -71,7 +74,7 @@ ThreadPool::~ThreadPool() {
void ThreadPool::ScheduleCallback(const std::function<void()> &callback) {
std::lock_guard<std::mutex> lock(mu_);
callbacks_.push(callback);
cv_.notify_all();
cv_.notify_one();
}
} // namespace grpc

Loading…
Cancel
Save