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

Wait-free queue for a single producer and a single consumer. More...

#include <wait_free_spsc_queue.h>

Public Member Functions

 WaitFreeSPSCQueue (size_t capacity)
 Creates a queue with at least the specified capacity. More...
 
 ~WaitFreeSPSCQueue ()
 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, class Allocator = embb::base::Allocator< Type >>
class embb::containers::WaitFreeSPSCQueue< Type, Allocator >

Wait-free queue for a single producer and a single consumer.

Implemented concepts:
Queue Concept
See also
LockFreeMPMCQueue
Template Parameters
TypeType of the queue elements
AllocatorAllocator type for allocating queue elements.

Constructor & Destructor Documentation

template<typename Type , class Allocator = embb::base::Allocator< Type >>
embb::containers::WaitFreeSPSCQueue< Type, Allocator >::WaitFreeSPSCQueue ( size_t  capacity)

Creates a queue with at least the specified capacity.

Dynamic memory allocation
Allocates 2^k elements of type Type, where k is the smallest number such that capacity <= 2^k holds.
Concurrency
Not thread-safe
See also
Queue Concept
Parameters
[in]capacityCapacity of the queue
template<typename Type , class Allocator = embb::base::Allocator< Type >>
embb::containers::WaitFreeSPSCQueue< Type, Allocator >::~WaitFreeSPSCQueue ( )

Destroys the queue.

Concurrency
Not thread-safe

Member Function Documentation

template<typename Type , class Allocator = embb::base::Allocator< Type >>
size_t embb::containers::WaitFreeSPSCQueue< Type, Allocator >::GetCapacity ( )

Returns the capacity of the queue.

Returns
Number of elements the queue can hold.
Concurrency
Thread-safe and wait-free
template<typename Type , class Allocator = embb::base::Allocator< Type >>
bool embb::containers::WaitFreeSPSCQueue< Type, Allocator >::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 wait-free
Note
Concurrently enqueueing elements by multiple producers leads to undefined behavior.
See also
Queue Concept
Parameters
[in]elementConst reference to the element that shall be enqueued
template<typename Type , class Allocator = embb::base::Allocator< Type >>
bool embb::containers::WaitFreeSPSCQueue< Type, Allocator >::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 wait-free
Note
Concurrently dequeueing elements by multiple consumers leads to undefined behavior.
See also
Queue Concept
Parameters
[in,out]elementReference to the dequeued element. Unchanged, if the operation was not successful.