aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-04-09 13:13:25 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-04-09 13:13:25 +0000
commit7abee7168a90b07f3746779e338b4523d48724b0 (patch)
tree69e9a206023fc4ee38add3d61b288a3146ff5600
parent151a0e84ebf6b8f9ce06696418843943b78de737 (diff)
downloadChibiOS-7abee7168a90b07f3746779e338b4523d48724b0.tar.gz
ChibiOS-7abee7168a90b07f3746779e338b4523d48724b0.tar.bz2
ChibiOS-7abee7168a90b07f3746779e338b4523d48724b0.zip
Added new function chPoolLoadArray().
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4088 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--docs/reports/STM32F407-168-GCC.txt2
-rw-r--r--os/kernel/include/chmempools.h40
-rw-r--r--os/kernel/src/chmempools.c38
-rw-r--r--readme.txt3
-rw-r--r--test/testpools.c22
5 files changed, 94 insertions, 11 deletions
diff --git a/docs/reports/STM32F407-168-GCC.txt b/docs/reports/STM32F407-168-GCC.txt
index 238741838..e28a0a1f9 100644
--- a/docs/reports/STM32F407-168-GCC.txt
+++ b/docs/reports/STM32F407-168-GCC.txt
@@ -6,7 +6,7 @@ Settings: SYSCLK=168, ACR=0x705 (5 wait states)
*** ChibiOS/RT test suite
***
*** Kernel: 2.5.0
-*** Compiled: Apr 1 2012 - 14:26:26
+*** Compiled: Apr 9 2012 - 15:07:48
*** Compiler: GCC 4.6.2
*** Architecture: ARMv7-ME
*** Core Variant: Cortex-M4
diff --git a/os/kernel/include/chmempools.h b/os/kernel/include/chmempools.h
index 8a0d6f47d..a920e2579 100644
--- a/os/kernel/include/chmempools.h
+++ b/os/kernel/include/chmempools.h
@@ -75,10 +75,50 @@ typedef struct {
#define MEMORYPOOL_DECL(name, size, provider) \
MemoryPool name = _MEMORYPOOL_DATA(name, size, provider)
+/**
+ * @name Macro Functions
+ * @{
+ */
+/**
+ * @brief Adds an object to a memory pool.
+ * @pre The memory pool must be already been initialized.
+ * @pre The added object must be of the right size for the specified
+ * memory pool.
+ * @pre The added object must be memory aligned to the size of
+ * @p stkalign_t type.
+ * @note This function is just an alias for @p chPoolFree() and has been
+ * added for clarity.
+ *
+ * @param[in] mp pointer to a @p MemoryPool structure
+ * @param[in] objp the pointer to the object to be added
+ *
+ * @api
+ */
+#define chPoolAdd(mp, objp) chPoolFree(mp, objp)
+
+/**
+ * @brief Adds an object to a memory pool.
+ * @pre The memory pool must be already been initialized.
+ * @pre The added object must be of the right size for the specified
+ * memory pool.
+ * @pre The added object must be memory aligned to the size of
+ * @p stkalign_t type.
+ * @note This function is just an alias for @p chPoolFree() and has been
+ * added for clarity.
+ *
+ * @param[in] mp pointer to a @p MemoryPool structure
+ * @param[in] objp the pointer to the object to be added
+ *
+ * @iclass
+ */
+#define chPoolAddI(mp, objp) chPoolFreeI(mp, objp)
+/** @} */
+
#ifdef __cplusplus
extern "C" {
#endif
void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider);
+ void chPoolLoadArray(MemoryPool *mp, void *p, size_t n);
void *chPoolAllocI(MemoryPool *mp);
void *chPoolAlloc(MemoryPool *mp);
void chPoolFreeI(MemoryPool *mp, void *objp);
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
@@ -61,7 +61,33 @@ void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t 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 */
/** @} */
diff --git a/readme.txt b/readme.txt
index 514f4c894..089b6e9d9 100644
--- a/readme.txt
+++ b/readme.txt
@@ -106,6 +106,9 @@
3484947)(backported to 2.4.1).
- FIX: Fixed various minor documentation errors (bug 3484942)(backported
to 2.4.1).
+- NEW: Added a new function chPoolLoadArray() to the Memory Pools subsystem,
+ it allows to load an entire array element's into a pool with a single
+ operation.
- NEW: Addes support for .S patch in the GCC ARM ports, by Ayman El-Khashab.
- NEW: Added a switch to the STM32F4 Makefile files in order to enable or
disable the FPU support in a single place.
diff --git a/test/testpools.c b/test/testpools.c
index 1c864d973..2583170fd 100644
--- a/test/testpools.c
+++ b/test/testpools.c
@@ -75,20 +75,30 @@ static void pools1_setup(void) {
static void pools1_execute(void) {
int i;
- /* Adding the WAs to the pool. */
- for (i = 0; i < MAX_THREADS; i++)
- chPoolFree(&mp1, wa[i]);
+ /* Adding the WAs to the pool.*/
+ chPoolLoadArray(&mp1, wa[0], MAX_THREADS);
- /* Empting the pool again. */
+ /* Emptying the pool.*/
for (i = 0; i < MAX_THREADS; i++)
test_assert(1, chPoolAlloc(&mp1) != NULL, "list empty");
- /* Now must be empty. */
+ /* Now must be empty.*/
test_assert(2, chPoolAlloc(&mp1) == NULL, "list not empty");
+ /* Adding the WAs to the pool, one by one this time.*/
+ for (i = 0; i < MAX_THREADS; i++)
+ chPoolFree(&mp1, wa[i]);
+
+ /* Emptying the pool again.*/
+ for (i = 0; i < MAX_THREADS; i++)
+ test_assert(3, chPoolAlloc(&mp1) != NULL, "list empty");
+
+ /* Now must be empty again.*/
+ test_assert(4, chPoolAlloc(&mp1) == NULL, "list not empty");
+
/* Covering the case where a provider is unable to return more memory.*/
chPoolInit(&mp1, 16, null_provider);
- test_assert(3, chPoolAlloc(&mp1) == NULL, "provider returned memory");
+ test_assert(5, chPoolAlloc(&mp1) == NULL, "provider returned memory");
}
ROMCONST struct testcase testpools1 = {