From 7abee7168a90b07f3746779e338b4523d48724b0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 9 Apr 2012 13:13:25 +0000 Subject: Added new function chPoolLoadArray(). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4088 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmempools.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chmempools.c b/os/kernel/src/chmempools.c index 6d1f7e866..8ef5cc403 100644 --- a/os/kernel/src/chmempools.c +++ b/os/kernel/src/chmempools.c @@ -60,8 +60,34 @@ void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider) { mp->mp_provider = provider; } +/** + * @brief Loads a memory pool with an array of static objects. + * @pre The memory pool must be already been initialized. + * @pre The array elements must be of the right size for the specified + * memory pool. + * @post The memory pool contains the elements of the input array. + * + * @param[in] mp pointer to a @p MemoryPool structure + * @param[in] p pointer to the array first element + * @param[in] n number of elements in the array + * + * @api + */ +void chPoolLoadArray(MemoryPool *mp, void *p, size_t n) { + + chDbgCheck((mp != NULL) && MEM_IS_ALIGNED(p) && (n != 0), + "chPoolLoadArray"); + + while (n) { + chPoolAdd(mp, p); + p = (void *)(((uint8_t *)p) + mp->mp_object_size); + n--; + } +} + /** * @brief Allocates an object from a memory pool. + * @pre The memory pool must be already been initialized. * * @param[in] mp pointer to a @p MemoryPool structure * @return The pointer to the allocated object. @@ -84,6 +110,7 @@ void *chPoolAllocI(MemoryPool *mp) { /** * @brief Allocates an object from a memory pool. + * @pre The memory pool must be already been initialized. * * @param[in] mp pointer to a @p MemoryPool structure * @return The pointer to the allocated object. @@ -101,14 +128,15 @@ void *chPoolAlloc(MemoryPool *mp) { } /** - * @brief Releases (or adds) an object into (to) a memory pool. + * @brief Releases an object into a memory pool. + * @pre The memory pool must be already been initialized. * @pre The freed object must be of the right size for the specified * memory pool. * @pre The freed object must be memory aligned to the size of * @p stkalign_t type. * * @param[in] mp pointer to a @p MemoryPool structure - * @param[in] objp the pointer to the object to be released or added + * @param[in] objp the pointer to the object to be released * * @iclass */ @@ -124,14 +152,15 @@ void chPoolFreeI(MemoryPool *mp, void *objp) { } /** - * @brief Releases (or adds) an object into (to) a memory pool. + * @brief Releases an object into a memory pool. + * @pre The memory pool must be already been initialized. * @pre The freed object must be of the right size for the specified * memory pool. * @pre The freed object must be memory aligned to the size of * @p stkalign_t type. * * @param[in] mp pointer to a @p MemoryPool structure - * @param[in] objp the pointer to the object to be released or added + * @param[in] objp the pointer to the object to be released * * @api */ @@ -141,6 +170,7 @@ void chPoolFree(MemoryPool *mp, void *objp) { chPoolFreeI(mp, objp); chSysUnlock(); } + #endif /* CH_USE_MEMPOOLS */ /** @} */ -- cgit v1.2.3