added tp->wait_empty()

This commit is contained in:
gabime
2018-05-27 02:53:16 +03:00
parent 0d0a841e8d
commit 8338b45b2b
4 changed files with 51 additions and 16 deletions

View File

@@ -72,6 +72,13 @@ public:
return true;
}
// wait until the queue is empty
void wait_empty()
{
std::unique_lock<std::mutex> lock(queue_mutex_);
pop_cv_.wait(lock, [this] { return this->q_.empty(); });
}
private:
size_t max_items_;
std::mutex queue_mutex_;

View File

@@ -139,6 +139,11 @@ public:
return msg_counter_.load(std::memory_order_relaxed);
}
void wait_empty()
{
q_.wait_empty();
}
private:
std::atomic<size_t> msg_counter_; // total # of messages processed in this pool
q_type q_;