Template Class MPSCQueue

Nested Relationships

Nested Types

Class Documentation

template<class T, std::size_t B = 1024>
class MPSCQueue

an unbounded queue from many producers to one consumer, a lane each

Public Types

using Item = T

the type of the items

Public Functions

MPSCQueue(void) = default
MPSCQueue(const MPSCQueue&) = delete
MPSCQueue &operator=(const MPSCQueue&) = delete
~MPSCQueue()

destroys the items left, the blocks and the lanes

Producer producer(void)

a new producer, with a lane of its own; any thread may call it

bool tryPop(T &x)

dequeues an item into x, false if none was found in a turn of the lanes; only the consumer calls it

std::size_t popInto(T *out, std::size_t n)

dequeues up to n items into out, those of a lane before the next one, and returns how many; only the consumer calls it

inline void waitPop(T &x)

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

inline std::size_t waitPopInto(T *out, std::size_t n)

as popInto(), sleeping until at least one item comes; n >= 1

bool empty(void)

true if no item was found in a turn of the lanes; only the consumer calls it

class Producer

the handle of a producer, its lane: one thread at a time pushes

Public Functions

Producer(void) = default
inline Producer(Producer &&o) noexcept
inline Producer &operator=(Producer &&o) noexcept
template<class ...Args>
void emplace(Args&&... args)

enqueues the item built from args

Pre:

the handle comes from producer()

inline void push(const T &v)
inline void push(T &&v)
inline void notify(void)

wakes the consumer if it sleeps in waitPop() or waitPopInto(), after pushes: a fence and the read of a line when it does not

Pre:

the handle comes from producer()