Template Class SPSCQueue

Class Documentation

template<class T>
class SPSCQueue

a bounded queue from one producer to one consumer, lock-free

Public Types

using Item = T

the type of the items

Public Functions

explicit SPSCQueue(std::size_t capacity)

a queue of the given capacity

Pre:

capacity >= 2 is a power of 2

SPSCQueue(const SPSCQueue&) = delete
SPSCQueue &operator=(const SPSCQueue&) = delete
~SPSCQueue()

destroys the items left

inline bool push(const T &v)

enqueues v, false if the queue is full; only the producer calls it

inline bool push(T &&v)
template<class ...Args>
bool emplace(Args&&... args)

enqueues the item built from args, false if the queue is full (and then nothing is built); only the producer calls it

std::optional<T> pop(void)

dequeues an item, nothing if the queue is empty; only the consumer calls it

bool tryPop(T &x)

dequeues an item into x, false if the queue is empty; only the consumer calls it

inline void notify(void) noexcept

wakes the consumer if it sleeps in waitPop(), after pushes: a fence and the read of a line when it does not; only the producer calls it

inline void waitPop(T &x)

dequeues an item into x, sleeping until one comes [see EventCount.h], the producer calling notify() after its pushes; only the consumer calls it

std::size_t size(void) const

the number of items at some moment of the call

inline std::size_t capacity(void) const