Skip to content

Commit

Permalink
kernel: Streamline z_is_thread_ready()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
peter-mitsis committed Jan 9, 2025
1 parent 6487761 commit 51faefa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions kernel/include/kthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 51faefa

Please sign in to comment.