Skip to content

Commit

Permalink
kernel: Update k_wakeup()
Browse files Browse the repository at this point in the history
This commit does two things to k_wakeup():

1. It locks the scheduler before marking the thread as not suspended.
As the the clearing of the _THREAD_SUSPENDED bit is not atomic, this
helps ensure that neither another thread nor ISR interrupts this
action (resulting in a corrupted thread_state).

2. The call to flag_ipi() has been removed as it is already being
made within ready_thread().

Signed-off-by: Peter Mitsis <[email protected]>
(cherry picked from commit 51ae993)
  • Loading branch information
peter-mitsis authored and henrikbrixandersen committed Mar 12, 2024
1 parent fe92cf6 commit cd21e04
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,13 +1653,18 @@ void z_impl_k_wakeup(k_tid_t thread)
}
}

k_spinlock_key_t key = k_spin_lock(&sched_spinlock);

z_mark_thread_as_not_suspended(thread);
z_ready_thread(thread);

flag_ipi();
if (!thread_active_elsewhere(thread)) {
ready_thread(thread);
}

if (!arch_is_in_isr()) {
z_reschedule_unlocked();
if (arch_is_in_isr()) {
k_spin_unlock(&sched_spinlock, key);
} else {
z_reschedule(&sched_spinlock, key);
}
}

Expand Down

0 comments on commit cd21e04

Please sign in to comment.