ADTF  3.18.2
lock_free_stack< T >

Lock-free stack class that allows multiple writers and readers. More...

Public Member Functions

 lock_free_stack (tUInt nReserve=0, tBool bGrow=tTrue)
 Constructor. More...
 
virtual ~lock_free_stack ()
 Destructor.
 
tErrorCode Push (const T &oValue)
 Pushes an element onto the stack. More...
 
tErrorCode Pop (T *pValue)
 Pops an element from the stack. More...
 

Protected Attributes

std::recursive_mutex m_oMutex
 
std::stack< T > m_oStack
 

Private Member Functions

 lock_free_stack (const lock_free_stack &oOther)
 

Detailed Description

template<class T>
class A_UTILS_NS::lock_free_stack< T >

Lock-free stack 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 168 of file lockfreestack.h.

Constructor & Destructor Documentation

◆ lock_free_stack()

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

Constructor.

Parameters
[in]nReserveThe amount of elements to preallocate. If the stack grows beyond that size new elements will be allocated dynamically.
[in]bGrowWhether or not the stack should allocate new elements on-the-fly or not. The stack is realtime save if the parameter is tFalse. In this case you have to preallocate all elements with the help of the nReserve parameter of the constructor.

Definition at line 185 of file lockfreestack.h.

Member Function Documentation

◆ Pop()

tErrorCode Pop ( T *  pValue)
inline

Pops an element from the stack.

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

Definition at line 214 of file lockfreestack.h.

◆ Push()

tErrorCode Push ( const T &  oValue)
inline

Pushes an element onto the stack.

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

Definition at line 201 of file lockfreestack.h.