CppCommon  1.0.4.1
C++ Common Library
Classes | Public Member Functions | List of all members
CppCommon::MPSCLinkedBatcher< T > Class Template Reference

Multiple producers / single consumer wait-free linked batcher. More...

#include <mpsc_linked_batcher.h>

Public Member Functions

 MPSCLinkedBatcher ()
 
 MPSCLinkedBatcher (const MPSCLinkedBatcher &)=delete
 
 MPSCLinkedBatcher (MPSCLinkedBatcher &&)=delete
 
 ~MPSCLinkedBatcher ()
 
MPSCLinkedBatcheroperator= (const MPSCLinkedBatcher &)=delete
 
MPSCLinkedBatcheroperator= (MPSCLinkedBatcher &&)=delete
 
bool Enqueue (const T &item)
 Enqueue an item into the linked batcher (multiple producers threads method) More...
 
bool Enqueue (T &&item)
 Enqueue an item into the linked batcher (multiple producers threads method) More...
 
bool Dequeue (const std::function< void(const T &)> &handler=[](const int &){})
 Dequeue all items from the linked queue (single consumer thread method) More...
 

Detailed Description

template<typename T>
class CppCommon::MPSCLinkedBatcher< T >

Multiple producers / single consumer wait-free linked batcher.

Multiple producers / single consumer wait-free linked batcher use only atomic operations to provide thread-safe enqueue and batch dequeue operations. Linked batcher is a dynamically grows queue which allocates memory for each new node. It allows a consumer thread to process all items in queue in a batch mode.

FIFO order is guaranteed!

Thread-safe.

Based on Boost Wait-free multi-producer queue http://www.boost.org/doc/libs/1_60_0/doc/html/atomic/usage_examples.html#boost_atomic.usage_examples.mp_queue

Definition at line 33 of file mpsc_linked_batcher.h.

Constructor & Destructor Documentation

◆ MPSCLinkedBatcher() [1/3]

template<typename T >
CppCommon::MPSCLinkedBatcher< T >::MPSCLinkedBatcher
inline

Definition at line 12 of file mpsc_linked_batcher.inl.

◆ MPSCLinkedBatcher() [2/3]

template<typename T >
CppCommon::MPSCLinkedBatcher< T >::MPSCLinkedBatcher ( const MPSCLinkedBatcher< T > &  )
delete

◆ MPSCLinkedBatcher() [3/3]

template<typename T >
CppCommon::MPSCLinkedBatcher< T >::MPSCLinkedBatcher ( MPSCLinkedBatcher< T > &&  )
delete

◆ ~MPSCLinkedBatcher()

template<typename T >
CppCommon::MPSCLinkedBatcher< T >::~MPSCLinkedBatcher
inline

Definition at line 17 of file mpsc_linked_batcher.inl.

Member Function Documentation

◆ Dequeue()

template<typename T >
bool CppCommon::MPSCLinkedBatcher< T >::Dequeue ( const std::function< void(const T &)> &  handler = [](const int&){})
inline

Dequeue all items from the linked queue (single consumer thread method)

All items in the batcher will be processed by the given handler.

Will not block.

Parameters
handler- Batch handler (default is empty handler)
Returns
'true' if all items were successfully handled, 'false' if the linked batcher is empty

Definition at line 52 of file mpsc_linked_batcher.inl.

◆ Enqueue() [1/2]

template<typename T >
bool CppCommon::MPSCLinkedBatcher< T >::Enqueue ( const T &  item)
inline

Enqueue an item into the linked batcher (multiple producers threads method)

The item will be copied into the linked batcher.

Will not block.

Parameters
item- Item to enqueue
Returns
'true' if the item was successfully enqueue, 'false' if there is no enough memory for the batcher node

Definition at line 24 of file mpsc_linked_batcher.inl.

◆ Enqueue() [2/2]

template<typename T >
bool CppCommon::MPSCLinkedBatcher< T >::Enqueue ( T &&  item)
inline

Enqueue an item into the linked batcher (multiple producers threads method)

The item will be moved into the linked batcher.

Will not block.

Parameters
item- Item to enqueue
Returns
'true' if the item was successfully enqueue, 'false' if there is no enough memory for the batcher node

Definition at line 31 of file mpsc_linked_batcher.inl.

◆ operator=() [1/2]

template<typename T >
MPSCLinkedBatcher& CppCommon::MPSCLinkedBatcher< T >::operator= ( const MPSCLinkedBatcher< T > &  )
delete

◆ operator=() [2/2]

template<typename T >
MPSCLinkedBatcher& CppCommon::MPSCLinkedBatcher< T >::operator= ( MPSCLinkedBatcher< T > &&  )
delete

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