Thread-safe FIFO queue. More...
#include <queue.h>
Public Member Functions | |
| void | push (const T &val) |
Pushes a copy of val onto the back of the queue. | |
| void | push (T &&val) |
Moves val onto the back of the queue. | |
| template<typename... Args> | |
| void | emplace (Args &&... args) |
| Constructs an element in-place at the back of the queue. | |
| void | push (const List< T > &list) |
Pushes every element in list onto the back of the queue. | |
| std::pair< T, Error > | pop (unsigned int timeoutMs=0) |
| Removes and returns the front element, blocking until one is available or the timeout expires. | |
| bool | popOrFail (T &val) |
| Tries to pop the front element without blocking. | |
| std::pair< T, Error > | peek (unsigned int timeoutMs=0) |
| Returns a copy of the front element without removing it, blocking until one is available or the timeout expires. | |
| bool | peekOrFail (T &val) |
| Tries to copy the front element without blocking or removing it. | |
| Error | waitForEmpty (unsigned int timeoutMs=0) |
| Blocks until the queue is empty. | |
| bool | isEmpty () const |
| Returns true if the queue has no elements. | |
| size_t | size () const |
| Returns the number of elements currently in the queue. | |
| void | clear () |
| Removes all elements from the queue. | |
Thread-safe FIFO queue.
All public methods are safe to call concurrently from multiple threads.
| T | The element type stored in the queue. |
Constructs an element in-place at the back of the queue.
| Args | Constructor argument types. |
| args | Arguments forwarded to the T constructor. |
Returns true if the queue has no elements.
Returns a copy of the front element without removing it, blocking until one is available or the timeout expires.
| timeoutMs | Maximum time to wait in milliseconds. A value of zero (the default) waits indefinitely. |
Tries to copy the front element without blocking or removing it.
| [out] | val | Receives a copy of the front element on success. |
true if an element was available, false if the queue was empty. Removes and returns the front element, blocking until one is available or the timeout expires.
| timeoutMs | Maximum time to wait in milliseconds. A value of zero (the default) waits indefinitely. |
Tries to pop the front element without blocking.
| [out] | val | Receives the dequeued element on success. |
true if an element was dequeued, false if the queue was empty. Pushes every element in list onto the back of the queue.
| list | List of values to enqueue. |
Pushes a copy of val onto the back of the queue.
| val | Value to enqueue. |
Moves val onto the back of the queue.
| val | Rvalue reference to enqueue. |
Returns the number of elements currently in the queue.
Blocks until the queue is empty.
Useful for backpressure: a producer can wait until the consumer has drained the queue before pushing more work. Note that this only guarantees the items have been popped, not that the consumer has finished processing them.
| timeoutMs | Maximum time to wait in milliseconds. A value of zero (the default) waits indefinitely. |