Skip to content

Commit

Permalink
Merge pull request #21092 from maribu/sys/event/fix-race
Browse files Browse the repository at this point in the history
sys/event: fix race in event_wait_multi()
  • Loading branch information
benpicco authored Dec 16, 2024
2 parents a40852d + c5ff57c commit 679ac92
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions sys/event/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ event_t *event_wait_multi(event_queue_t *queues, size_t n_queues)
assert(queues && n_queues);
event_t *result = NULL;

do {
while (1) {
unsigned state = irq_disable();
for (size_t i = 0; i < n_queues; i++) {
assert(queues[i].waiter);
Expand All @@ -100,14 +100,16 @@ event_t *event_wait_multi(event_queue_t *queues, size_t n_queues)
break;
}
}
irq_restore(state);
if (result == NULL) {
thread_flags_wait_any(THREAD_FLAG_EVENT);

if (result != NULL) {
result->list_node.next = NULL;
irq_restore(state);
return result;
}
} while (result == NULL);

result->list_node.next = NULL;
return result;
irq_restore(state);
thread_flags_wait_any(THREAD_FLAG_EVENT);
}
}

#if IS_USED(MODULE_XTIMER) || IS_USED(MODULE_ZTIMER)
Expand Down

0 comments on commit 679ac92

Please sign in to comment.