Wait-Free, Lock-Free queue built on top of a contiguous Ring Buffer using C++ 20.
This structure contains a very minimalistic interface:
Create an SPSC
queue holding items of type T
with a fixed queueSize
. queueSize
must be a power of two. cacheLineAlignment
must also be a power of two and defaults to 64.
Enqueue an item using copy assignment. This method blocks if queue is full.
Enqueue an item using move assignment. This method also blocks if queue is full. Requires from that type of object is std::is_nothrow_move_assignable_v<TT>
.
Enqueue an item using copy assignment. This method is non blocking and returns false if queue is full. If push succeeds, returns true.
Enqueue an item using move assignment. This method also is non blocking and returns false if queue is full. If push succeeds, returns true. Requires from that type of object is std::is_nothrow_move_assignable_v<TT>
.
Return a pointer to the front item of the queue if existing, otherwise, nullptr
.
Dequeue the first item of the queue. Previous item at front()
can now be overwritten by push()
calls.
Return true
if the queue is currently empty, false otherwise.
Return the fixed capacity of the queue.
Based on Erik Rigtorp's strategy of avoiding false sharing, as well as diminishing cache coherency traffic by storing cached local copies of the write and read indexes for each writer-consumer threads. See: