ADTF
|
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) | |
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.
|
inline |
Constructor.
[in] | nReserve | The amount of elements to preallocate. If the queue grows beyond that size new elements will be allocated dynamically. |
[in] | bGrow | option to grow or not to grow above reserved size |
Definition at line 221 of file lockfreequeue.h.
|
inline |
Pops an element from the queue.
[out] | pValue | Pointer where the element should be stored ("=" operator will be used on the dereferenced pointer). |
ERR_EMPTY | The queue was empty. |
Definition at line 250 of file lockfreequeue.h.
|
inline |
Pushes an element into the queue.
[in] | oValue | The new element. |
ERR_MEMORY | No memory left to allocate new elements. |
Definition at line 237 of file lockfreequeue.h.