11 #include <condition_variable>
28 std::unique_lock<std::mutex> l(mutex);
40 std::unique_lock<std::mutex> l(mutex);
41 if (queue.size() == 0)
43 value = queue.front();
53 std::unique_lock<std::mutex> l(mutex);
54 if (queue.size() == 0)
56 T value = queue.front();
63 size_t size()
const {
return queue.size(); }
68 std::condition_variable cond;
Interface for queue that is thread safe.
Definition: ISafeQueue.hpp:14
A queue class that is thread safe.
Definition: SafeQueue.hpp:19
bool tryPop(T &value) override
Try to pop a value from the queue, lock a mutex while trying to pop the value.
Definition: SafeQueue.hpp:38
T pop() override
Pop a value from the queue, lock a mutex and wait if the queue is empty.
Definition: SafeQueue.hpp:51
~SafeQueue()=default
Destructor.
void push(T value) override
Push in queue, lock a mutex while pushing the value.
Definition: SafeQueue.hpp:26
size_t size() const
Returns the current size of the queue.
Definition: SafeQueue.hpp:63