µOS++ IIIe Reference  v6.3.15
“Perfekt ist nicht gut genug”
The third edition of µOS++, a POSIX inspired open source system, written in C++.
os::rtos::memory_pool_typed< T, Allocator > Class Template Reference

Template of a synchronised memory pool with block type and allocator. More...

#include <cmsis-plus/rtos/os.h>

Inherits os::rtos::memory_pool_allocated< Allocator >.

Public Types

using allocator_type = Allocator
 Standard allocator type definition. More...
 
using size_t = uint16_t
 Type of memory pool size storage. More...
 
using value_type = T
 Standard allocator type definition. More...
 

Public Member Functions

template<typename T >
constexpr std::size_t compute_allocated_size_bytes (std::size_t blocks, std::size_t block_size_bytes)
 Calculator for pool storage requirements. More...
 
Constructors & Destructor
 memory_pool_typed (std::size_t blocks, const memory_pool::attributes &attr=memory_pool::initializer, const allocator_type &allocator=allocator_type())
 Construct a memory pool object instance. More...
 
 memory_pool_typed (const char *name, std::size_t blocks, const memory_pool::attributes &attr=memory_pool::initializer, const allocator_type &allocator=allocator_type())
 Construct a named memory pool object instance. More...
 
virtual ~memory_pool_typed ()
 Destruct the memory pool object instance. More...
 
Public Member Functions
value_typealloc (void)
 Allocate a memory block. More...
 
value_typetry_alloc (void)
 Allocate a memory block. More...
 
value_typetimed_alloc (clock::duration_t timeout)
 Allocate a memory block with timeout. More...
 
result_t free (value_type *block)
 Free the memory block. More...
 
Operators
bool operator== (const memory_pool &rhs) const
 Compare memory pools. More...
 
Public Member Functions
result_t free (void *block)
 Free the memory block. More...
 
std::size_t capacity (void) const
 Get memory pool capacity. More...
 
std::size_t count (void) const
 Get blocks count. More...
 
std::size_t block_size (void) const
 Get block size. More...
 
bool empty (void) const
 Check if the memory pool is empty. More...
 
bool full (void) const
 Check if the memory pool is full. More...
 
result_t reset (void)
 Reset the memory pool. More...
 
void * pool (void)
 Get the pool storage address. More...
 
Public Member Functions
const char * name (void) const
 Get object name. More...
 

Static Public Member Functions

Operators
static void * operator new (std::size_t bytes)
 Allocate space for a new object instance using the RTOS system allocator. More...
 
static void * operator new (std::size_t bytes, void *ptr)
 Emplace a new object instance. More...
 
static void * operator new[] (std::size_t bytes)
 Allocate space for an array of new object instances using the RTOS system allocator. More...
 
static void * operator new[] (std::size_t bytes, void *ptr)
 Emplace an array of new object instances. More...
 
static void operator delete (void *ptr, std::size_t bytes)
 Deallocate the dynamically allocated object instance. using the RTOS system allocator. More...
 
static void operator delete[] (void *ptr, std::size_t bytes)
 Deallocate the dynamically allocated array of object. instances using the RTOS system allocator. More...
 

Static Public Attributes

static const attributes initializer
 Default memory pool initialiser. More...
 
static constexpr memory_pool::size_t max_size
 Maximum pool size. More...
 

Detailed Description

template<typename T, typename Allocator = memory::allocator<void*>>
class os::rtos::memory_pool_typed< T, Allocator >

Template of a synchronised memory pool with block type and allocator.

Definition at line 617 of file os-mempool.h.

Types

◆ allocator_type

template<typename T, typename Allocator = memory::allocator<void*>>
using os::rtos::memory_pool_typed< T, Allocator >::allocator_type = Allocator

Standard allocator type definition.

Definition at line 628 of file os-mempool.h.

◆ value_type

template<typename T, typename Allocator = memory::allocator<void*>>
using os::rtos::memory_pool_typed< T, Allocator >::value_type = T

Standard allocator type definition.

Definition at line 624 of file os-mempool.h.

Constructor & Destructor Documentation

◆ memory_pool_typed() [1/2]

template<typename T , typename Allocator >
os::rtos::memory_pool_typed< T, Allocator >::memory_pool_typed ( std::size_t  blocks,
const memory_pool::attributes attr = memory_pool::initializer,
const allocator_type allocator = allocator_type () 
)
inline

Construct a memory pool object instance.

Parameters
[in]blocksThe maximum number of items in the pool.
[in]attrReference to attributes.
[in]allocatorReference to allocator. Default a local temporary instance.

This constructor shall initialise a memory pool object with attributes referenced by attr. If the attributes specified by attr are modified later, the memory pool attributes shall not be affected. Upon successful initialisation, the state of the memory pool variable shall become initialised.

Only the memory pool itself may be used for allocations. It is not allowed to make copies of condition variable objects.

In cases where default memory pool attributes are appropriate, the variable memory_pool::initializer can be used to initialise condition variables. The effect shall be equivalent to creating a memory pool object with the simple constructor.

If the attributes define a storage area (via mp_pool_address and mp_pool_size_bytes), that storage is used, otherwise the storage is dynamically allocated using the RTOS specific allocator (rtos::memory::allocator).

Implemented as a wrapper over the parent constructor, automatically passing the message size.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 1138 of file os-mempool.h.

◆ memory_pool_typed() [2/2]

template<typename T , typename Allocator >
os::rtos::memory_pool_typed< T, Allocator >::memory_pool_typed ( const char *  name,
std::size_t  blocks,
const memory_pool::attributes attr = memory_pool::initializer,
const allocator_type allocator = allocator_type () 
)
inline

Construct a named memory pool object instance.

Parameters
[in]namePointer to name.
[in]blocksThe maximum number of items in the pool.
[in]attrReference to attributes.
[in]allocatorReference to allocator. Default a local temporary instance.

This constructor shall initialise a named memory pool object with attributes referenced by attr. If the attributes specified by attr are modified later, the memory pool attributes shall not be affected. Upon successful initialisation, the state of the memory pool variable shall become initialised.

Only the memory pool itself may be used for allocations. It is not allowed to make copies of condition variable objects.

In cases where default memory pool attributes are appropriate, the variable memory_pool::initializer can be used to initialise condition variables. The effect shall be equivalent to creating a memory pool object with the simple constructor.

If the attributes define a storage area (via mp_pool_address and mp_pool_size_bytes), that storage is used, otherwise the storage is dynamically allocated using the RTOS specific allocator (rtos::memory::allocator).

Implemented as a wrapper over the parent constructor, automatically passing the message size.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 1177 of file os-mempool.h.

◆ ~memory_pool_typed()

template<typename T , typename Allocator >
os::rtos::memory_pool_typed< T, Allocator >::~memory_pool_typed ( )
virtual

Destruct the memory pool object instance.

This destructor shall destroy a memory pool object; the object becomes, in effect, uninitialised. An implementation may cause the destructor to set the object to an invalid value.

It shall be safe to destroy an initialised memory pool object upon which no threads are currently blocked. Attempting to destroy a memory pool object upon which other threads are currently blocked results in undefined behaviour.

If the storage for the memory pool was dynamically allocated, it is deallocated using the same allocator.

Implemented as a wrapper over the parent destructor.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 1205 of file os-mempool.h.

Member Function Documentation

◆ alloc()

template<typename T , typename Allocator >
memory_pool_typed< T, Allocator >::value_type * os::rtos::memory_pool_typed< T, Allocator >::alloc ( void  )
inline

Allocate a memory block.

Parameters
None.
Returns
Pointer to memory block, or nullptr if interrupted.

Wrapper over the parent method, automatically passing the cast.

See also
memory_pool::alloc().

Definition at line 1219 of file os-mempool.h.

◆ block_size()

std::size_t os::rtos::memory_pool::block_size ( void  ) const
inlineinherited

Get block size.

Parameters
None.
Returns
The block size, in bytes.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 919 of file os-mempool.h.

◆ capacity()

std::size_t os::rtos::memory_pool::capacity ( void  ) const
inlineinherited

Get memory pool capacity.

Parameters
None.
Returns
The max number of blocks in the pool.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 908 of file os-mempool.h.

◆ compute_allocated_size_bytes()

template<typename T >
constexpr std::size_t os::rtos::memory_pool::compute_allocated_size_bytes ( std::size_t  blocks,
std::size_t  block_size_bytes 
)
inlineinherited

Calculator for pool storage requirements.

Parameters
blocksNumber of blocks.
block_size_bytesSize of block.
Returns
Total required storage in bytes, including internal alignment.

Definition at line 179 of file os-mempool.h.

◆ count()

std::size_t os::rtos::memory_pool::count ( void  ) const
inlineinherited

Get blocks count.

Parameters
None.
Returns
The number of blocks used from the queue.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 930 of file os-mempool.h.

◆ empty()

bool os::rtos::memory_pool::empty ( void  ) const
inlineinherited

Check if the memory pool is empty.

Parameters
None
Return values
trueThe memory pool has no allocated blocks.
falseThe memory pool has allocated blocks.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 941 of file os-mempool.h.

◆ free() [1/2]

result_t os::rtos::memory_pool::free ( void *  block)
inherited

Free the memory block.

Parameters
[in]blockPointer to memory block to free.
Return values
result::okThe memory block was released.
EINVALThe block does not belong to the memory pool.

Return a memory block previously allocated by alloc() back to the memory pool.

It uses a critical section to protect simultaneous access from other threads or interrupts.

Note
Can be invoked from Interrupt Service Routines.

Definition at line 764 of file os-mempool.cpp.

◆ free() [2/2]

template<typename T , typename Allocator >
result_t os::rtos::memory_pool_typed< T, Allocator >::free ( value_type block)
inline

Free the memory block.

Parameters
None.
Return values
result::okThe memory block was released.
EINVALThe block does not belong to the memory pool.

Wrapper over the parent method, automatically passing the cast.

See also
memory_pool::free().

Definition at line 1262 of file os-mempool.h.

◆ full()

bool os::rtos::memory_pool::full ( void  ) const
inlineinherited

Check if the memory pool is full.

Parameters
None.
Return values
trueAll memory blocks are allocated.
falseThere are still memory blocks that can be allocated.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 952 of file os-mempool.h.

◆ name()

const char * os::rtos::internal::object_named::name ( void  ) const
inlineinherited

Get object name.

Parameters
None.
Returns
A null terminated string.

All objects return a non-null string; anonymous objects return "-".

Note
Can be invoked from Interrupt Service Routines.

Definition at line 760 of file os-decls.h.

◆ operator delete()

void os::rtos::internal::object_named_system::operator delete ( void *  ptr,
std::size_t  bytes 
)
inlinestaticinherited

Deallocate the dynamically allocated object instance. using the RTOS system allocator.

Parameters
ptrPointer to object.
bytesNumber of bytes to deallocate.
Returns
Nothing.

The deallocation function (3.7.4.2) called by a delete-expression to render the value of ptr invalid.

ptr shall be a null pointer or its value shall be a value returned by an earlier call to the (possibly replaced) operator new() which has not been invalidated by an intervening call to operator delete(void*).

If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the earlier call to operator new.

The storage is deallocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 134 of file os-inlines.h.

◆ operator delete[]()

void os::rtos::internal::object_named_system::operator delete[] ( void *  ptr,
std::size_t  bytes 
)
inlinestaticinherited

Deallocate the dynamically allocated array of object. instances using the RTOS system allocator.

Parameters
ptrPointer to array of objects.
bytesNumber of bytes to deallocate.
Returns
Nothing.

The deallocation function (3.7.4.2) called by the array form of a delete-expression to render the value of ptr invalid.

If ptr is null, does nothing. Otherwise, reclaims the storage allocated by the earlier call to operator new.

The storage is deallocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 155 of file os-inlines.h.

◆ operator new() [1/2]

void * os::rtos::internal::object_named_system::operator new ( std::size_t  bytes)
inlinestaticinherited

Allocate space for a new object instance using the RTOS system allocator.

Parameters
bytesNumber of bytes to allocate.
Returns
Pointer to allocated object.

The allocation function (3.7.4.1) called by a new-expression (5.3.4) to allocate a storage of size bytes suitably aligned to represent any object of that size. Return a non-null pointer to suitably aligned storage (3.7.4).

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 56 of file os-inlines.h.

◆ operator new() [2/2]

void * os::rtos::internal::object_named_system::operator new ( std::size_t  bytes,
void *  ptr 
)
inlinestaticinherited

Emplace a new object instance.

Parameters
bytesNumber of bytes to emplace.
ptrPointer to location to emplace the object.
Returns
Pointer to emplaced object.

The allocation function (3.7.4.1) called by a placement new-expression to allocate a storage of size bytes suitably aligned to represent any object of that size. Return a non-null pointer to suitably aligned storage (3.7.4).

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 93 of file os-inlines.h.

◆ operator new[]() [1/2]

void * os::rtos::internal::object_named_system::operator new[] ( std::size_t  bytes)
inlinestaticinherited

Allocate space for an array of new object instances using the RTOS system allocator.

Parameters
bytesNumber of bytes to allocate.
Returns
Pointer to allocated array.

The allocation function (3.7.4.1) called by the array form of a new-expression (5.3.4) to allocate a storage of size bytes suitably aligned to represent any array object of that size or smaller.

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 74 of file os-inlines.h.

◆ operator new[]() [2/2]

void * os::rtos::internal::object_named_system::operator new[] ( std::size_t  bytes,
void *  ptr 
)
inlinestaticinherited

Emplace an array of new object instances.

Parameters
bytesNumber of bytes to emplace.
ptrPointer to location to emplace the object.
Returns
Pointer to emplaced array.

The allocation function (3.7.4.1) called by the array form of a placement new-expression to allocate a storage of size bytes suitably aligned to represent any array object of that size or smaller.

The storage is allocated using the RTOS system allocator.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 110 of file os-inlines.h.

◆ operator==()

bool os::rtos::memory_pool::operator== ( const memory_pool rhs) const
inlineinherited

Compare memory pools.

Return values
trueThe given memory pool is the same as this memory pool.
falseThe memory pools are different.

Identical memory pools should have the same memory address.

Definition at line 897 of file os-mempool.h.

◆ pool()

void * os::rtos::memory_pool::pool ( void  )
inlineinherited

Get the pool storage address.

Parameters
None.
Returns
Pointer to storage.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 963 of file os-mempool.h.

◆ reset()

result_t os::rtos::memory_pool::reset ( void  )
inherited

Reset the memory pool.

Parameters
None.
Return values
result::okThe memory pool was reset.
EPERMCannot be invoked from an Interrupt Service Routines.

Reset the memory pool to the initial state, with all blocks free.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 816 of file os-mempool.cpp.

◆ timed_alloc()

template<typename T , typename Allocator >
memory_pool_typed< T, Allocator >::value_type * os::rtos::memory_pool_typed< T, Allocator >::timed_alloc ( clock::duration_t  timeout)
inline

Allocate a memory block with timeout.

Parameters
[in]timeoutTimeout to wait, in clock units (ticks or seconds).
Returns
Pointer to memory block, or nullptr if timeout.

Wrapper over the parent method, automatically passing the cast.

See also
memory_pool::timed_alloc().

Definition at line 1247 of file os-mempool.h.

◆ try_alloc()

template<typename T , typename Allocator >
memory_pool_typed< T, Allocator >::value_type * os::rtos::memory_pool_typed< T, Allocator >::try_alloc ( void  )
inline

Allocate a memory block.

Parameters
None.
Returns
Pointer to memory block, or nullptr if no memory available.

Wrapper over the parent method, automatically passing the cast.

See also
memory_pool::try_alloc().

Definition at line 1233 of file os-mempool.h.


The documentation for this class was generated from the following file: