From 45e44e73288edeee8572f235419c9842c7e5dcc5 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 23 Feb 2016 09:11:43 +0000 Subject: [PATCH] Added chMtxUnlockAllS(). git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8927 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chmtx.h | 1 + os/rt/src/chmtx.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/os/rt/include/chmtx.h b/os/rt/include/chmtx.h index f1cc65a2f..f4a0bc0bc 100644 --- a/os/rt/include/chmtx.h +++ b/os/rt/include/chmtx.h @@ -108,6 +108,7 @@ extern "C" { void chMtxUnlock(mutex_t *mp); void chMtxUnlockS(mutex_t *mp); void chMtxUnlockAll(void); + void chMtxUnlockAllS(void); #ifdef __cplusplus } #endif diff --git a/os/rt/src/chmtx.c b/os/rt/src/chmtx.c index e8f315ed3..926f67f12 100644 --- a/os/rt/src/chmtx.c +++ b/os/rt/src/chmtx.c @@ -471,6 +471,45 @@ void chMtxUnlockS(mutex_t *mp) { #endif } +/** + * @brief Unlocks all mutexes owned by the invoking thread. + * @post The stack of owned mutexes is emptied and all the found + * mutexes are unlocked. + * @post This function does not reschedule so a call to a rescheduling + * function must be performed before unlocking the kernel. + * @note This function is MUCH MORE efficient than releasing the + * mutexes one by one and not just because the call overhead, + * this function does not have any overhead related to the priority + * inheritance mechanism. + * + * @sclass + */ +void chMtxUnlockAllS(void) { + thread_t *ctp = currp; + + while (ctp->mtxlist != NULL) { + mutex_t *mp = ctp->mtxlist; + ctp->mtxlist = mp->next; + if (chMtxQueueNotEmptyS(mp)) { +#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE + mp->cnt = (cnt_t)1; +#endif + thread_t *tp = queue_fifo_remove(&mp->queue); + mp->owner = tp; + mp->next = tp->mtxlist; + tp->mtxlist = mp; + (void) chSchReadyI(tp); + } + else { +#if CH_CFG_USE_MUTEXES_RECURSIVE == TRUE + mp->cnt = (cnt_t)0; +#endif + mp->owner = NULL; + } + } + ctp->prio = ctp->realprio; +} + /** * @brief Unlocks all mutexes owned by the invoking thread. * @post The stack of owned mutexes is emptied and all the found