aboutsummaryrefslogtreecommitdiffstats
path: root/os/lib/include/chmempools.h
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-06-15 09:11:07 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-06-15 09:11:07 +0000
commit7d47d8cf46c4728c277d0971efd7f5a3f7368cec (patch)
tree5a3176c064d83b43eda8e4423d5c74aa987969bf /os/lib/include/chmempools.h
parent4a78d17518b55d8c3818f9f6711aff691a8d9298 (diff)
downloadChibiOS-7d47d8cf46c4728c277d0971efd7f5a3f7368cec.tar.gz
ChibiOS-7d47d8cf46c4728c277d0971efd7f5a3f7368cec.tar.bz2
ChibiOS-7d47d8cf46c4728c277d0971efd7f5a3f7368cec.zip
New API added to pools and fifos.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12100 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'os/lib/include/chmempools.h')
-rw-r--r--os/lib/include/chmempools.h82
1 files changed, 68 insertions, 14 deletions
diff --git a/os/lib/include/chmempools.h b/os/lib/include/chmempools.h
index 60d6a8da9..72c1e60dd 100644
--- a/os/lib/include/chmempools.h
+++ b/os/lib/include/chmempools.h
@@ -163,7 +163,6 @@ extern "C" {
sysinterval_t timeout);
void *chGuardedPoolAllocTimeout(guarded_memory_pool_t *gmp,
sysinterval_t timeout);
- void chGuardedPoolFreeI(guarded_memory_pool_t *gmp, void *objp);
void chGuardedPoolFree(guarded_memory_pool_t *gmp, void *objp);
#endif
#ifdef __cplusplus
@@ -252,6 +251,64 @@ static inline void chGuardedPoolObjectInit(guarded_memory_pool_t *gmp,
}
/**
+ * @brief Allocates an object from a guarded memory pool.
+ * @pre The guarded memory pool must be already been initialized.
+ *
+ * @param[in] gmp pointer to a @p guarded_memory_pool_t structure
+ * @return The pointer to the allocated object.
+ * @retval NULL if the pool is empty.
+ *
+ * @iclass
+ */
+static inline void *chGuardedPoolAllocI(guarded_memory_pool_t *gmp) {
+ void *p;
+
+ p = chPoolAllocI(&gmp->pool);
+ if (p != NULL) {
+ chSemFastWaitI(&gmp->sem);
+ chDbgAssert(chSemGetCounterI(&gmp->sem) >= (cnt_t)0,
+ "semaphore out of sync");
+ }
+ return p;
+}
+
+/**
+ * @brief Releases an object into a guarded memory pool.
+ * @pre The guarded memory pool must already be initialized.
+ * @pre The freed object must be of the right size for the specified
+ * guarded memory pool.
+ * @pre The added object must be properly aligned.
+ *
+ * @param[in] gmp pointer to a @p guarded_memory_pool_t structure
+ * @param[in] objp the pointer to the object to be released
+ *
+ * @iclass
+ */
+static inline void chGuardedPoolFreeI(guarded_memory_pool_t *gmp, void *objp) {
+
+ chPoolFreeI(&gmp->pool, objp);
+ chSemSignalI(&gmp->sem);
+}
+
+/**
+ * @brief Releases an object into a guarded memory pool.
+ * @pre The guarded memory pool must already be initialized.
+ * @pre The freed object must be of the right size for the specified
+ * guarded memory pool.
+ * @pre The added object must be properly aligned.
+ *
+ * @param[in] gmp pointer to a @p guarded_memory_pool_t structure
+ * @param[in] objp the pointer to the object to be released
+ *
+ * @sclass
+ */
+static inline void chGuardedPoolFreeS(guarded_memory_pool_t *gmp, void *objp) {
+
+ chGuardedPoolFreeI(gmp, objp);
+ chSchRescheduleS();
+}
+
+/**
* @brief Adds an object to a guarded memory pool.
* @pre The guarded memory pool must be already been initialized.
* @pre The added object must be of the right size for the specified
@@ -290,25 +347,22 @@ static inline void chGuardedPoolAddI(guarded_memory_pool_t *gmp, void *objp) {
}
/**
- * @brief Allocates an object from a guarded memory pool.
+ * @brief Adds an object to a guarded memory pool.
* @pre The guarded memory pool must be already been initialized.
+ * @pre The added object must be of the right size for the specified
+ * guarded memory pool.
+ * @pre The added object must be properly aligned.
+ * @note This function is just an alias for @p chGuardedPoolFreeI() and
+ * has been added for clarity.
*
* @param[in] gmp pointer to a @p guarded_memory_pool_t structure
- * @return The pointer to the allocated object.
- * @retval NULL if the pool is empty.
+ * @param[in] objp the pointer to the object to be added
*
- * @iclass
+ * @sclass
*/
-static inline void *chGuardedPoolAllocI(guarded_memory_pool_t *gmp) {
- void *p;
+static inline void chGuardedPoolAddS(guarded_memory_pool_t *gmp, void *objp) {
- p = chPoolAllocI(&gmp->pool);
- if (p != NULL) {
- chSemFastWaitI(&gmp->sem);
- chDbgAssert(chSemGetCounterI(&gmp->sem) >= (cnt_t)0,
- "semaphore out of sync");
- }
- return p;
+ chGuardedPoolFreeS(gmp, objp);
}
#endif /* CH_CFG_USE_SEMAPHORES == TRUE */