Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential lost wakeup in cv_wait(_timed). #673

Merged
merged 3 commits into from
Oct 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sys/kern/condvar.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <sys/condvar.h>
#include <sys/sleepq.h>
#include <sys/sched.h>
#include <sys/interrupt.h>
#include <sys/lock.h>

void cv_init(condvar_t *cv, const char *name) {
Expand All @@ -9,17 +10,20 @@ void cv_init(condvar_t *cv, const char *name) {
}

void cv_wait(condvar_t *cv, lock_t m) {
WITH_NO_PREEMPTION {
WITH_INTR_DISABLED {
cv->waiters++;
lk_release(m);
/* If we got interrupted here and an interrupt filter called
* cv_signal, we would have a lost wakeup, so we need interrupts
* to be disabled. Same goes for cv_wait_timed. */
sleepq_wait(cv, __caller(0));
}
lk_acquire(m, __caller(0));
}

int cv_wait_timed(condvar_t *cv, lock_t m, systime_t timeout) {
int status;
WITH_NO_PREEMPTION {
WITH_INTR_DISABLED {
cv->waiters++;
lk_release(m);
status = sleepq_wait_timed(cv, __caller(0), timeout);
Expand Down