|
| | 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
|
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
template<class T, std::size_t B = 1024>
template<class... 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()