aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--os/lib/include/chmempools.h82
-rw-r--r--os/lib/include/chobjfifos.h65
-rw-r--r--os/lib/src/chmempools.c18
-rw-r--r--readme.txt5
4 files changed, 138 insertions, 32 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 */
diff --git a/os/lib/include/chobjfifos.h b/os/lib/include/chobjfifos.h
index dfb0692ef..a422bf81d 100644
--- a/os/lib/include/chobjfifos.h
+++ b/os/lib/include/chobjfifos.h
@@ -210,6 +210,20 @@ static inline void chFifoReturnObjectI(objects_fifo_t *ofp,
* @param[in] ofp pointer to a @p objects_fifo_t structure
* @param[in] objp pointer to the object to be released
*
+ * @sclass
+ */
+static inline void chFifoReturnObjectS(objects_fifo_t *ofp,
+ void *objp) {
+
+ chGuardedPoolFreeS(&ofp->free, objp);
+}
+
+/**
+ * @brief Releases a fetched object.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objp pointer to the object to be released
+ *
* @api
*/
static inline void chFifoReturnObject(objects_fifo_t *ofp,
@@ -270,6 +284,57 @@ static inline void chFifoSendObject(objects_fifo_t *ofp, void *objp) {
}
/**
+ * @brief Posts an high priority object.
+ * @note By design the object can be always immediately posted.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objp pointer to the object to be posted
+ *
+ * @iclass
+ */
+static inline void chFifoSendObjectAheadI(objects_fifo_t *ofp,
+ void *objp) {
+ msg_t msg;
+
+ msg = chMBPostAheadI(&ofp->mbx, (msg_t)objp);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+
+/**
+ * @brief Posts an high priority object.
+ * @note By design the object can be always immediately posted.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objp pointer to the object to be posted
+ *
+ * @sclass
+ */
+static inline void chFifoSendObjectAheadS(objects_fifo_t *ofp,
+ void *objp) {
+ msg_t msg;
+
+ msg = chMBPostAheadTimeoutS(&ofp->mbx, (msg_t)objp, TIME_IMMEDIATE);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+
+/**
+ * @brief Posts an high priority object.
+ * @note By design the object can be always immediately posted.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objp pointer to the object to be released
+ *
+ * @api
+ */
+static inline void chFifoSendObjectAhead(objects_fifo_t *ofp, void *objp) {
+
+ msg_t msg;
+
+ msg = chMBPostAheadTimeout(&ofp->mbx, (msg_t)objp, TIME_IMMEDIATE);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+
+/**
* @brief Fetches an object.
*
* @param[in] ofp pointer to a @p objects_fifo_t structure
diff --git a/os/lib/src/chmempools.c b/os/lib/src/chmempools.c
index 43078c951..2fcd0cb3b 100644
--- a/os/lib/src/chmempools.c
+++ b/os/lib/src/chmempools.c
@@ -315,24 +315,6 @@ void *chGuardedPoolAllocTimeout(guarded_memory_pool_t *gmp,
* @param[in] gmp pointer to a @p guarded_memory_pool_t structure
* @param[in] objp the pointer to the object to be released
*
- * @iclass
- */
-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
- *
* @api
*/
void chGuardedPoolFree(guarded_memory_pool_t *gmp, void *objp) {
diff --git a/readme.txt b/readme.txt
index f115bf238..e6f9a4f85 100644
--- a/readme.txt
+++ b/readme.txt
@@ -91,6 +91,11 @@
*****************************************************************************
*** Next ***
+- NEW: Added new functions to objects fifos: chFifoReturnObjectS(),
+ chFifoSendObjectAheadI(), chFifoSendObjectAheadS() and
+ chFifoSendObjectAhead().
+- NEW: Added new functions to guarded pools: chGuardedPoolFreeS() and
+ chGuardedPoolAddS().
- NEW: Added initializer sections for flash0...flash7 memory areas in
GCC Cortex-M linker scripts.
- NEW: Added support for oversampling in STM32 ADCv3 driver.