ADTF
|
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) | |
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.
|
inline |
Constructor.
[in] | nReserve | The amount of elements to preallocate. If the stack grows beyond that size new elements will be allocated dynamically. |
[in] | bGrow | Whether 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.
|
inline |
Pops an element from the stack.
[out] | pValue | Pointer where the element should be stored ("=" operator will be used on the dereferenced pointer). |
ERR_EMPTY | The stack was empty. |
Definition at line 214 of file lockfreestack.h.
|
inline |
Pushes an element onto the stack.
[in] | oValue | The new element. |
ERR_MEMORY | No memory left to allocate new elements. |
Definition at line 201 of file lockfreestack.h.