Memory Pools improvement.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4146 35acf78f-673a-0410-8e92-d51de3d6d3f4master
parent
c670c00668
commit
a4283e0d49
|
@ -60,7 +60,7 @@ typedef struct {
|
||||||
* @param[in] provider memory provider function for the memory pool
|
* @param[in] provider memory provider function for the memory pool
|
||||||
*/
|
*/
|
||||||
#define _MEMORYPOOL_DATA(name, size, provider) \
|
#define _MEMORYPOOL_DATA(name, size, provider) \
|
||||||
{NULL, MEM_ALIGN_NEXT(size), provider}
|
{NULL, size, provider}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static memory pool initializer in hungry mode.
|
* @brief Static memory pool initializer in hungry mode.
|
||||||
|
|
|
@ -27,7 +27,10 @@
|
||||||
* <h2>Operation mode</h2>
|
* <h2>Operation mode</h2>
|
||||||
* The Memory Pools APIs allow to allocate/free fixed size objects in
|
* The Memory Pools APIs allow to allocate/free fixed size objects in
|
||||||
* <b>constant time</b> and reliably without memory fragmentation
|
* <b>constant time</b> and reliably without memory fragmentation
|
||||||
* problems.
|
* problems.<br>
|
||||||
|
* 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.
|
||||||
* @pre In order to use the memory pools APIs the @p CH_USE_MEMPOOLS option
|
* @pre In order to use the memory pools APIs the @p CH_USE_MEMPOOLS option
|
||||||
* must be enabled in @p chconf.h.
|
* must be enabled in @p chconf.h.
|
||||||
* @{
|
* @{
|
||||||
|
@ -56,7 +59,7 @@ void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider) {
|
||||||
chDbgCheck((mp != NULL) && (size >= sizeof(void *)), "chPoolInit");
|
chDbgCheck((mp != NULL) && (size >= sizeof(void *)), "chPoolInit");
|
||||||
|
|
||||||
mp->mp_next = NULL;
|
mp->mp_next = NULL;
|
||||||
mp->mp_object_size = MEM_ALIGN_NEXT(size);
|
mp->mp_object_size = size;
|
||||||
mp->mp_provider = provider;
|
mp->mp_provider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,8 +78,7 @@ void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider) {
|
||||||
*/
|
*/
|
||||||
void chPoolLoadArray(MemoryPool *mp, void *p, size_t n) {
|
void chPoolLoadArray(MemoryPool *mp, void *p, size_t n) {
|
||||||
|
|
||||||
chDbgCheck((mp != NULL) && MEM_IS_ALIGNED(p) && (n != 0),
|
chDbgCheck((mp != NULL) && (n != 0), "chPoolLoadArray");
|
||||||
"chPoolLoadArray");
|
|
||||||
|
|
||||||
while (n) {
|
while (n) {
|
||||||
chPoolAdd(mp, p);
|
chPoolAdd(mp, p);
|
||||||
|
@ -132,8 +134,7 @@ void *chPoolAlloc(MemoryPool *mp) {
|
||||||
* @pre The memory pool must be already been initialized.
|
* @pre The memory pool must be already been initialized.
|
||||||
* @pre The freed object must be of the right size for the specified
|
* @pre The freed object must be of the right size for the specified
|
||||||
* memory pool.
|
* memory pool.
|
||||||
* @pre The freed object must be memory aligned to the size of
|
* @pre The object must be properly aligned to contain a pointer to void.
|
||||||
* @p stkalign_t type.
|
|
||||||
*
|
*
|
||||||
* @param[in] mp pointer to a @p MemoryPool structure
|
* @param[in] mp pointer to a @p MemoryPool structure
|
||||||
* @param[in] objp the pointer to the object to be released
|
* @param[in] objp the pointer to the object to be released
|
||||||
|
@ -144,8 +145,7 @@ void chPoolFreeI(MemoryPool *mp, void *objp) {
|
||||||
struct pool_header *php = objp;
|
struct pool_header *php = objp;
|
||||||
|
|
||||||
chDbgCheckClassI();
|
chDbgCheckClassI();
|
||||||
chDbgCheck((mp != NULL) && (objp != NULL) && MEM_IS_ALIGNED(objp),
|
chDbgCheck((mp != NULL) && (objp != NULL), "chPoolFreeI");
|
||||||
"chPoolFreeI");
|
|
||||||
|
|
||||||
php->ph_next = mp->mp_next;
|
php->ph_next = mp->mp_next;
|
||||||
mp->mp_next = php;
|
mp->mp_next = php;
|
||||||
|
@ -156,8 +156,7 @@ void chPoolFreeI(MemoryPool *mp, void *objp) {
|
||||||
* @pre The memory pool must be already been initialized.
|
* @pre The memory pool must be already been initialized.
|
||||||
* @pre The freed object must be of the right size for the specified
|
* @pre The freed object must be of the right size for the specified
|
||||||
* memory pool.
|
* memory pool.
|
||||||
* @pre The freed object must be memory aligned to the size of
|
* @pre The object must be properly aligned to contain a pointer to void.
|
||||||
* @p stkalign_t type.
|
|
||||||
*
|
*
|
||||||
* @param[in] mp pointer to a @p MemoryPool structure
|
* @param[in] mp pointer to a @p MemoryPool structure
|
||||||
* @param[in] objp the pointer to the object to be released
|
* @param[in] objp the pointer to the object to be released
|
||||||
|
|
|
@ -154,6 +154,9 @@
|
||||||
lwIP demos.
|
lwIP demos.
|
||||||
- NEW: lwIP related code is not centralized into a single place, no need to
|
- NEW: lwIP related code is not centralized into a single place, no need to
|
||||||
duplicate the code in each application or demo.
|
duplicate the code in each application or demo.
|
||||||
|
- CHANGE: Kernel memory pools now do not check the alignment of the inserted
|
||||||
|
objects, it is responsibility of the application to insert properly
|
||||||
|
aligned objects.
|
||||||
- CHANGE: The PORT_INT_REQUIRED_STACK parameter for the Cortex-Mx ports has
|
- CHANGE: The PORT_INT_REQUIRED_STACK parameter for the Cortex-Mx ports has
|
||||||
been increased to 32 from 16 because the stack frame sizes are increased
|
been increased to 32 from 16 because the stack frame sizes are increased
|
||||||
when compiling with optimizations disabled, which is common during
|
when compiling with optimizations disabled, which is common during
|
||||||
|
|
Loading…
Reference in New Issue