ADTF
lock_free_queue< T >

Lock-free queue (FIFO) class that allows multiple writers and readers. More...

Public Member Functions

 lock_free_queue (tUInt nReserve=0, tBool bGrow=tTrue)
 Constructor. More...
 
virtual ~lock_free_queue ()
 Destructor.
 
tResult Push (const T &oValue)
 Pushes an element into the queue. More...
 
tResult Pop (T *pValue)
 Pops an element from the queue. More...
 

Protected Attributes

std::queue< T > m_oQueue
 
std::recursive_mutex m_oMutex
 

Private Member Functions

 lock_free_queue (const lock_free_queue &oOther)
 

Detailed Description

template<class T>
class A_UTILS_NS::lock_free_queue< T >

Lock-free queue (FIFO) class that allows multiple writers and readers.

You can call Push and Pop anytime from any thread you like.

Please note that the destructor is not thread safe!! You need to ensure that no other thread accesses the object while the destructor is running.

This is the fallback implementation that uses mutexes when the required operations are not avaliable. So it is NOT lock-free at all.

Definition at line 207 of file lockfreequeue.h.

Constructor & Destructor Documentation

◆ lock_free_queue()

lock_free_queue ( tUInt  nReserve = 0,
tBool  bGrow = tTrue 
)
inline

Constructor.

Parameters
[in]nReserveThe amount of elements to preallocate. If the queue grows beyond that size new elements will be allocated dynamically.
[in]bGrowoption to grow or not to grow above reserved size

Definition at line 221 of file lockfreequeue.h.

Member Function Documentation

◆ Pop()

tResult Pop ( T *  pValue)
inline

Pops an element from the queue.

Parameters
[out]pValuePointer where the element should be stored ("=" operator will be used on the dereferenced pointer).
Return values
ERR_EMPTYThe queue was empty.

Definition at line 250 of file lockfreequeue.h.

◆ Push()

tResult Push ( const T &  oValue)
inline

Pushes an element into the queue.

Parameters
[in]oValueThe new element.
Return values
ERR_MEMORYNo memory left to allocate new elements.

Definition at line 237 of file lockfreequeue.h.