Wait-free value pool using array construction.
More...
#include <wait_free_array_value_pool.h>
|
class | Iterator |
| Forward iterator to iterate over the allocated elements of the pool. More...
|
|
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
-
Type | Element type (must support atomic operations such as int ). |
Undefined | Bottom element (cannot be stored in the pool) |
Allocator | Allocator used to allocate the pool array |
template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
template<typename ForwardIterator >
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] | first | Iterator pointing to the first element of the range the pool is filled with |
[in] | last | Iterator 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> >>
Destructs the pool.
- Concurrency
- Not thread-safe
template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
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> >>
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> >>
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] | capacity | count of indices that shall be guaranteed |
template<typename Type, Type Undefined, class Allocator = embb::base::Allocator< embb::base::Atomic<Type> >>
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] | element | Reference 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> >>
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] | element | Element to be returned to the pool |
[in] | index | Index of the element as obtained by Allocate() |