20 mutable std::mutex
mut;
32 std::lock_guard<std::mutex> lock(mut);
38 std::lock_guard<std::mutex> lock(mut);
45 std::lock_guard<std::mutex> lock(mut);
46 queue.push_back(elem);
48 not_empty.notify_one();
54 std::lock_guard<std::mutex> lock(mut);
55 queue.push_back(elem);
57 not_empty.notify_one();
62 std::unique_lock<std::mutex> lock(mut);
63 while ( queue.empty() )
71 T
Dequeue(
const std::chrono::milliseconds& timeout) {
72 std::unique_lock<std::mutex> lock(mut);
73 while ( queue.empty() )
74 not_empty.wait_for(lock, timeout);
void Clear()
Clears the queue.
std::condition_variable not_empty
condition variable for not empty notification
std::mutex mut
mutex for protection
void Enqueue(const T &elem)
Enqueues an element and notifies one waiting operation that queue is not empty.
std::deque< T > queue
STL dequeue.
SynchronizedQueue()
We need a default constructor here.
T Dequeue(const std::chrono::milliseconds &timeout)
Dequeues front element, waits timeout if queue is empty.
void Enqueue(T &&elem)
Enqueues an element by moving and notifies one waiting operation that queue is not empty...
A synchronized, thread-safe queue was modeled after ringbuffer example from boost?! and/or a Herb Sutter column?!
SynchronizedQueue< T > operator=(SynchronizedQueue< T > &)
disable assignment
T Dequeue()
Dequeues front element, waits indefinitely if queue is empty.