This template provides inter-thread first-in first-out (FIFO) queueing. More...
#include <DwmThreadQueue.hh>
Public Member Functions | |
| Queue () | |
| Constructor. | |
| ~Queue () | |
| Destructor. | |
| uint32_t | MaxLength () const |
| Returns the max length of the queue. | |
| uint32_t | MaxLength (uint32_t maxLength) |
| Sets and returns the max length of the queue. | |
| std::deque< _ValueType >::size_type | Length () const |
| Returns the current length of the queue. | |
| bool | PushBack (const _ValueType &value) |
Inserts value on the back of the queue. | |
| bool | PushBack (_ValueType &&value) |
Inserts value on the back of the queue. | |
| template<typename InputIterator > | |
| uint32_t | PushBack (InputIterator firstIter, InputIterator lastIter) |
| Inserts the values from firstIter to lastIter on the back of the queue. | |
| bool | PushFront (const _ValueType &value) |
Inserts value on the front of the queue. | |
| template<typename InputIterator > | |
| uint32_t | PushFront (InputIterator firstIter, InputIterator lastIter) |
| void | ConditionSignal () |
| Unblocks at least one thread waiting on the condition variable. | |
| bool | ConditionWait () |
| Waits for the condition variable to be signalled or broadcasted. | |
| template<class Rep , class Period > | |
| bool | ConditionTimedWait (const std::chrono::duration< Rep, Period > &timeToWait) |
| Waits for the condition variable to be signalled or broadcasted for timeToWait to pass. | |
| bool | PopFront (_ValueType &value) |
Pops the entry from the front of the queue and stores it in value. | |
| bool | PopBack (_ValueType &value) |
Pops the entry from the back of the queue and stores it in value. | |
| bool | WaitForNotEmpty () |
| Blocks the calling thread until the queue contains at least one entry. | |
| template<class Rep , class Period > | |
| bool | TimedWaitForNotEmpty (const std::chrono::duration< Rep, Period > &timeToWait) |
Waits timeToWait for the queue to be non-empty. | |
| bool | Empty () |
| Returns true if the queue is empty, else returns false. | |
| void | RandomShuffle () |
| uint32_t | Copy (std::deque< _ValueType > &c) |
Copies the contents of the queue to c. | |
| uint32_t | Swap (std::deque< _ValueType > &c) |
| This member is a simple optimization for fetching the contents of the queue. | |
Protected Member Functions | |
| void | Lock () |
| void | Unlock () |
Protected Attributes | |
| uint32_t | _maxLength |
| std::deque< _ValueType > | _queue |
| std::mutex | _mutex |
| std::atomic< bool > | _signalled |
| std::unique_lock< std::mutex > | _lock |
| std::condition_variable | _cv |
This template provides inter-thread first-in first-out (FIFO) queueing.
A source thread may insert objects into the back of the queue using PushBack() while a sink thread pops objects from the front of the queue using PopFront(). A sink thread may use WaitForNotEmpty() to wait for entries to be added to the queue; the calling thread will be blocked until the queue is non-empty. A sink thread may also choose to use ConditionWait() and PopFront(), which allows a source to wake up the sink using ConditionBroadcast() or ConditionSignal() without pushing an entry into the queue.
|
inline |
Waits for the condition variable to be signalled or broadcasted for timeToWait to pass.
Returns true if the condition variable was signalled or broadcasted, else returns false.
|
inline |
Copies the contents of the queue to c.
Returns the number of elements copied. Note that c will always be cleared before elements are copied. Hence if there are no entries in the queue, c will be empty on return.
|
inline |
Returns the max length of the queue.
If 0, no maximum length will be enforced.
|
inline |
Sets and returns the max length of the queue.
If 0, no maximum length will be enforced.
|
inline |
Pops the entry from the back of the queue and stores it in value.
Returns true on success, false on failure.
|
inline |
Pops the entry from the front of the queue and stores it in value.
Returns true on success, false on failure.
|
inline |
Inserts value on the back of the queue.
Returns true on success, false on failure.
|
inline |
Inserts value on the back of the queue.
Returns true on success, false on failure.
|
inline |
Inserts the values from firstIter to lastIter on the back of the queue.
Note that lastIter is excluded, i.e. the range of entries inserted is [firstIter,lastIter). Returns the number of entries inserted.
|
inline |
Inserts value on the front of the queue.
Returns true on success, false on failure.
|
inline |
This member is a simple optimization for fetching the contents of the queue.
It swaps the encapsulated queue with c, then clears the contents of the encapsulated queue. It returns the number of entries in c after the swap, i.e. the number of entries that were in the encapsulated queue before this member was called.
|
inline |
Waits timeToWait for the queue to be non-empty.
Returns true if the queue is non-empty, else returns false.
|
inline |
Blocks the calling thread until the queue contains at least one entry.
Returns true on success, false on failure.