|
|
@ -70,7 +70,7 @@ public:
|
|
|
|
// apparently mingw deadlocks if the mutex is released before cv.notify_one(),
|
|
|
|
// apparently mingw deadlocks if the mutex is released before cv.notify_one(),
|
|
|
|
// so release the mutex at the very end each function.
|
|
|
|
// so release the mutex at the very end each function.
|
|
|
|
|
|
|
|
|
|
|
|
// try to enqueue and block if no room left
|
|
|
|
// try to enqueue and block if no room left
|
|
|
|
void enqueue(T &&item)
|
|
|
|
void enqueue(T &&item)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(queue_mutex_);
|
|
|
|
std::unique_lock<std::mutex> lock(queue_mutex_);
|
|
|
@ -85,6 +85,7 @@ public:
|
|
|
|
std::unique_lock<std::mutex> lock(queue_mutex_);
|
|
|
|
std::unique_lock<std::mutex> lock(queue_mutex_);
|
|
|
|
q_.push_back(std::move(item));
|
|
|
|
q_.push_back(std::move(item));
|
|
|
|
push_cv_.notify_one();
|
|
|
|
push_cv_.notify_one();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// try to dequeue item. if no item found. wait upto timeout and try again
|
|
|
|
// try to dequeue item. if no item found. wait upto timeout and try again
|
|
|
@ -96,7 +97,8 @@ public:
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
q_.pop_front(popped_item);
|
|
|
|
popped_item = std::move(q_.front());
|
|
|
|
|
|
|
|
q_.pop_front();
|
|
|
|
pop_cv_.notify_one();
|
|
|
|
pop_cv_.notify_one();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|