|
| | LockFreeQueue (size_t capacity=128) |
| | Construct a LockFreeQueue.
|
| | ~LockFreeQueue () |
| | Destructor – signals shutdown so any blocked pop() returns.
|
| | LockFreeQueue (const LockFreeQueue &)=delete |
| LockFreeQueue & | operator= (const LockFreeQueue &)=delete |
| | LockFreeQueue (LockFreeQueue &&)=delete |
| LockFreeQueue & | operator= (LockFreeQueue &&)=delete |
| ErrorCode | push (T item) |
| | Enqueue an item (non-blocking, lock-free).
|
| T | pop () |
| | Dequeue an item, blocking indefinitely until one is available.
|
| std::optional< T > | pop (std::chrono::milliseconds timeout) |
| | Dequeue an item with a maximum wait duration.
|
| std::optional< T > | try_pop () |
| | Try to dequeue without blocking.
|
| bool | empty () const |
| | Return true if the queue appears empty (approximate).
|
| size_t | size () const |
| | Return the approximate number of items in the queue.
|
| size_t | capacity () const noexcept |
| | Return the ring buffer capacity (always a power of two).
|
| void | clear () |
| | Discard all items currently in the queue.
|
| void | shutdown () |
| | Signal shutdown so that all blocked pop() calls return promptly.
|
| bool | is_shutdown () const |
| | Return true if shutdown() has been called.
|
| void | rearm () |
| | Clear shutdown and discard any residual items so the queue is reusable after a shutdown(). The queue object itself is not moved, so any reference/pointer held by a consumer stays valid across a re-arm.
|
template<typename T>
class libe3::LockFreeQueue< T >
Lock-free bounded blocking queue.
Built on an MPMC lock-free ring buffer. Blocking pop variants use an adaptive wait strategy:
- Spin with CPU pause hints (lowest latency, nanoseconds)
- Thread yield (cooperative, microseconds)
- Block on a condition variable, woken by push()/shutdown() (idle wait, avoids busy-loop when quiet; wake latency instead of a poll period)
- Template Parameters
-
| T | Element type. Must be default-constructible and movable. |
Definition at line 48 of file lockfree_queue.hpp.