CMSIS-RTOS
Version 1.03
Real-Time Operating System: API and RTX Reference Implementation.
|
Manage thread-safe fixed-size blocks of dynamic memory. More...
Macros | |
#define | osFeature_Pool 1 |
Memory Pools: 1=available, 0=not available. More... | |
#define | osPoolDef(name, no, type) |
Define a Memory Pool. More... | |
#define | osPool(name) &os_pool_def_##name |
Access a Memory Pool definition. More... | |
Functions | |
osPoolId | osPoolCreate (const osPoolDef_t *pool_def) |
Create and Initialize a memory pool. More... | |
void * | osPoolAlloc (osPoolId pool_id) |
Allocate a memory block from a memory pool. More... | |
void * | osPoolCAlloc (osPoolId pool_id) |
Allocate a memory block from a memory pool and set memory block to zero. More... | |
osStatus | osPoolFree (osPoolId pool_id, void *block) |
Return an allocated memory block back to a specific memory pool. More... | |
Memory pools are fixed-size blocks of memory that are thread-safe. They operate much faster than the dynamically allocated heap and do not suffer from fragmentation. Being thread-safe, they can be accessed from threads and ISRs alike.
Shared memory is one of the basic models to exchange information between threads. Using memory pools for exchanging data, you can share more complex objects between threads if compared to a Message Queue. Memory pool management functions are used to define and manage such fixed-sized memory pools.
Follow these steps to create and use a memory pool:
#define osFeature_Pool 1 |
A CMSIS-RTOS implementation may support fixed-size memory pools.
CMSIS-RTOS RTX Setting: osFeature_Pool is 1
#define osPool | ( | name | ) | &os_pool_def_##name |
Access a memory pool for the functions osPoolCreate.
name | name of the memory pool |
#define osPoolDef | ( | name, | |
no, | |||
type | |||
) |
Define a memory pool that is referenced by osPool.
name | name of the memory pool. |
no | maximum number of blocks (objects) in the memory pool. |
type | data type of a single block (object). |
void * osPoolAlloc | ( | osPoolId | pool_id | ) |
[in] | pool_id | memory pool ID obtain referenced with osPoolCreate. |
Allocate a memory block from the memory pool.
Code Example
void * osPoolCAlloc | ( | osPoolId | pool_id | ) |
[in] | pool_id | memory pool ID obtain referenced with osPoolCreate. |
Allocate a memory block from the memory pool. The block is initialized to zero.
Code Example
osPoolId osPoolCreate | ( | const osPoolDef_t * | pool_def | ) |
[in] | pool_def | memory pool definition referenced with osPool. |
Create and initialize a memory pool.
Code Example
[in] | pool_id | memory pool ID obtain referenced with osPoolCreate. |
[in] | block | address of the allocated memory block that is returned to the memory pool. |
Return a memory block to a memory pool.
Code Example