CppCommon
1.0.4.1
C++ Common Library
|
Multiple producers / multiple consumers wait batcher. More...
#include <wait_batcher.h>
Public Member Functions | |
WaitBatcher (size_t capacity=0, size_t initial=0) | |
Default class constructor. More... | |
WaitBatcher (const WaitBatcher &)=delete | |
WaitBatcher (WaitBatcher &&)=delete | |
~WaitBatcher () | |
WaitBatcher & | operator= (const WaitBatcher &)=delete |
WaitBatcher & | operator= (WaitBatcher &&)=delete |
operator bool () const noexcept | |
Check if the wait batcher is not empty. More... | |
bool | closed () const |
Is wait batcher closed? More... | |
bool | empty () const |
Is wait batcher empty? More... | |
size_t | capacity () const |
Get wait batcher capacity. More... | |
size_t | size () const |
Get wait batcher size. More... | |
bool | Enqueue (const T &item) |
Enqueue an item into the wait batcher. More... | |
bool | Enqueue (T &&item) |
Enqueue an item into the wait batcher. More... | |
template<class InputIterator > | |
bool | Enqueue (InputIterator first, InputIterator last) |
Enqueue all items into the wait batcher. More... | |
bool | Dequeue (std::vector< T > &items) |
Dequeue all items from the wait batcher. More... | |
void | Close () |
Close the wait batcher. More... | |
Multiple producers / multiple consumers wait batcher.
Multiple producers / multiple consumers wait batcher provides a classic solution for producer-consumer problem using two vectors and hot-swap technique with monitor synchronization primitive (mutex with condition variable). It allows a consumer thread to process all items in queue in a batch mode.
FIFO order is guaranteed!
https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem
Definition at line 31 of file wait_batcher.h.
|
inlineexplicit |
Default class constructor.
capacity | - Wait batcher capacity (0 for unlimited capacity, default is 0) |
initial | - Initial wait batcher capacity (default is 0) |
Definition at line 12 of file wait_batcher.inl.
|
delete |
|
delete |
|
inline |
Definition at line 18 of file wait_batcher.inl.
|
inline |
Get wait batcher capacity.
Definition at line 31 of file wait_batcher.inl.
|
inline |
Close the wait batcher.
Will block.
Definition at line 149 of file wait_batcher.inl.
|
inline |
Is wait batcher closed?
Definition at line 24 of file wait_batcher.inl.
|
inline |
Dequeue all items from the wait batcher.
Will block.
items | - Items to dequeue |
Definition at line 121 of file wait_batcher.inl.
|
inline |
Is wait batcher empty?
Definition at line 54 of file wait_batcher.h.
|
inline |
Enqueue an item into the wait batcher.
The item will be copied into the wait batcher.
Will block.
item | - Item to enqueue |
Definition at line 48 of file wait_batcher.inl.
|
inline |
Enqueue all items into the wait batcher.
All items will be copied into the wait batcher.
Will block.
first | - Iterator to the first item |
last | - Iterator to the last item |
Definition at line 97 of file wait_batcher.inl.
|
inline |
Enqueue an item into the wait batcher.
The item will be moved into the wait batcher.
Will block.
item | - Item to enqueue |
Definition at line 72 of file wait_batcher.inl.
|
inlineexplicitnoexcept |
Check if the wait batcher is not empty.
Definition at line 48 of file wait_batcher.h.
|
delete |
|
delete |
|
inline |
Get wait batcher size.
Definition at line 41 of file wait_batcher.inl.