Lock-free value pool using binary tree construction.
More...
#include <lock_free_tree_value_pool.h>
|
class | Iterator |
| Forward iterator to iterate over the allocated elements of the pool. More...
|
|
template<typename Type, Type Undefined, class PoolAllocator = embb::base::Allocator< embb::base::Atomic<Type> >, class TreeAllocator = embb::base::Allocator < embb::base::Atomic<int> >>
class embb::containers::LockFreeTreeValuePool< Type, Undefined, PoolAllocator, TreeAllocator >
Lock-free value pool using binary tree construction.
- Implemented concepts:
- Value Pool Concept
- See also
- WaitFreeArrayValuePool
- Template Parameters
-
Type | Element type (must support atomic operations such as int ). |
Undefined | Bottom element (cannot be stored in the pool) |
PoolAllocator | Allocator used to allocate the pool array |
TreeAllocator | Allocator used to allocate the array representing the binary tree. |
template<typename Type , Type Undefined, class PoolAllocator = embb::base::Allocator< embb::base::Atomic<Type> >, class TreeAllocator = embb::base::Allocator < embb::base::Atomic<int> >>
template<typename ForwardIterator >
Constructs a pool and fills it with the elements in the specified range.
- Dynamic memory allocation
- Let
n = std::distance(first, last)
)
and k
be the minimum number such that n <= 2^k holds
. Then, ((2^k)-1) * sizeof(embb::Atomic<int>) + n*sizeof(embb::Atomic<Type>)
bytes of memory are allocated.
- 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 PoolAllocator = embb::base::Allocator< embb::base::Atomic<Type> >, class TreeAllocator = embb::base::Allocator < embb::base::Atomic<int> >>
Destructs the pool.
- Concurrency
- Not thread-safe
template<typename Type , Type Undefined, class PoolAllocator = embb::base::Allocator< embb::base::Atomic<Type> >, class TreeAllocator = embb::base::Allocator < embb::base::Atomic<int> >>
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 PoolAllocator = embb::base::Allocator< embb::base::Atomic<Type> >, class TreeAllocator = embb::base::Allocator < embb::base::Atomic<int> >>
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 PoolAllocator = embb::base::Allocator< embb::base::Atomic<Type> >, class TreeAllocator = embb::base::Allocator < embb::base::Atomic<int> >>
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 PoolAllocator = embb::base::Allocator< embb::base::Atomic<Type> >, class TreeAllocator = embb::base::Allocator < embb::base::Atomic<int> >>
Allocates an element from the pool.
- Returns
- Index of the element if the pool is not empty, otherwise
-1
.
- Concurrency
- Thread-safe and lock-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 PoolAllocator = embb::base::Allocator< embb::base::Atomic<Type> >, class TreeAllocator = embb::base::Allocator < embb::base::Atomic<int> >>
Returns an element to the pool.
- Note
- The element must have been allocated with Allocate().
- Concurrency
- Thread-safe and lock-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() |