HPC_Voxel_Engine 0.2.0
High-Performance C++ Voxel Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Core::ThreadSafeQueue< T > Class Template Reference

A thread-safe FIFO queue wrapper using mutexes and condition variables. Designed for producer-consumer scenarios (like ThreadPools). More...

#include <src/core/ThreadSafeQueue.h>

Collaboration diagram for Core::ThreadSafeQueue< T >:
Collaboration graph

Public Member Functions

 ThreadSafeQueue ()=default
 
 ThreadSafeQueue (const ThreadSafeQueue &)=delete
 
ThreadSafeQueueoperator= (const ThreadSafeQueue &)=delete
 
void push (T &&objValue)
 Pushes a value into the queue (Move semantics).
 
void push (const T &objValue)
 Pushes a value into the queue (Copy semantics).
 
bool wait_and_pop (T &objValue)
 Waits until the queue is not empty, then pops the front element.
 
std::optional< T > try_pop ()
 Non-blocking attempt to pop an item.
 
bool empty () const
 
void invalidate ()
 Wakes up all waiting threads effectively cancelling the wait.
 

Private Attributes

std::queue< T > m_queJobs
 
std::mutex m_objMutex
 
std::condition_variable m_objContVar
 
std::atomic< bool > m_bInvalidated = false
 

Detailed Description

template<typename T>
class Core::ThreadSafeQueue< T >

A thread-safe FIFO queue wrapper using mutexes and condition variables. Designed for producer-consumer scenarios (like ThreadPools).

Constructor & Destructor Documentation

◆ ThreadSafeQueue() [1/2]

template<typename T >
Core::ThreadSafeQueue< T >::ThreadSafeQueue ( )
default

◆ ThreadSafeQueue() [2/2]

template<typename T >
Core::ThreadSafeQueue< T >::ThreadSafeQueue ( const ThreadSafeQueue< T > &  )
delete

Member Function Documentation

◆ empty()

template<typename T >
bool Core::ThreadSafeQueue< T >::empty ( ) const
inline

◆ invalidate()

template<typename T >
void Core::ThreadSafeQueue< T >::invalidate ( )
inline

Wakes up all waiting threads effectively cancelling the wait.

Here is the caller graph for this function:

◆ operator=()

template<typename T >
ThreadSafeQueue & Core::ThreadSafeQueue< T >::operator= ( const ThreadSafeQueue< T > &  )
delete

◆ push() [1/2]

template<typename T >
void Core::ThreadSafeQueue< T >::push ( const T &  objValue)
inline

Pushes a value into the queue (Copy semantics).

◆ push() [2/2]

template<typename T >
void Core::ThreadSafeQueue< T >::push ( T &&  objValue)
inline

Pushes a value into the queue (Move semantics).

Here is the caller graph for this function:

◆ try_pop()

template<typename T >
std::optional< T > Core::ThreadSafeQueue< T >::try_pop ( )
inline

Non-blocking attempt to pop an item.

Returns
std::optional containing the item if found, nullopt otherwise.
Here is the caller graph for this function:

◆ wait_and_pop()

template<typename T >
bool Core::ThreadSafeQueue< T >::wait_and_pop ( T &  objValue)
inline

Waits until the queue is not empty, then pops the front element.

Parameters
objValueReference to store the popped value.
Returns
True if value popped, False if queue was invalidated/stopped.
Here is the caller graph for this function:

Member Data Documentation

◆ m_bInvalidated

template<typename T >
std::atomic<bool> Core::ThreadSafeQueue< T >::m_bInvalidated = false
private

◆ m_objContVar

template<typename T >
std::condition_variable Core::ThreadSafeQueue< T >::m_objContVar
private

◆ m_objMutex

template<typename T >
std::mutex Core::ThreadSafeQueue< T >::m_objMutex
mutableprivate

◆ m_queJobs

template<typename T >
std::queue<T> Core::ThreadSafeQueue< T >::m_queJobs
private

The documentation for this class was generated from the following file: