kernel: poll: Lock all calls to signal_poll_event

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 <ambroise.vincent@arm.com>
This commit is contained in:
Ambroise Vincent 2023-09-11 15:54:51 +01:00 committed by Anas Nashif
commit 995eeda266

View file

@ -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
*/
@ -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)