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

Lock-free stack. More...

#include <lock_free_stack.h>

Public Member Functions

 LockFreeStack (size_t capacity)
 Creates a stack with the specified capacity. More...
 
size_t GetCapacity ()
 Returns the capacity of the stack. More...
 
 ~LockFreeStack ()
 Destroys the stack. More...
 
bool TryPush (Type const &element)
 Tries to push an element onto the stack. More...
 
bool TryPop (Type &element)
 Tries to pop an element from the stack. More...
 

Detailed Description

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

Lock-free stack.

Implemented concepts:
Stack Concept
Template Parameters
TypeType of the stack 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::LockFreeStack< Type, ValuePool >::LockFreeStack ( size_t  capacity)

Creates a stack with the specified capacity.

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

Destroys the stack.

Concurrency
Not thread-safe

Member Function Documentation

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

Returns the capacity of the stack.

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

Tries to push an element onto the stack.

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

Tries to pop an element from the stack.

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