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

Wait-free value pool using array construction. More...

#include <wait_free_array_value_pool.h>

Classes

class  Iterator
 Forward iterator to iterate over the allocated elements of the pool. More...
 

Public Member Functions

Iterator Begin ()
 Gets a forward iterator to the first allocated element in the pool. More...
 
Iterator End ()
 Gets a forward iterator pointing after the last allocated element in the pool. More...
 
template<typename ForwardIterator >
 WaitFreeArrayValuePool (ForwardIterator first, ForwardIterator last)
 Constructs a pool and fills it with the elements in the specified range. More...
 
 ~WaitFreeArrayValuePool ()
 Destructs the pool. More...
 
int Allocate (Type &element)
 Allocates an element from the pool. More...
 
void Free (Type element, int index)
 Returns an element to the pool. More...
 

Static Public Member Functions

static size_t GetMinimumElementCountForGuaranteedCapacity (size_t capacity)
 Due to concurrency effects, a pool might provide less elements than managed by it. More...
 

Detailed Description

template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
class embb::containers::WaitFreeArrayValuePool< Type, Undefined, Allocator >

Wait-free value pool using array construction.

Implemented concepts:
Value Pool Concept
See also
LockFreeTreeValuePool
Template Parameters
TypeElement type (must support atomic operations such as int).
UndefinedBottom element (cannot be stored in the pool)
AllocatorAllocator used to allocate the pool array

Constructor & Destructor Documentation

template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
template<typename ForwardIterator >
embb::containers::WaitFreeArrayValuePool< Type, Undefined, Allocator >::WaitFreeArrayValuePool ( ForwardIterator  first,
ForwardIterator  last 
)

Constructs a pool and fills it with the elements in the specified range.

Dynamic memory allocation
Dynamically allocates n*sizeof(embb::base::Atomic<Type>) bytes, where n = std::distance(first, last) is the number of pool elements.
Concurrency
Not thread-safe
See also
Value Pool Concept
Parameters
[in]firstIterator pointing to the first element of the range the pool is filled with
[in]lastIterator pointing to the last plus one element of the range the pool is filled with
template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
embb::containers::WaitFreeArrayValuePool< Type, Undefined, Allocator >::~WaitFreeArrayValuePool ( )

Destructs the pool.

Concurrency
Not thread-safe

Member Function Documentation

template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
Iterator embb::containers::WaitFreeArrayValuePool< Type, Undefined, Allocator >::Begin ( )

Gets a forward iterator to the first allocated element in the pool.

Returns
a forward iterator pointing to the first allocated element.
Concurrency
Thread-safe and wait-free
template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
Iterator embb::containers::WaitFreeArrayValuePool< Type, Undefined, Allocator >::End ( )

Gets a forward iterator pointing after the last allocated element in the pool.

Returns
a forward iterator pointing after the last allocated element.
Concurrency
Thread-safe and wait-free
template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
static size_t embb::containers::WaitFreeArrayValuePool< Type, Undefined, Allocator >::GetMinimumElementCountForGuaranteedCapacity ( size_t  capacity)
static

Due to concurrency effects, a pool might provide less elements than managed by it.

However, usually one wants to guarantee a minimal capacity. The count of elements that must be given to the pool when to guarantee capacity elements is computed using this function.

Returns
count of indices the pool has to be initialized with
Parameters
[in]capacitycount of indices that shall be guaranteed
template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
int embb::containers::WaitFreeArrayValuePool< Type, Undefined, Allocator >::Allocate ( Type &  element)

Allocates an element from the pool.

Returns
Index of the element if the pool is not empty, otherwise -1.
Concurrency
Thread-safe and wait-free
See also
Value Pool Concept
Parameters
[in,out]elementReference to the allocated element. Unchanged, if the operation was not successful.
template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
void embb::containers::WaitFreeArrayValuePool< Type, Undefined, Allocator >::Free ( Type  element,
int  index 
)

Returns an element to the pool.

Note
The element must have been allocated with Allocate().
Concurrency
Thread-safe and wait-free
See also
Value Pool Concept
Parameters
[in]elementElement to be returned to the pool
[in]indexIndex of the element as obtained by Allocate()