ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::MPSCQueue< T, B >::Producer Class Reference

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

#include <ADS/concurrent/MPSCQueue.h>

Public member functions

 Producer (void)=default
 a handle of no lane, to be assigned one from producer()
 Producer (Producer &&o) noexcept
 the lane of \( o \), which is left with none
Producer & operator= (Producer &&o) noexcept
 the lane of \( o \), which is left with none
template<class... Args>
void emplace (Args &&... args)
 enqueues the item built from args in the lane of the handle
void push (const T &v)
 enqueues a copy of \( v \), as emplace()
void push (T &&v)
 enqueues \( v \), moved, as emplace()
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

Friends

class MPSCQueue

Detailed description

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

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

Constructor and destructor documentation

◆ Producer() [1/2]

template<class T, std::size_t B = 1024>
ADS::MPSCQueue< T, B >::Producer::Producer ( void )
default

a handle of no lane, to be assigned one from producer()

◆ Producer() [2/2]

template<class T, std::size_t B = 1024>
ADS::MPSCQueue< T, B >::Producer::Producer ( Producer && o)
inlinenoexcept

the lane of \( o \), which is left with none

Member function documentation

◆ emplace()

template<class T, std::size_t B = 1024>
template<class... Args>
void ADS::MPSCQueue< T, B >::Producer::emplace ( Args &&... args)

enqueues the item built from args in the lane of the handle

In pseudocode (the list of bounded buffers of Aldinucci et al., beyond the book), \( b \) the last block of the lane, \( b.f \) the count of its items:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{emplace}( x ) \cr 2 & \quad p \gets b.f\quad \triangleright\ \text{relaxed, only this} \text{ thread writes it} \cr 3 & \quad \textbf{if}\ p = B\ \textbf{then} \cr 4 & \qquad n \gets \text{a spare block, else one of the blocks} \text{ given back (all taken by an exchange), else a new one} \cr 5 & \qquad n.f \gets 0;\ b.\mathit{next} \gets n\quad \triangleright \ \text{release};\ b \gets n;\ p \gets 0 \cr 6 & \quad b[ p ] \gets x \cr 7 & \quad b.f \gets p + 1\quad \triangleright\ \text{release: the item} \text{ before its count} \end{array}} \]

Precondition
the handle comes from producer()

◆ notify()

template<class T, std::size_t B = 1024>
void ADS::MPSCQueue< T, B >::Producer::notify ( void )
inline

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

Precondition
the handle comes from producer()

◆ operator=()

template<class T, std::size_t B = 1024>
Producer & ADS::MPSCQueue< T, B >::Producer::operator= ( Producer && o)
inlinenoexcept

the lane of \( o \), which is left with none

◆ push() [1/2]

template<class T, std::size_t B = 1024>
void ADS::MPSCQueue< T, B >::Producer::push ( const T & v)
inline

enqueues a copy of \( v \), as emplace()

◆ push() [2/2]

template<class T, std::size_t B = 1024>
void ADS::MPSCQueue< T, B >::Producer::push ( T && v)
inline

enqueues \( v \), moved, as emplace()

◆ MPSCQueue

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

The documentation for this class was generated from the following file: