aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Threading/ProducerConsumerQueue.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared/Threading/ProducerConsumerQueue.h')
-rw-r--r--src/server/shared/Threading/ProducerConsumerQueue.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/server/shared/Threading/ProducerConsumerQueue.h b/src/server/shared/Threading/ProducerConsumerQueue.h
index 961cb9f9c82..41bff445c2e 100644
--- a/src/server/shared/Threading/ProducerConsumerQueue.h
+++ b/src/server/shared/Threading/ProducerConsumerQueue.h
@@ -21,6 +21,7 @@
#include <condition_variable>
#include <mutex>
#include <queue>
+#include <atomic>
template <typename T>
class ProducerConsumerQueue
@@ -29,9 +30,12 @@ private:
std::mutex _queueLock;
std::queue<T> _queue;
std::condition_variable _condition;
+ std::atomic<bool> _shutdown;
public:
+ ProducerConsumerQueue<T>() : _shutdown(false) { }
+
void Push(const T& value)
{
_queueLock.lock();
@@ -68,7 +72,10 @@ public:
{
std::unique_lock<std::mutex> lock(_queueLock);
- _condition.wait(lock, [this](){ return !_queue.empty(); });
+ while (_queue.empty() && !_shutdown)
+ {
+ _condition.wait(lock);
+ }
if (_queue.empty())
return;
@@ -91,6 +98,8 @@ public:
_queue.pop();
}
+ _shutdown = true;
+
_queueLock.unlock();
_condition.notify_all();