4#include <condition_variable>
37 void push(
const T& objValue) {
51 std::unique_lock<std::mutex> objLock(
m_objMutex);
75 T objValue = std::move(
m_queJobs.front());
A thread-safe FIFO queue wrapper using mutexes and condition variables. Designed for producer-consume...
Definition ThreadSafeQueue.h:17
bool empty() const
Definition ThreadSafeQueue.h:80
ThreadSafeQueue & operator=(const ThreadSafeQueue &)=delete
void push(const T &objValue)
Pushes a value into the queue (Copy semantics).
Definition ThreadSafeQueue.h:37
void invalidate()
Wakes up all waiting threads effectively cancelling the wait.
Definition ThreadSafeQueue.h:88
bool wait_and_pop(T &objValue)
Waits until the queue is not empty, then pops the front element.
Definition ThreadSafeQueue.h:50
void push(T &&objValue)
Pushes a value into the queue (Move semantics).
Definition ThreadSafeQueue.h:26
ThreadSafeQueue(const ThreadSafeQueue &)=delete
std::queue< T > m_queJobs
Definition ThreadSafeQueue.h:97
std::optional< T > try_pop()
Non-blocking attempt to pop an item.
Definition ThreadSafeQueue.h:70
ThreadSafeQueue()=default
std::mutex m_objMutex
Definition ThreadSafeQueue.h:98
std::atomic< bool > m_bInvalidated
Definition ThreadSafeQueue.h:100
std::condition_variable m_objContVar
Definition ThreadSafeQueue.h:99