|
| | SPSCQueue (int capacity) |
| | Allocate capacity slots; throws a C string (after printing a message) if capacity is not a power of 2.
|
| |
| | SPSCQueue (const SPSCQueue &)=delete |
| | Copying is disabled.
|
| |
| void | operator= (const SPSCQueue &)=delete |
| | Copy assignment is disabled.
|
| |
| | SPSCQueue (SPSCQueue &&d) noexcept |
| | Move constructor: take over the slots, indices, capacity and mask of d; the terminate flag starts cleared.
|
| |
| void | push (T value) |
| | Write value at the back and wake a reader if the queue was empty.
|
| |
| bool | popW (T &value) |
| | Pop the front element into value, blocking while the queue is empty.
|
| |
| bool | popW (T &value, unsigned msTmo) |
| | Like popW(T&), but waits at most msTmo milliseconds; returns false on timeout or if terminating while still empty.
|
| |
| bool | pop (T &value) |
| | Pop the front element into value, polling for up to 1 ms and then blocking with popW(T&).
|
| |
| bool | try_pop (T &value) |
| | Pop the front element into value without blocking; returns false if the queue is empty.
|
| |
| bool | peek (T &value) const |
| | Copy the front element into value without removing it; returns false if the queue is empty.
|
| |
| T & | front () |
| | Return a reference to the slot at the read position (not checked for emptiness).
|
| |
| const T & | front () const |
| | Return a const reference to the slot at the read position (not checked for emptiness).
|
| |
| T & | back () |
| | Return a reference to the slot at the write position, the next one push() will fill.
|
| |
| const T & | back () const |
| | Return a const reference to the slot at the write position, the next one push() will fill.
|
| |
| bool | is_empty () const |
| | Return true if the read and write positions are equal.
|
| |
| bool | wait_for_nonempty () const |
| | Block until the queue is not empty; returns false if shutdown() was called while it is still empty, else true.
|
| |
| int | guess_size () const |
| | Return the number of queued elements (write minus read position, plus the capacity if negative).
|
| |
| size_t | size () const |
| | Return the capacity.
|
| |
| void | shutdown () |
| | Set the terminate flag and wake one blocked reader.
|
| |
| void | startup () |
| | Clear the terminate flag and reset both positions to 0.
|
| |
template<typename T>
class SPSCQueue< T >
Fixed-capacity ring buffer for one producer thread and one consumer thread.
push() never checks for a full queue; the read functions can block on a condition variable, and shutdown() releases blocked readers.