diff --git a/readme.txt b/readme.txt index f3672038c..1fb359a87 100644 --- a/readme.txt +++ b/readme.txt @@ -75,6 +75,8 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process, *** 0.8.2 *** - FIX: Duplicated sections in the documentation removed. +- NEW: Added chPoolAllocI() and chPoolFreeI() APIs in order to allow the use + of memory pools from interrupt handlers and timer callbacks. *** 0.8.1 *** - FIX: Fixed a regression in version 0.8.0, the configuration switch diff --git a/src/chmempools.c b/src/chmempools.c index ae97648a4..dad37aeb4 100644 --- a/src/chmempools.c +++ b/src/chmempools.c @@ -46,16 +46,28 @@ void chPoolInit(MemoryPool *mp, size_t size) { * @return The pointer to the allocated object. * @retval NULL if pool is empty. */ -void *chPoolAlloc(MemoryPool *mp) { +void *chPoolAllocI(MemoryPool *mp) { void *objp; - chDbgAssert(mp != NULL, "chpools.c, chPoolAlloc()"); - - chSysLock(); + chDbgAssert(mp != NULL, "chmempools.c, chPoolAllocI()"); if ((objp = mp->mp_next) != NULL) mp->mp_next = mp->mp_next->ph_next; + return objp; +} + +/** + * Allocates an object from a memory pool. + * @param mp pointer to a \p MemoryPool structure + * @return The pointer to the allocated object. + * @retval NULL if pool is empty. + */ +void *chPoolAlloc(MemoryPool *mp) { + void *objp; + + chSysLock(); + objp = chPoolAllocI(mp); chSysUnlock(); return objp; } @@ -67,17 +79,27 @@ void *chPoolAlloc(MemoryPool *mp) { * @note the object is assumed to be of the right size for the specified * memory pool. */ -void chPoolFree(MemoryPool *mp, void *objp) { +void chPoolFreeI(MemoryPool *mp, void *objp) { struct pool_header *php = objp; chDbgAssert((mp != NULL) && (objp != NULL), - "chpools.c, chPoolFree()"); - - chSysLock(); + "chmempools.c, chPoolFreeI()"); php->ph_next = mp->mp_next; mp->mp_next = php; +} +/** + * Releases (or adds) an object into (to) a memory pool. + * @param mp pointer to a \p MemoryPool structure + * @param objp the pointer to the object to be released or added + * @note the object is assumed to be of the right size for the specified + * memory pool. + */ +void chPoolFree(MemoryPool *mp, void *objp) { + + chSysLock(); + chPoolFreeI(mp, objp); chSysUnlock(); } diff --git a/src/include/mempools.h b/src/include/mempools.h index 0037bf487..28ddeea35 100644 --- a/src/include/mempools.h +++ b/src/include/mempools.h @@ -43,11 +43,10 @@ typedef struct { extern "C" { #endif void chPoolInit(MemoryPool *mp, size_t size); + void *chPoolAllocI(MemoryPool *mp); void *chPoolAlloc(MemoryPool *mp); + void chPoolFreeI(MemoryPool *mp, void *objp); void chPoolFree(MemoryPool *mp, void *objp); -#ifdef CH_USE_HEAP - void chPoolRelease(MemoryPool *mp); -#endif #ifdef __cplusplus } #endif