Template of a synchronised memory pool with block type and local storage. More...
#include <cmsis-plus/rtos/os.h>
Inheritance diagram for os::rtos::memory_pool_inclusive< T, N >:Public Types | |
| using | allocator_type = memory::allocator< thread::stack::allocation_element_t > |
| Default RTOS allocator. | |
| using | size_t = uint16_t |
| Type of memory pool size storage. | |
| using | value_type = T |
| Local type of message. | |
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. | |
Constructors & Destructor | |
| memory_pool_inclusive (const attributes &attr=initializer) | |
| Construct a memory pool object instance. | |
| memory_pool_inclusive (const char *name, const attributes &attr=initializer) | |
| Construct a named memory pool object instance. | |
| virtual | ~memory_pool_inclusive () override |
| Destruct the memory pool object instance. | |
Public Member Functions | |
| value_type * | alloc (void) |
| Allocate a memory block. | |
| value_type * | try_alloc (void) |
| Allocate a memory block. | |
| value_type * | timed_alloc (clock::duration_t timeout) |
| Allocate a memory block with timeout. | |
| result_t | free (value_type *block) |
| Free the memory block. | |
Operators | |
| bool | operator== (const memory_pool &rhs) const |
| Compare memory pools. | |
Public Member Functions | |
| result_t | free (void *block) |
| Free the memory block. | |
| std::size_t | capacity (void) const |
| Get memory pool capacity. | |
| std::size_t | count (void) const |
| Get blocks count. | |
| std::size_t | block_size (void) const |
| Get block size. | |
| bool | empty (void) const |
| Check if the memory pool is empty. | |
| bool | full (void) const |
| Check if the memory pool is full. | |
| result_t | reset (void) |
| Reset the memory pool. | |
| void * | pool (void) |
| Get the pool storage address. | |
Public Member Functions | |
| const char * | name (void) const |
| Get object name. | |
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. | |
| static void * | operator new (std::size_t bytes, void *ptr) |
| Emplace a new object instance. | |
| static void * | operator new[] (std::size_t bytes) |
| Allocate space for an array of new object instances using the RTOS system allocator. | |
| static void * | operator new[] (std::size_t bytes, void *ptr) |
| Emplace an array of new object instances. | |
| static void | operator delete (void *ptr, std::size_t bytes) |
| Deallocate the dynamically allocated object instance. using the RTOS system allocator. | |
| static void | operator delete[] (void *ptr, std::size_t bytes) |
| Deallocate the dynamically allocated array of object. instances using the RTOS system allocator. | |
Static Public Attributes | |
| static const std::size_t | blocks = N |
| Local constant based on template definition. | |
| static const attributes | initializer |
| Default memory pool initialiser. | |
| static constexpr memory_pool::size_t | max_size = static_cast<memory_pool::size_t> (0 - 1) |
| Maximum pool size. | |
Protected Attributes | |
Private Member Variables | |
| arena< void *, blocks, sizeof(T)> | arena_ |
| Local storage for the pool. | |
Definition at line 755 of file os-mempool.h.
|
inherited |
Definition at line 201 of file os-mempool.h.
| using os::rtos::memory_pool_inclusive< T, N >::value_type = T |
Definition at line 761 of file os-mempool.h.
| os::rtos::memory_pool_inclusive< T, N >::memory_pool_inclusive | ( | const attributes & | attr = initializer | ) |
| [in] | attr | Reference to attributes. |
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.
The storage shall be statically allocated inside the memory pool object instance.
Implemented as a wrapper over the parent constructor, automatically passing the message size and the storage details.
Definition at line 1291 of file os-mempool.h.
| os::rtos::memory_pool_inclusive< T, N >::memory_pool_inclusive | ( | const char * | name, |
| const attributes & | attr = initializer |
||
| ) |
| [in] | name | Pointer to name. |
| [in] | attr | Reference to attributes. |
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.
The storage shall be statically allocated inside the memory pool object instance.
Implemented as a wrapper over the parent constructor, automatically passing the message size and the storage details.
Definition at line 1323 of file os-mempool.h.
References os::rtos::memory_pool_inclusive< T, N >::arena_, and os::rtos::memory_pool_inclusive< T, N >::blocks.
|
overridevirtual |
This destructor shall destroy the 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.
Definition at line 1344 of file os-mempool.h.
|
inline |
nullptr if interrupted.Wrapper over the parent method, automatically passing the cast.
Definition at line 1357 of file os-mempool.h.
References os::rtos::memory_pool::alloc().
|
inlineinherited |
Definition at line 923 of file os-mempool.h.
|
inlineinherited |
Definition at line 914 of file os-mempool.h.
Referenced by os::rtos::memory_pool::full().
|
inlineconstexprinherited |
| blocks | Number of blocks. |
| block_size_bytes | Size of block. |
Definition at line 188 of file os-mempool.h.
Referenced by os::rtos::memory_pool::memory_pool(), and os::rtos::memory_pool_allocated< Allocator >::memory_pool_allocated().
|
inlineinherited |
Definition at line 932 of file os-mempool.h.
Referenced by os::rtos::memory_pool::empty(), and os::rtos::memory_pool::full().
|
inlineinherited |
| true | The memory pool has no allocated blocks. |
| false | The memory pool has allocated blocks. |
Definition at line 941 of file os-mempool.h.
References os::rtos::memory_pool::count().
|
inline |
| result::ok | The memory block was released. |
| EINVAL | The block does not belong to the memory pool. |
Wrapper over the parent method, automatically passing the cast.
Definition at line 1399 of file os-mempool.h.
References os::rtos::memory_pool::free().
|
inherited |
| [in] | block | Pointer to memory block to free. |
| result::ok | The memory block was released. |
| EINVAL | The 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.
Definition at line 781 of file os-mempool.cpp.
References os::rtos::internal::object_named::name(), os::rtos::result::ok, and os::trace::printf().
Referenced by os::rtos::memory_pool_typed< T, Allocator >::free(), and os::rtos::memory_pool_inclusive< T, N >::free().
|
inlineinherited |
| true | All memory blocks are allocated. |
| false | There are still memory blocks that can be allocated. |
Definition at line 950 of file os-mempool.h.
References os::rtos::memory_pool::capacity(), and os::rtos::memory_pool::count().
|
inlineinherited |
All objects return a non-null string; anonymous objects return "-".
Definition at line 753 of file os-decls.h.
Referenced by os::memory::lifo::lifo(), os::memory::malloc_memory_resource::malloc_memory_resource(), os::rtos::message_queue_typed< T, Allocator >::message_queue_typed(), os::memory::block_pool::~block_pool(), os::rtos::event_flags::~event_flags(), os::memory::first_fit_top::~first_fit_top(), os::memory::lifo::~lifo(), os::memory::malloc_memory_resource::~malloc_memory_resource(), os::rtos::memory_pool::~memory_pool(), os::rtos::message_queue::~message_queue(), os::rtos::mutex::~mutex(), os::rtos::semaphore::~semaphore(), os::rtos::thread::~thread(), os::rtos::timer::~timer(), os::rtos::memory_pool::alloc(), os::rtos::thread::cancel(), os::rtos::event_flags::clear(), os::rtos::mutex::consistent(), os::rtos::thread::detach(), os::memory::new_delete_memory_resource::do_allocate(), os::memory::block_pool::do_allocate(), os::memory::first_fit_top::do_allocate(), os::memory::lifo::do_allocate(), os::memory::malloc_memory_resource::do_allocate(), os::rtos::thread::flags_raise(), os::rtos::memory_pool::free(), os::rtos::event_flags::get(), os::rtos::thread::interrupt(), os::rtos::thread::join(), os::rtos::thread::kill(), os::rtos::internal::terminated_threads_list::link(), os::rtos::mutex::lock(), os::rtos::memory::memory_resource::out_of_memory_handler(), os::rtos::semaphore::post(), os::rtos::mutex::prio_ceiling(), os::rtos::mutex::prio_ceiling(), os::rtos::thread::priority(), os::rtos::thread::priority_inherited(), os::rtos::event_flags::raise(), os::rtos::message_queue::receive(), os::rtos::memory_pool::reset(), os::rtos::message_queue::reset(), os::rtos::mutex::reset(), os::rtos::semaphore::reset(), os::rtos::thread::resume(), os::rtos::message_queue::send(), os::rtos::clock::sleep_for(), os::rtos::timer::start(), os::rtos::timer::stop(), os::rtos::memory_pool::timed_alloc(), os::rtos::mutex::timed_lock(), os::rtos::message_queue::timed_receive(), os::rtos::message_queue::timed_send(), os::rtos::semaphore::timed_wait(), os::rtos::event_flags::timed_wait(), os::rtos::memory::memory_resource::trace_print_statistics(), os::rtos::memory_pool::try_alloc(), os::rtos::mutex::try_lock(), os::rtos::message_queue::try_receive(), os::rtos::message_queue::try_send(), os::rtos::event_flags::try_wait(), os::rtos::semaphore::try_wait(), os::rtos::internal::ready_threads_list::unlink_head(), os::rtos::mutex::unlock(), os::rtos::event_flags::wait(), os::rtos::semaphore::wait(), and os::rtos::event_flags::waiting().
|
inlinestaticinherited |
| ptr | Pointer to object. |
| bytes | Number of bytes to deallocate. |
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.
Definition at line 120 of file os-inlines.h.
References os::rtos::memory::allocator_stateless_default_resource< T >::deallocate(), and os::rtos::interrupts::in_handler_mode().
|
inlinestaticinherited |
| ptr | Pointer to array of objects. |
| bytes | Number of bytes to deallocate. |
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.
Definition at line 141 of file os-inlines.h.
|
inlinestaticinherited |
| bytes | Number of bytes to allocate. |
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.
Definition at line 43 of file os-inlines.h.
References os::rtos::memory::allocator_stateless_default_resource< T >::allocate(), and os::rtos::interrupts::in_handler_mode().
|
inlinestaticinherited |
| bytes | Number of bytes to emplace. |
| ptr | Pointer to location to emplace the 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.
Definition at line 80 of file os-inlines.h.
|
inlinestaticinherited |
| bytes | Number of bytes to allocate. |
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.
Definition at line 61 of file os-inlines.h.
|
inlinestaticinherited |
| bytes | Number of bytes to emplace. |
| ptr | Pointer to location to emplace the object. |
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.
Definition at line 97 of file os-inlines.h.
|
inlineinherited |
| true | The given memory pool is the same as this memory pool. |
| false | The memory pools are different. |
Identical memory pools should have the same memory address.
Definition at line 905 of file os-mempool.h.
|
inlineinherited |
Definition at line 959 of file os-mempool.h.
|
inherited |
| result::ok | The memory pool was reset. |
| EPERM | Cannot be invoked from an Interrupt Service Routines. |
Reset the memory pool to the initial state, with all blocks free.
Definition at line 846 of file os-mempool.cpp.
References os::rtos::interrupts::in_handler_mode(), os::rtos::internal::object_named::name(), os::rtos::result::ok, os_assert_err, and os::trace::printf().
|
inline |
| [in] | timeout | Timeout to wait, in clock units (ticks or seconds). |
nullptr if timeout.Wrapper over the parent method, automatically passing the cast.
Definition at line 1385 of file os-mempool.h.
References os::rtos::memory_pool::timed_alloc().
|
inline |
nullptr if no memory available.Wrapper over the parent method, automatically passing the cast.
Definition at line 1371 of file os-mempool.h.
References os::rtos::memory_pool::try_alloc().
|
protected |
The local storage is large enough to include blocks blocks of type T. For performance reasons, the individual components are aligned as pointers.
Definition at line 829 of file os-mempool.h.
Referenced by os::rtos::memory_pool_inclusive< T, N >::memory_pool_inclusive().
|
static |
Definition at line 766 of file os-mempool.h.
Referenced by os::rtos::memory_pool_inclusive< T, N >::memory_pool_inclusive().