|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Thread-safe FIFO queue with blocking waits, the workhorse producer/consumer channel in CMSDK. More...
#include <Utils.h>
Public Member Functions | |
| WaitQueue () | |
| virtual | ~WaitQueue () |
| bool | add (T entry) |
| Append an entry and wake one waiting consumer. | |
| uint32 | getCount () |
| Number of queued entries. | |
| bool | peekFirst (T &first) |
| Copy the front entry without removing it. | |
| bool | takeFirst (T &first) |
| Remove and return the front entry. | |
| bool | waitForAndPeekFirst (T &first, uint32 timeoutMS) |
Block up to timeoutMS for an entry and peek it without removal. | |
| bool | waitForAndTakeFirst (T &first, uint32 timeoutMS) |
Block up to timeoutMS for an entry and dequeue it. | |
| virtual bool | clear () |
| Discard all queued entries. | |
Protected Attributes | |
| Mutex | mutex |
| Semaphore | semaphore |
| std::queue< T > | internalQueue |
Thread-safe FIFO queue with blocking waits, the workhorse producer/consumer channel in CMSDK.
All operations take an internal mutex with a 200 ms timeout and return false rather than deadlock if it cannot be acquired. A semaphore is signalled on every add() so consumers can block in waitForAndTakeFirst()/waitForAndPeekFirst() without polling.
| T | Element type (copied by value). For heap pointers prefer WaitQueuePointer, which deletes leftovers on clear(). |
|
inline |
|
inlinevirtual |
|
inline |
Append an entry and wake one waiting consumer.
| entry | Value to enqueue. |
Definition at line 709 of file Utils.h.
References internalQueue, mutex, and semaphore.
|
inlinevirtual |
Discard all queued entries.
Reimplemented in cmlabs::utils::WaitQueuePointer< T >, cmlabs::utils::WaitQueuePointer< cmlabs::DataMessage * >, and cmlabs::utils::WaitQueuePointer< cmlabs::RequestReply * >.
Definition at line 805 of file Utils.h.
References internalQueue, and mutex.
|
inline |
Number of queued entries.
Definition at line 718 of file Utils.h.
References internalQueue, and mutex.
|
inline |
Copy the front entry without removing it.
| [out] | first | Receives the front value. |
Definition at line 727 of file Utils.h.
References internalQueue, and mutex.
|
inline |
Remove and return the front entry.
| [out] | first | Receives the front value. |
Definition at line 739 of file Utils.h.
References internalQueue, and mutex.
|
inline |
Block up to timeoutMS for an entry and peek it without removal.
| [out] | first | Receives the front value. |
| timeoutMS | Max wait in ms. |
Definition at line 753 of file Utils.h.
References internalQueue, mutex, and semaphore.
|
inline |
Block up to timeoutMS for an entry and dequeue it.
| [out] | first | Receives the value. |
| timeoutMS | Max wait in ms. |
Definition at line 779 of file Utils.h.
References internalQueue, mutex, and semaphore.
Referenced by cmlabs::utils::WaitQueuePointer< T >::waitForAndTakeFirst().
|
protected |
Definition at line 817 of file Utils.h.
Referenced by add(), clear(), cmlabs::utils::WaitQueuePointer< T >::clear(), getCount(), peekFirst(), takeFirst(), waitForAndPeekFirst(), and waitForAndTakeFirst().
|
protected |
Definition at line 815 of file Utils.h.
Referenced by add(), clear(), cmlabs::utils::WaitQueuePointer< T >::clear(), getCount(), peekFirst(), takeFirst(), waitForAndPeekFirst(), and waitForAndTakeFirst().
|
protected |
Definition at line 816 of file Utils.h.
Referenced by add(), waitForAndPeekFirst(), and waitForAndTakeFirst().