Class loon::SpscQueue¶
template <typename T, size_t N>
A lock-free single-producer single-consumer (SPSC) queue with fixed capacity. More...
#include <spsc.hpp>
Public Functions¶
| Type | Name |
|---|---|
| size_t | capacity () const Returns the maximum number of elements the queue can hold. |
| bool | empty () const Checks if the queue is empty. |
| bool | full () const Checks if the queue is full. |
| bool | pop (T & value) Pops a value from the front of the queue. |
| bool | push (const T & value) Pushes a value to the back of the queue. |
Detailed Description¶
SpscQueue provides O(1) push and pop operations without locks, suitable for communication between a single producer thread and a single consumer thread. The capacity is fixed at compile time and the queue will reject new elements when full.
Indices are ever-increasing (never explicitly wrapped), relying on well-defined unsigned integer overflow. Buffer access uses modulo N.
Template parameters:
TThe element type to store.NThe maximum number of elements the queue can hold (must be > 0).
** **
Public Functions Documentation¶
function capacity¶
Returns the maximum number of elements the queue can hold.
function empty¶
Checks if the queue is empty.
function full¶
Checks if the queue is full.
function pop¶
Pops a value from the front of the queue.
Parameters:
valueThe value popped from the queue (output).
Returns:
true if a value was popped, false if the queue is empty. This method is safe to call from the consumer thread only.
function push¶
Pushes a value to the back of the queue.
Parameters:
valueThe value to push (copied).
Returns:
true if the value was added, false if the queue is full. This method is safe to call from the producer thread only.
The documentation for this class was generated from the following file include/loon/spsc.hpp