|
|
@ -133,7 +133,14 @@ class multiqueue_handler
|
|
|
|
bool push_(T* o, bool blocking) noexcept
|
|
|
|
bool push_(T* o, bool blocking) noexcept
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(q_mutex);
|
|
|
|
std::unique_lock<std::mutex> lock(q_mutex);
|
|
|
|
while (active_ and blocking and buffer.full()) {
|
|
|
|
if (not blocking) {
|
|
|
|
|
|
|
|
// non-blocking case
|
|
|
|
|
|
|
|
if (not active_ or buffer.full()) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// blocking case
|
|
|
|
|
|
|
|
while (active_ and buffer.full()) {
|
|
|
|
nof_waiting++;
|
|
|
|
nof_waiting++;
|
|
|
|
cv_full.wait(lock);
|
|
|
|
cv_full.wait(lock);
|
|
|
|
nof_waiting--;
|
|
|
|
nof_waiting--;
|
|
|
@ -143,6 +150,7 @@ class multiqueue_handler
|
|
|
|
cv_exit.notify_one();
|
|
|
|
cv_exit.notify_one();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
buffer.push(std::forward<T>(*o));
|
|
|
|
buffer.push(std::forward<T>(*o));
|
|
|
|
if (consumer_notify_needed) {
|
|
|
|
if (consumer_notify_needed) {
|
|
|
|
// Note: The consumer thread only needs to be notified and awaken when queues transition from empty to non-empty
|
|
|
|
// Note: The consumer thread only needs to be notified and awaken when queues transition from empty to non-empty
|
|
|
|