git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@432 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2008-09-13 09:01:16 +00:00
parent e733a7d662
commit 8248aca282
4 changed files with 12 additions and 46 deletions

View File

@ -95,8 +95,8 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
- FIX: The API chSemWaitTimeout() was missing in the documentation. - FIX: The API chSemWaitTimeout() was missing in the documentation.
- CHANGE: Modified the chMtxUnlock() and chMtxUnlockS() APIs to return the - CHANGE: Modified the chMtxUnlock() and chMtxUnlockS() APIs to return the
pointer to the released mutex instead of void. pointer to the released mutex instead of void.
- CHANGE: Now the chThdResume() asserts that the thread is in PRSUSPEND state - CHANGE: Now the chThdResume() API asserts that the thread is in PRSUSPEND
rather than test it. state rather than test it.
- CHANGE: Removed the CH_USE_TERMINATE, CH_USE_SLEEP, CH_USE_SUSPEND and - CHANGE: Removed the CH_USE_TERMINATE, CH_USE_SLEEP, CH_USE_SUSPEND and
CH_USE_RESUME configuration options in order to make the chconf.h file CH_USE_RESUME configuration options in order to make the chconf.h file
simpler. The related functions are very small and almost always required. simpler. The related functions are very small and almost always required.

View File

@ -27,54 +27,36 @@
#ifdef CH_USE_MEMPOOLS #ifdef CH_USE_MEMPOOLS
/** /**
* Initializes a memory pool. * Initializes an empty memory pool.
* @param mp pointer to a \p MemoryPool structure * @param mp pointer to a \p MemoryPool structure
* @param size the size of the objects contained in this memory pool * @param size the size of the objects contained in this memory pool
* @param allow_growth if \p TRUE then the memory pool can allocate
* more space from the heap when needed
* @note The parameter \p allow_growth is ignored if the \p CH_USE_HEAP
* configuration option is not enabled.
*/ */
void chPoolInit(MemoryPool *mp, size_t size, bool_t allow_growth) { void chPoolInit(MemoryPool *mp, size_t size) {
chDbgAssert((mp != NULL) && (size >= sizeof(void *)), chDbgAssert((mp != NULL) && (size >= sizeof(void *)),
"chpools.c, chPoolFree()"); "chpools.c, chPoolFree()");
mp->mp_next = NULL; mp->mp_next = NULL;
mp->mp_object_size = size; mp->mp_object_size = size;
#ifdef CH_USE_HEAP
mp->mp_grow = allow_growth;
#endif /* CH_USE_HEAP */
} }
/** /**
* Allocates an object from a memory pool. * Allocates an object from a memory pool.
* @param mp pointer to a \p MemoryPool structure * @param mp pointer to a \p MemoryPool structure
* @return the pointer to the allocated object or \p NULL if the memory is * @return the pointer to the allocated object or \p NULL if pool is empty
* exhausted
*/ */
void *chPoolAlloc(MemoryPool *mp) { void *chPoolAlloc(MemoryPool *mp) {
void *p; void *objp;
chDbgAssert(mp != NULL, "chpools.c, chPoolAlloc()"); chDbgAssert(mp != NULL, "chpools.c, chPoolAlloc()");
chSysLock(); chSysLock();
if (mp->mp_next == NULL) { if ((objp = mp->mp_next) != NULL)
#ifdef CH_USE_HEAP mp->mp_next = mp->mp_next->ph_next;
if (mp->mp_grow) {
chSysUnlock();
return chHeapAlloc(mp->mp_object_size);
}
#endif /* CH_USE_HEAP */
return NULL;
}
p = mp->mp_next;
mp->mp_next = mp->mp_next->ph_next;
chSysUnlock(); chSysUnlock();
return p; return objp;
} }
/** /**
@ -82,7 +64,7 @@ void *chPoolAlloc(MemoryPool *mp) {
* @param mp pointer to a \p MemoryPool structure * @param mp pointer to a \p MemoryPool structure
* @param objp the pointer to the object to be released or added * @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 * @note the object is assumed to be of the right size for the specified
* buffer. * memory pool.
*/ */
void chPoolFree(MemoryPool *mp, void *objp) { void chPoolFree(MemoryPool *mp, void *objp) {
struct pool_header *php = objp; struct pool_header *php = objp;
@ -98,22 +80,6 @@ void chPoolFree(MemoryPool *mp, void *objp) {
chSysUnlock(); chSysUnlock();
} }
#ifdef CH_USE_HEAP
/**
* Releases all the objects contained into a pool.
* @param mp pointer to a \p MemoryPool structure
* @note It is assumed that all the object are allocated using the heap
* allocator, do not use this function if the pool contains other kind
* of objects, as example static areas.
*/
void chPoolRelease(MemoryPool *mp) {
void *p;
while ((p = chPoolAlloc(mp)) != NULL)
chHeapFree(p);
}
#endif
#endif /* CH_USE_MEMPOOLS */ #endif /* CH_USE_MEMPOOLS */
/** @} */ /** @} */

View File

@ -42,7 +42,7 @@ typedef struct {
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void chPoolInit(MemoryPool *mp, size_t size, bool_t allow_growth); void chPoolInit(MemoryPool *mp, size_t size);
void *chPoolAlloc(MemoryPool *mp); void *chPoolAlloc(MemoryPool *mp);
void chPoolFree(MemoryPool *mp, void *objp); void chPoolFree(MemoryPool *mp, void *objp);
#ifdef CH_USE_HEAP #ifdef CH_USE_HEAP

View File

@ -32,7 +32,7 @@ static char *pools1_gettest(void) {
static void pools1_setup(void) { static void pools1_setup(void) {
chPoolInit(&mp1, UserStackSize(THREADS_STACK_SIZE), FALSE); chPoolInit(&mp1, UserStackSize(THREADS_STACK_SIZE));
} }
static void pools1_teardown(void) { static void pools1_teardown(void) {