From 6c95dafd826014e2b07d490ecce9f48ebbc46ce4 Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Sat, 2 Jun 2018 14:42:33 -0700 Subject: [PATCH] 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 --- kernel/sched.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched.c b/kernel/sched.c index 56ee09e04da..3ee40babfb2 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -122,7 +122,7 @@ static int should_preempt(struct k_thread *th, int preempt_ok) } /* Or if we're pended/suspended/dummy (duh) */ - if (!_current || _is_thread_prevented_from_running(_current)) { + if (!_current || !_is_thread_ready(_current)) { return 1; }