From 34fd822f84d409fa649934251fae01994de7888b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 17 Oct 2009 09:21:59 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1226 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmemcore.c | 4 ++-- os/kernel/src/chmempools.c | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 00e04a2d6..7177fe432 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -60,7 +60,7 @@ void core_init(void) { * sizeof(align_t). * * - * @param[in] the size of the block to be allocated + * @param[in] size the size of the block to be allocated * @return A pointer to the allocated memory block. * @retval NULL allocation failed, core memory exhausted. */ @@ -79,7 +79,7 @@ void *chCoreAlloc(size_t size) { * type @p align_t so it is not possible to allocate less than * sizeof(align_t). * - * @param[in] the size of the block to be allocated. + * @param[in] size the size of the block to be allocated. * @return A pointer to the allocated memory block. * @retval NULL allocation failed, core memory exhausted. */ diff --git a/os/kernel/src/chmempools.c b/os/kernel/src/chmempools.c index a8d7da818..76ef39b58 100644 --- a/os/kernel/src/chmempools.c +++ b/os/kernel/src/chmempools.c @@ -32,14 +32,20 @@ * * @param[out] mp pointer to a @p MemoryPool structure * @param[in] size the size of the objects contained in this memory pool, - * the minimum accepted size is the size of a pointer to void + * the minimum accepted size is the size of a pointer to void. + * + * @note The size is internally aligned to be a multiple of the @p align_t + * type size. */ void chPoolInit(MemoryPool *mp, size_t size) { chDbgCheck((mp != NULL) && (size >= sizeof(void *)), "chPoolInit"); mp->mp_next = NULL; - mp->mp_object_size = size; + mp->mp_object_size = MEM_ALIGN_SIZE(size); +#if CH_USE_MEMCORE + mp->mp_usecore = FALSE; +#endif } /** @@ -56,7 +62,10 @@ void *chPoolAllocI(MemoryPool *mp) { if ((objp = mp->mp_next) != NULL) mp->mp_next = mp->mp_next->ph_next; - +#if CH_USE_MEMCORE + else if (mp->mp_usecore) + objp = chCoreAllocI(mp->mp_object_size); +#endif return objp; } @@ -81,13 +90,17 @@ void *chPoolAlloc(MemoryPool *mp) { * * @param[in] mp pointer to a @p MemoryPool structure * @param[in] 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 * memory pool. + * @note The object is assumed to be memory aligned to the size of @p align_t + * type. */ void chPoolFreeI(MemoryPool *mp, void *objp) { struct pool_header *php = objp; - chDbgCheck((mp != NULL) && (objp != NULL), "chPoolFreeI"); + chDbgCheck((mp != NULL) && (objp != NULL) && MEM_IS_ALIGNED(objp), + "chPoolFreeI"); php->ph_next = mp->mp_next; mp->mp_next = php; -- cgit v1.2.3