#include "safe_queue.h" template TestQueue::TestQueue(void) : q() {} template TestQueue::~TestQueue(void) {} template SafeQueue::SafeQueue(void) : q() , m() , c() {} template SafeQueue::~SafeQueue(void) {} // Add an element to the queue. template void SafeQueue::enqueue(T t) { std::lock_guard lock(m); q.push(t); c.notify_one(); } // Get the "front"-element. // If the queue is empty, wait till a element is avaiable. template T SafeQueue::dequeue(void) { std::unique_lock lock(m); while(q.empty()) { // release lock as long as the wait and reaquire it afterwards. c.wait(lock); } T val = q.front(); q.pop(); return val; } template bool SafeQueue::empty(void) { return q.empty(); }