|
|
|
@ -251,15 +251,18 @@ public:
|
|
|
|
|
base_blocking_queue(PushingFunc push_func_, PoppingFunc pop_func_, Args&&... args) :
|
|
|
|
|
circ_buffer(std::forward<Args>(args)...), push_func(push_func_), pop_func(pop_func_)
|
|
|
|
|
{}
|
|
|
|
|
base_blocking_queue(const base_blocking_queue&) = delete;
|
|
|
|
|
base_blocking_queue(base_blocking_queue&&) = delete;
|
|
|
|
|
base_blocking_queue& operator=(const base_blocking_queue&) = delete;
|
|
|
|
|
base_blocking_queue& operator=(base_blocking_queue&&) = delete;
|
|
|
|
|
|
|
|
|
|
void stop()
|
|
|
|
|
{
|
|
|
|
|
std::unique_lock<std::mutex> lock(mutex);
|
|
|
|
|
if (active) {
|
|
|
|
|
active = false;
|
|
|
|
|
if (nof_waiting == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (nof_waiting > 0) {
|
|
|
|
|
// Stop pending pushing/popping threads
|
|
|
|
|
do {
|
|
|
|
|
lock.unlock();
|
|
|
|
|
cvar_empty.notify_all();
|
|
|
|
@ -268,6 +271,10 @@ public:
|
|
|
|
|
lock.lock();
|
|
|
|
|
} while (nof_waiting > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Empty queue
|
|
|
|
|
circ_buffer.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool try_push(const T& t) { return push_(t, false); }
|
|
|
|
@ -284,7 +291,6 @@ public:
|
|
|
|
|
bool pop_wait_until(T& obj, const std::chrono::system_clock::time_point& until) { return pop_(obj, true, &until); }
|
|
|
|
|
void clear()
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
|
T obj;
|
|
|
|
|
while (pop_(obj, false)) {
|
|
|
|
|
}
|
|
|
|
|