Skip to content

Commit

Permalink
kernel: poll: Lock all calls to signal_poll_event
Browse files Browse the repository at this point in the history
The signal_poll_event function was previously called without the poll
lock held. This created a race condition between a thread calling k_poll
to wait for an event and another thread signalling for this same event.
This resulted in the waiting thread to stay pending and the handle to it
getting removed from the notifyq, meaning it couldn't get woken up
again.

Signed-off-by: Ambroise Vincent <[email protected]>
  • Loading branch information
ambroise-arm authored and coran21 committed Sep 21, 2023
1 parent ac09125 commit bd6f366
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kernel/poll.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2017 Wind River Systems, Inc.
* Copyright (c) 2023 Arm Limited (or its affiliates). All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -466,11 +467,14 @@ static int signal_poll_event(struct k_poll_event *event, uint32_t state)
void z_handle_obj_poll_events(sys_dlist_t *events, uint32_t state)
{
struct k_poll_event *poll_event;
k_spinlock_key_t key = k_spin_lock(&lock);

poll_event = (struct k_poll_event *)sys_dlist_get(events);
if (poll_event != NULL) {
(void) signal_poll_event(poll_event, state);
}

k_spin_unlock(&lock, key);
}

void z_impl_k_poll_signal_init(struct k_poll_signal *sig)
Expand Down

0 comments on commit bd6f366

Please sign in to comment.