From 51faefac27d88d667b557d3300e7df0c7ee31ac8 Mon Sep 17 00:00:00 2001 From: Peter Mitsis Date: Mon, 6 Jan 2025 11:35:03 -0800 Subject: [PATCH] kernel: Streamline z_is_thread_ready() The check for an active timeout in z_is_thread_ready() was originally added to cover the case of a sleeping thread. However, since there is now a bit in the thread state that indicates if the thread is sleeping we can drop that superfluous check. Making this change necessitates moving k_wakeup()'s call to z_abort_thread_timeout() so that it is within the locked _sched_spinlock section to ensure that we do not end up with a stray thread timeout in the timeout list. Signed-off-by: Peter Mitsis --- kernel/include/kthread.h | 3 +-- kernel/sched.c | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/include/kthread.h b/kernel/include/kthread.h index 35049c7805bdef..a751d4cd505fae 100644 --- a/kernel/include/kthread.h +++ b/kernel/include/kthread.h @@ -108,8 +108,7 @@ static inline bool z_is_thread_timeout_active(struct k_thread *thread) static inline bool z_is_thread_ready(struct k_thread *thread) { - return !((z_is_thread_prevented_from_running(thread)) != 0U || - z_is_thread_timeout_active(thread)); + return !z_is_thread_prevented_from_running(thread); } static inline bool z_is_thread_state_set(struct k_thread *thread, uint32_t state) diff --git a/kernel/sched.c b/kernel/sched.c index 0c2be8ab74b870..add0dc51ddf106 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -1164,10 +1164,10 @@ void z_impl_k_wakeup(k_tid_t thread) { SYS_PORT_TRACING_OBJ_FUNC(k_thread, wakeup, thread); - z_abort_thread_timeout(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;