ChibiOS/RT
5.1.0
|
Memory Pools related APIs and services.
The Memory Pools APIs allow to allocate/free fixed size objects in constant time and reliably without memory fragmentation problems.
Memory Pools do not enforce any alignment constraint on the contained object however the objects must be properly aligned to contain a pointer to void.
CH_CFG_USE_MEMPOOLS
option must be enabled in chconf.h
. Macros | |
#define | _MEMORYPOOL_DATA(name, size, align, provider) {NULL, size, align, provider} |
Data part of a static memory pool initializer. More... | |
#define | MEMORYPOOL_DECL(name, size, align, provider) memory_pool_t name = _MEMORYPOOL_DATA(name, size, align, provider) |
Static memory pool initializer. More... | |
#define | _GUARDEDMEMORYPOOL_DATA(name, size, align) |
Data part of a static guarded memory pool initializer. More... | |
#define | GUARDEDMEMORYPOOL_DECL(name, size, align) guarded_memory_pool_t name = _GUARDEDMEMORYPOOL_DATA(name, size, align) |
Static guarded memory pool initializer. More... | |
Data Structures | |
struct | pool_header |
Memory pool free object header. More... | |
struct | memory_pool_t |
Memory pool descriptor. More... | |
struct | guarded_memory_pool_t |
Guarded memory pool descriptor. More... | |
Functions | |
void | chPoolObjectInitAligned (memory_pool_t *mp, size_t size, unsigned align, memgetfunc_t provider) |
Initializes an empty memory pool. More... | |
void | chPoolLoadArray (memory_pool_t *mp, void *p, size_t n) |
Loads a memory pool with an array of static objects. More... | |
void * | chPoolAllocI (memory_pool_t *mp) |
Allocates an object from a memory pool. More... | |
void * | chPoolAlloc (memory_pool_t *mp) |
Allocates an object from a memory pool. More... | |
void | chPoolFreeI (memory_pool_t *mp, void *objp) |
Releases an object into a memory pool. More... | |
void | chPoolFree (memory_pool_t *mp, void *objp) |
Releases an object into a memory pool. More... | |
void | chGuardedPoolObjectInitAligned (guarded_memory_pool_t *gmp, size_t size, unsigned align) |
Initializes an empty guarded memory pool. More... | |
void | chGuardedPoolLoadArray (guarded_memory_pool_t *gmp, void *p, size_t n) |
Loads a guarded memory pool with an array of static objects. More... | |
void * | chGuardedPoolAllocTimeoutS (guarded_memory_pool_t *gmp, sysinterval_t timeout) |
Allocates an object from a guarded memory pool. More... | |
void * | chGuardedPoolAllocTimeout (guarded_memory_pool_t *gmp, sysinterval_t timeout) |
Allocates an object from a guarded memory pool. More... | |
void | chGuardedPoolFree (guarded_memory_pool_t *gmp, void *objp) |
Releases an object into a guarded memory pool. More... | |
static void | chPoolObjectInit (memory_pool_t *mp, size_t size, memgetfunc_t provider) |
Initializes an empty memory pool. More... | |
static void | chPoolAdd (memory_pool_t *mp, void *objp) |
Adds an object to a memory pool. More... | |
static void | chPoolAddI (memory_pool_t *mp, void *objp) |
Adds an object to a memory pool. More... | |
static void | chGuardedPoolObjectInit (guarded_memory_pool_t *gmp, size_t size) |
Initializes an empty guarded memory pool. More... | |
static void * | chGuardedPoolAllocI (guarded_memory_pool_t *gmp) |
Allocates an object from a guarded memory pool. More... | |
static void | chGuardedPoolFreeI (guarded_memory_pool_t *gmp, void *objp) |
Releases an object into a guarded memory pool. More... | |
static void | chGuardedPoolFreeS (guarded_memory_pool_t *gmp, void *objp) |
Releases an object into a guarded memory pool. More... | |
static void | chGuardedPoolAdd (guarded_memory_pool_t *gmp, void *objp) |
Adds an object to a guarded memory pool. More... | |
static void | chGuardedPoolAddI (guarded_memory_pool_t *gmp, void *objp) |
Adds an object to a guarded memory pool. More... | |
static void | chGuardedPoolAddS (guarded_memory_pool_t *gmp, void *objp) |
Adds an object to a guarded memory pool. More... | |
#define _MEMORYPOOL_DATA | ( | name, | |
size, | |||
align, | |||
provider | |||
) | {NULL, size, align, provider} |
Data part of a static memory pool initializer.
This macro should be used when statically initializing a memory pool that is part of a bigger structure.
[in] | name | the name of the memory pool variable |
[in] | size | size of the memory pool contained objects |
[in] | align | required memory alignment |
[in] | provider | memory provider function for the memory pool |
Definition at line 102 of file chmempools.h.
#define MEMORYPOOL_DECL | ( | name, | |
size, | |||
align, | |||
provider | |||
) | memory_pool_t name = _MEMORYPOOL_DATA(name, size, align, provider) |
Static memory pool initializer.
Statically initialized memory pools require no explicit initialization using chPoolInit()
.
[in] | name | the name of the memory pool variable |
[in] | size | size of the memory pool contained objects |
[in] | align | required memory alignment |
[in] | provider | memory provider function for the memory pool or NULL if the pool is not allowed to grow automatically |
Definition at line 116 of file chmempools.h.
#define _GUARDEDMEMORYPOOL_DATA | ( | name, | |
size, | |||
align | |||
) |
Data part of a static guarded memory pool initializer.
This macro should be used when statically initializing a memory pool that is part of a bigger structure.
[in] | name | the name of the memory pool variable |
[in] | size | size of the memory pool contained objects |
[in] | align | required memory alignment |
Definition at line 129 of file chmempools.h.
#define GUARDEDMEMORYPOOL_DECL | ( | name, | |
size, | |||
align | |||
) | guarded_memory_pool_t name = _GUARDEDMEMORYPOOL_DATA(name, size, align) |
Static guarded memory pool initializer.
Statically initialized guarded memory pools require no explicit initialization using chGuardedPoolInit()
.
[in] | name | the name of the guarded memory pool variable |
[in] | size | size of the memory pool contained objects |
[in] | align | required memory alignment |
Definition at line 143 of file chmempools.h.
void chPoolObjectInitAligned | ( | memory_pool_t * | mp, |
size_t | size, | ||
unsigned | align, | ||
memgetfunc_t | provider | ||
) |
Initializes an empty memory pool.
[out] | mp | pointer to a memory_pool_t structure |
[in] | size | the size of the objects contained in this memory pool, the minimum accepted size is the size of a pointer to void. |
[in] | align | required memory alignment |
[in] | provider | memory provider function for the memory pool or NULL if the pool is not allowed to grow automatically |
Definition at line 77 of file chmempools.c.
References memory_pool_t::align, chDbgCheck, memory_pool_t::next, memory_pool_t::object_size, and memory_pool_t::provider.
Referenced by chGuardedPoolObjectInitAligned(), and chPoolObjectInit().
void chPoolLoadArray | ( | memory_pool_t * | mp, |
void * | p, | ||
size_t | n | ||
) |
Loads a memory pool with an array of static objects.
[in] | mp | pointer to a memory_pool_t structure |
[in] | p | pointer to the array first element |
[in] | n | number of elements in the array |
Definition at line 103 of file chmempools.c.
References chDbgCheck, chPoolAdd(), and memory_pool_t::object_size.
void * chPoolAllocI | ( | memory_pool_t * | mp | ) |
Allocates an object from a memory pool.
[in] | mp | pointer to a memory_pool_t structure |
NULL | if pool is empty. |
Definition at line 126 of file chmempools.c.
References memory_pool_t::align, chDbgCheck, chDbgCheckClassI(), pool_header::next, memory_pool_t::next, memory_pool_t::object_size, and memory_pool_t::provider.
Referenced by chGuardedPoolAllocI(), chGuardedPoolAllocTimeoutS(), and chPoolAlloc().
void * chPoolAlloc | ( | memory_pool_t * | mp | ) |
Allocates an object from a memory pool.
[in] | mp | pointer to a memory_pool_t structure |
NULL | if pool is empty. |
Definition at line 155 of file chmempools.c.
References chPoolAllocI(), chSysLock(), and chSysUnlock().
Referenced by chThdCreateFromMemoryPool().
void chPoolFreeI | ( | memory_pool_t * | mp, |
void * | objp | ||
) |
Releases an object into a memory pool.
[in] | mp | pointer to a memory_pool_t structure |
[in] | objp | the pointer to the object to be released |
Definition at line 177 of file chmempools.c.
References memory_pool_t::align, chDbgAssert, chDbgCheck, chDbgCheckClassI(), MEM_ALIGN_MASK, pool_header::next, and memory_pool_t::next.
Referenced by chGuardedPoolFreeI(), chPoolAddI(), and chPoolFree().
void chPoolFree | ( | memory_pool_t * | mp, |
void * | objp | ||
) |
Releases an object into a memory pool.
[in] | mp | pointer to a memory_pool_t structure |
[in] | objp | the pointer to the object to be released |
Definition at line 202 of file chmempools.c.
References chPoolFreeI(), chSysLock(), and chSysUnlock().
Referenced by chPoolAdd(), and chThdRelease().
void chGuardedPoolObjectInitAligned | ( | guarded_memory_pool_t * | gmp, |
size_t | size, | ||
unsigned | align | ||
) |
Initializes an empty guarded memory pool.
[out] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | size | the size of the objects contained in this guarded memory pool, the minimum accepted size is the size of a pointer to void. |
[in] | align | required memory alignment |
Definition at line 221 of file chmempools.c.
References chPoolObjectInitAligned(), chSemObjectInit(), guarded_memory_pool_t::pool, and guarded_memory_pool_t::sem.
Referenced by chFifoObjectInit(), and chGuardedPoolObjectInit().
void chGuardedPoolLoadArray | ( | guarded_memory_pool_t * | gmp, |
void * | p, | ||
size_t | n | ||
) |
Loads a guarded memory pool with an array of static objects.
[in] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | p | pointer to the array first element |
[in] | n | number of elements in the array |
Definition at line 242 of file chmempools.c.
References chDbgCheck, chGuardedPoolAdd(), memory_pool_t::object_size, and guarded_memory_pool_t::pool.
Referenced by chFifoObjectInit().
void * chGuardedPoolAllocTimeoutS | ( | guarded_memory_pool_t * | gmp, |
sysinterval_t | timeout | ||
) |
Allocates an object from a guarded memory pool.
[in] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
NULL | if the operation timed out. |
Definition at line 270 of file chmempools.c.
References chPoolAllocI(), chSemWaitTimeoutS(), MSG_OK, guarded_memory_pool_t::pool, and guarded_memory_pool_t::sem.
Referenced by chFifoTakeObjectTimeoutS(), and chGuardedPoolAllocTimeout().
void * chGuardedPoolAllocTimeout | ( | guarded_memory_pool_t * | gmp, |
sysinterval_t | timeout | ||
) |
Allocates an object from a guarded memory pool.
[in] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | timeout | the number of ticks before the operation timeouts, the following special values are allowed:
|
NULL | if the operation timed out. |
Definition at line 297 of file chmempools.c.
References chGuardedPoolAllocTimeoutS(), chSysLock(), and chSysUnlock().
Referenced by chFifoTakeObjectTimeout().
void chGuardedPoolFree | ( | guarded_memory_pool_t * | gmp, |
void * | objp | ||
) |
Releases an object into a guarded memory pool.
[in] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | objp | the pointer to the object to be released |
Definition at line 320 of file chmempools.c.
References chGuardedPoolFreeI(), chSchRescheduleS(), chSysLock(), and chSysUnlock().
Referenced by chFifoReturnObject(), and chGuardedPoolAdd().
|
inlinestatic |
Initializes an empty memory pool.
[out] | mp | pointer to a memory_pool_t structure |
[in] | size | the size of the objects contained in this memory pool, the minimum accepted size is the size of a pointer to void. |
[in] | provider | memory provider function for the memory pool or NULL if the pool is not allowed to grow automatically |
Definition at line 193 of file chmempools.h.
References chPoolObjectInitAligned().
Referenced by _factory_init().
|
inlinestatic |
Adds an object to a memory pool.
chPoolFree()
and has been added for clarity.[in] | mp | pointer to a memory_pool_t structure |
[in] | objp | the pointer to the object to be added |
Definition at line 214 of file chmempools.h.
References chPoolFree().
Referenced by chPoolLoadArray().
|
inlinestatic |
Adds an object to a memory pool.
chPoolFreeI()
and has been added for clarity.[in] | mp | pointer to a memory_pool_t structure |
[in] | objp | the pointer to the object to be added |
Definition at line 233 of file chmempools.h.
References chPoolFreeI().
|
inlinestatic |
Initializes an empty guarded memory pool.
[out] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | size | the size of the objects contained in this guarded memory pool, the minimum accepted size is the size of a pointer to void. |
Definition at line 249 of file chmempools.h.
References chGuardedPoolObjectInitAligned().
|
inlinestatic |
Allocates an object from a guarded memory pool.
[in] | gmp | pointer to a guarded_memory_pool_t structure |
NULL | if the pool is empty. |
Definition at line 265 of file chmempools.h.
References chDbgAssert, chPoolAllocI(), chSemFastWaitI(), chSemGetCounterI(), guarded_memory_pool_t::pool, and guarded_memory_pool_t::sem.
Referenced by chFifoTakeObjectI().
|
inlinestatic |
Releases an object into a guarded memory pool.
[in] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | objp | the pointer to the object to be released |
Definition at line 289 of file chmempools.h.
References chPoolFreeI(), chSemSignalI(), guarded_memory_pool_t::pool, and guarded_memory_pool_t::sem.
Referenced by chFifoReturnObjectI(), chGuardedPoolAddI(), chGuardedPoolFree(), and chGuardedPoolFreeS().
|
inlinestatic |
Releases an object into a guarded memory pool.
[in] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | objp | the pointer to the object to be released |
Definition at line 307 of file chmempools.h.
References chGuardedPoolFreeI(), and chSchRescheduleS().
Referenced by chFifoReturnObjectS(), and chGuardedPoolAddS().
|
inlinestatic |
Adds an object to a guarded memory pool.
chGuardedPoolFree()
and has been added for clarity.[in] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | objp | the pointer to the object to be added |
Definition at line 327 of file chmempools.h.
References chGuardedPoolFree().
Referenced by chGuardedPoolLoadArray().
|
inlinestatic |
Adds an object to a guarded memory pool.
chGuardedPoolFreeI()
and has been added for clarity.[in] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | objp | the pointer to the object to be added |
Definition at line 346 of file chmempools.h.
References chGuardedPoolFreeI().
|
inlinestatic |
Adds an object to a guarded memory pool.
chGuardedPoolFreeI()
and has been added for clarity.[in] | gmp | pointer to a guarded_memory_pool_t structure |
[in] | objp | the pointer to the object to be added |
Definition at line 365 of file chmempools.h.
References chGuardedPoolFreeS().