aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2016-02-23 09:11:43 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2016-02-23 09:11:43 +0000
commit45e44e73288edeee8572f235419c9842c7e5dcc5 (patch)
tree5e8a3b7801fc09eb8dfaf2154330ed1858e3bb8c
parent7b08ab4ae5e671d6b3f2bee8dfb01bd70199c8bf (diff)
downloadChibiOS-45e44e73288edeee8572f235419c9842c7e5dcc5.tar.gz
ChibiOS-45e44e73288edeee8572f235419c9842c7e5dcc5.tar.bz2
ChibiOS-45e44e73288edeee8572f235419c9842c7e5dcc5.zip
Added chMtxUnlockAllS().
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8927 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/rt/include/chmtx.h1
-rw-r--r--os/rt/src/chmtx.c39
2 files changed, 40 insertions, 0 deletions
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
@@ -475,6 +475,45 @@ void chMtxUnlockS(mutex_t *mp) {
* @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 <b>MUCH MORE</b> 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
+ * mutexes are unlocked.
* @note This function is <b>MUCH MORE</b> 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