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

Pool for thread-safe management of arbitrary objects. More...

#include <object_pool.h>

Public Member Functions

 ObjectPool (size_t capacity)
 Constructs an object pool with capacity capacity. More...
 
 ~ObjectPool ()
 Destructs the pool. More...
 
size_t GetCapacity ()
 Returns the capacity of the pool. More...
 
void Free (Type *obj)
 Returns an element to the pool. More...
 
Type * Allocate (...)
 Allocates an element from the pool. More...
 

Detailed Description

template<class Type, typename ValuePool = embb::containers::WaitFreeArrayValuePool< bool, false >, class ObjectAllocator = embb::base::Allocator<Type>>
class embb::containers::ObjectPool< Type, ValuePool, ObjectAllocator >

Pool for thread-safe management of arbitrary objects.

Template Parameters
TypeElement type
ValuePoolType of the underlying value pool, determines whether the object pool is wait-free or lock-free
ObjectAllocatorType of allocator used to allocate objects

Constructor & Destructor Documentation

template<class Type, typename ValuePool = embb::containers::WaitFreeArrayValuePool< bool, false >, class ObjectAllocator = embb::base::Allocator<Type>>
embb::containers::ObjectPool< Type, ValuePool, ObjectAllocator >::ObjectPool ( size_t  capacity)

Constructs an object pool with capacity capacity.

Dynamic memory allocation
Allocates capacity elements of type Type.
Concurrency
Not thread-safe
Parameters
[in]capacityNumber of elements the pool can hold
template<class Type, typename ValuePool = embb::containers::WaitFreeArrayValuePool< bool, false >, class ObjectAllocator = embb::base::Allocator<Type>>
embb::containers::ObjectPool< Type, ValuePool, ObjectAllocator >::~ObjectPool ( )

Destructs the pool.

Concurrency
Not thread-safe

Member Function Documentation

template<class Type, typename ValuePool = embb::containers::WaitFreeArrayValuePool< bool, false >, class ObjectAllocator = embb::base::Allocator<Type>>
size_t embb::containers::ObjectPool< Type, ValuePool, ObjectAllocator >::GetCapacity ( )

Returns the capacity of the pool.

Returns
Number of elements the pool can hold.
Concurrency
Thread-safe and wait-free
template<class Type, typename ValuePool = embb::containers::WaitFreeArrayValuePool< bool, false >, class ObjectAllocator = embb::base::Allocator<Type>>
void embb::containers::ObjectPool< Type, ValuePool, ObjectAllocator >::Free ( Type *  obj)

Returns an element to the pool.

If the underlying value pool is wait-free/lock-free, this operation is also wait-free/lock-free, respectively.

Note
The element must have been allocated with Allocate().
Parameters
[in]objPointer to the object to be freed
template<class Type, typename ValuePool = embb::containers::WaitFreeArrayValuePool< bool, false >, class ObjectAllocator = embb::base::Allocator<Type>>
Type* embb::containers::ObjectPool< Type, ValuePool, ObjectAllocator >::Allocate (   ...)

Allocates an element from the pool.

If the underlying value pool is wait-free/lock-free, this operation is also wait-free/lock-free, respectively.

Returns
Pointer to the allocated object if successful, otherwise NULL.
Parameters
...Arguments of arbitrary type, passed to the object's constructor