Embedded Multicore Building Blocks V1.0.0
Public Member Functions | List of all members
embb::containers::LockFreeMPMCQueue< Type, ValuePool > Class Template Reference

Lock-free queue for multiple producers and multiple consumers. More...

#include <lock_free_mpmc_queue.h>

Public Member Functions

 LockFreeMPMCQueue (size_t capacity)
 Creates a queue with the specified capacity. More...
 
 ~LockFreeMPMCQueue ()
 Destroys the queue. More...
 
size_t GetCapacity ()
 Returns the capacity of the queue. More...
 
bool TryEnqueue (Type const &element)
 Tries to enqueue an element into the queue. More...
 
bool TryDequeue (Type &element)
 Tries to dequeue an element from the queue. More...
 

Detailed Description

template<typename Type, typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
class embb::containers::LockFreeMPMCQueue< Type, ValuePool >

Lock-free queue for multiple producers and multiple consumers.

Implemented concepts:
Queue Concept
See also
WaitFreeSPSCQueue
Template Parameters
TypeType of the queue elements
ValuePoolType of the value pool used as basis for the ObjectPool which stores the elements.

Constructor & Destructor Documentation

template<typename Type , typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
embb::containers::LockFreeMPMCQueue< Type, ValuePool >::LockFreeMPMCQueue ( size_t  capacity)

Creates a queue with the specified capacity.

Dynamic memory allocation
Let t be the maximum number of threads and x be 2.5*t+1. Then, x*(3*t+1) elements of size sizeof(void*), x elements of size sizeof(Type), and capacity+1 elements of size sizeof(Type) are allocated.
Concurrency
Not thread-safe
See also
Queue Concept
Parameters
[in]capacityCapacity of the queue
template<typename Type , typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
embb::containers::LockFreeMPMCQueue< Type, ValuePool >::~LockFreeMPMCQueue ( )

Destroys the queue.

Concurrency
Not thread-safe

Member Function Documentation

template<typename Type , typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
size_t embb::containers::LockFreeMPMCQueue< Type, ValuePool >::GetCapacity ( )

Returns the capacity of the queue.

Returns
Number of elements the queue can hold.
Concurrency
Thread-safe and wait-free
template<typename Type , typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
bool embb::containers::LockFreeMPMCQueue< Type, ValuePool >::TryEnqueue ( Type const &  element)

Tries to enqueue an element into the queue.

Returns
true if the element could be enqueued, false if the queue is full.
Concurrency
Thread-safe and lock-free
Note
It might be possible to enqueue more elements into the queue than its capacity permits.
See also
Queue Concept
Parameters
[in]elementConst reference to the element that shall be enqueued
template<typename Type , typename ValuePool = embb::containers::LockFreeTreeValuePool < bool, false >>
bool embb::containers::LockFreeMPMCQueue< Type, ValuePool >::TryDequeue ( Type &  element)

Tries to dequeue an element from the queue.

Returns
true if an element could be dequeued, false if the queue is empty.
Concurrency
Thread-safe and lock-free
See also
Queue Concept
Parameters
[in,out]elementReference to the dequeued element. Unchanged, if the operation was not successful.