[kernel] fix bug in event_signal with AUTOUNSIGNAL flag
Would not mark the event as unsignalled before potentially
releasing any waiting threads, which would let them fall through
event_wait until the signalling thread was run again.
diff --git a/kernel/event.c b/kernel/event.c
index 188b5d3..09e485a 100644
--- a/kernel/event.c
+++ b/kernel/event.c
@@ -99,13 +99,19 @@
#endif
if (!e->signalled) {
- e->signalled = true;
if (e->flags & EVENT_FLAG_AUTOUNSIGNAL) {
- /* try to release one thread and unsignal again if successful */
- if (wait_queue_wake_one(&e->wait, reschedule, NO_ERROR) > 0)
- e->signalled = false;
+ /* try to release one thread and leave unsignalled if successful */
+ if (wait_queue_wake_one(&e->wait, reschedule, NO_ERROR) <= 0) {
+ /*
+ * if we didn't actually find a thread to wake up, go to
+ * signalled state and let the next call to event_wait
+ * unsignal the event.
+ */
+ e->signalled = true;
+ }
} else {
/* release all threads and remain signalled */
+ e->signalled = true;
wait_queue_wake_all(&e->wait, reschedule, NO_ERROR);
}
}