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

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

#include <mpsc_linked_queue.h>

Public Member Functions

 MPSCLinkedQueue ()
 
 MPSCLinkedQueue (const MPSCLinkedQueue &)=delete
 
 MPSCLinkedQueue (MPSCLinkedQueue &&)=delete
 
 ~MPSCLinkedQueue ()
 
MPSCLinkedQueueoperator= (const MPSCLinkedQueue &)=delete
 
MPSCLinkedQueueoperator= (MPSCLinkedQueue &&)=delete
 
bool Enqueue (const T &item)
 Enqueue an item into the linked queue (multiple producers threads method) More...
 
bool Enqueue (T &&item)
 Enqueue an item into the linked queue (multiple producers threads method) More...
 
bool Dequeue (T &item)
 Dequeue an item from the linked queue (single consumer thread method) More...
 

Detailed Description

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

Multiple producers / single consumer wait-free linked queue.

Multiple producers / single consumer wait-free linked queue use only atomic operations to provide thread-safe enqueue and dequeue operations. Linked queue is a dynamically grows queue which allocates memory for each new node.

FIFO order is guaranteed!

Thread-safe.

C++ implementation of Dmitry Vyukov's non-intrusive lock free unbound MPSC queue http://www.1024cores.net/home/lock-free-algorithms/queues/non-intrusive-mpsc-node-based-queue

Examples
threads_mpsc_linked_queue.cpp.

Definition at line 32 of file mpsc_linked_queue.h.

Constructor & Destructor Documentation

◆ MPSCLinkedQueue() [1/3]

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

Definition at line 12 of file mpsc_linked_queue.inl.

◆ MPSCLinkedQueue() [2/3]

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

◆ MPSCLinkedQueue() [3/3]

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

◆ ~MPSCLinkedQueue()

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

Definition at line 24 of file mpsc_linked_queue.inl.

Member Function Documentation

◆ Dequeue()

template<typename T >
bool CppCommon::MPSCLinkedQueue< T >::Dequeue ( T &  item)
inline

Dequeue an item from the linked queue (single consumer thread method)

The item will be moved from the linked queue.

Will not block.

Parameters
item- Item to dequeue
Returns
'true' if the item was successfully dequeue, 'false' if the linked queue is empty
Examples
threads_mpsc_linked_queue.cpp.

Definition at line 62 of file mpsc_linked_queue.inl.

◆ Enqueue() [1/2]

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

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

The item will be copied into the linked queue.

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 queue node
Examples
threads_mpsc_linked_queue.cpp.

Definition at line 36 of file mpsc_linked_queue.inl.

◆ Enqueue() [2/2]

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

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

The item will be moved into the linked queue.

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 queue node

Definition at line 43 of file mpsc_linked_queue.inl.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

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