Skip to content

Commit 03cd198

Browse files
committed
kernel: sched: use _is_thread_ready() in should_preempt()
We are using _is_thread_prevented_from_running() to see if the _current thread can be preempted in should_preempt(). The idea being that even if the _current thread is a high priority coop thread, we can still preempt it when it's pending, suspended, etc. This does not take into account if the thread is sleeping. k_sleep() merely removes the thread from the ready_q and calls Swap(). The scheduler will swap away from the thread temporarily and then on the next cycle get stuck to the sleeping thread for however long the sleep timeout is, doing exactly nothing because other functions like _ready_thread() use _is_thread_ready() as a check before proceeding. We should use !_is_thread_ready() to take into account when threads are waiting on a timer, and let other threads run in the meantime. Signed-off-by: Michael Scott <[email protected]>
1 parent 7a18b08 commit 03cd198

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/sched.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static int should_preempt(struct k_thread *th, int preempt_ok)
122122
}
123123

124124
/* Or if we're pended/suspended/dummy (duh) */
125-
if (!_current || _is_thread_prevented_from_running(_current)) {
125+
if (!_current || !_is_thread_ready(_current)) {
126126
return 1;
127127
}
128128

0 commit comments

Comments
 (0)