From c63b42d4789e2c552f309c5c2021c3d2f6ece9f6 Mon Sep 17 00:00:00 2001 From: Peter Mitsis Date: Mon, 16 Dec 2024 17:46:59 -0800 Subject: [PATCH] kernel: Fix k_wakeup() exit paths z_reschedule() already has a check to determine if it is called from the context of an ISR--no need to duplicate it in k_wakeup(). Furthermore, if the target thread is not sleeping, there is no need to reschedule and we can do a fast return. Signed-off-by: Peter Mitsis --- kernel/sched.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/kernel/sched.c b/kernel/sched.c index d4de81b19d7..590eadcb501 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -1164,21 +1164,13 @@ void z_impl_k_wakeup(k_tid_t thread) k_spinlock_key_t key = k_spin_lock(&_sched_spinlock); - z_abort_thread_timeout(thread); - - if (!z_is_thread_sleeping(thread)) { - k_spin_unlock(&_sched_spinlock, key); - return; - } - - z_mark_thread_as_not_sleeping(thread); - - ready_thread(thread); - - if (arch_is_in_isr()) { - k_spin_unlock(&_sched_spinlock, key); - } else { + if (z_is_thread_sleeping(thread)) { + z_abort_thread_timeout(thread); + z_mark_thread_as_not_sleeping(thread); + ready_thread(thread); z_reschedule(&_sched_spinlock, key); + } else { + k_spin_unlock(&_sched_spinlock, key); } }