aboutsummaryrefslogtreecommitdiffstats
path: root/os/rt/src/chcond.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/rt/src/chcond.c')
-rw-r--r--os/rt/src/chcond.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/os/rt/src/chcond.c b/os/rt/src/chcond.c
index 355ad2b37..d4234d6b6 100644
--- a/os/rt/src/chcond.c
+++ b/os/rt/src/chcond.c
@@ -91,8 +91,9 @@ void chCondSignal(condition_variable_t *cp) {
chDbgCheck(cp != NULL);
chSysLock();
- if (queue_notempty(&cp->c_queue))
+ if (queue_notempty(&cp->c_queue)) {
chSchWakeupS(queue_fifo_remove(&cp->c_queue), MSG_OK);
+ }
chSysUnlock();
}
@@ -153,8 +154,9 @@ void chCondBroadcastI(condition_variable_t *cp) {
/* Empties the condition variable queue and inserts all the threads into the
ready list in FIFO order. The wakeup message is set to @p MSG_RESET in
order to make a chCondBroadcast() detectable from a chCondSignal().*/
- while (cp->c_queue.p_next != (void *)&cp->c_queue)
+ while (cp->c_queue.p_next != (void *)&cp->c_queue) {
chSchReadyI(queue_fifo_remove(&cp->c_queue))->p_u.rdymsg = MSG_RESET;
+ }
}
/**
@@ -209,13 +211,18 @@ msg_t chCondWaitS(condition_variable_t *cp) {
chDbgCheck(cp != NULL);
chDbgAssert(ctp->p_mtxlist != NULL, "not owning a mutex");
+ /* Getting "current" mutex and releasing it.*/
mp = chMtxGetNextMutexS();
chMtxUnlockS(mp);
+
+ /* Start waiting on the condition variable, on exit the mutex is taken
+ again.*/
ctp->p_u.wtobjp = cp;
queue_prio_insert(ctp, &cp->c_queue);
chSchGoSleepS(CH_STATE_WTCOND);
msg = ctp->p_u.rdymsg;
chMtxLockS(mp);
+
return msg;
}
@@ -254,6 +261,7 @@ msg_t chCondWaitTimeout(condition_variable_t *cp, systime_t time) {
chSysLock();
msg = chCondWaitTimeoutS(cp, time);
chSysUnlock();
+
return msg;
}
@@ -293,13 +301,19 @@ msg_t chCondWaitTimeoutS(condition_variable_t *cp, systime_t time) {
chDbgCheck((cp != NULL) && (time != TIME_IMMEDIATE));
chDbgAssert(currp->p_mtxlist != NULL, "not owning a mutex");
+ /* Getting "current" mutex and releasing it.*/
mp = chMtxGetNextMutexS();
chMtxUnlockS(mp);
+
+ /* Start waiting on the condition variable, on exit the mutex is taken
+ again.*/
currp->p_u.wtobjp = cp;
queue_prio_insert(currp, &cp->c_queue);
msg = chSchGoSleepTimeoutS(CH_STATE_WTCOND, time);
- if (msg != MSG_TIMEOUT)
+ if (msg != MSG_TIMEOUT) {
chMtxLockS(mp);
+ }
+
return msg;
}
#endif /* CH_CFG_USE_CONDVARS_TIMEOUT */