From d442927667bb8d58dab3fb45b9fc7aaa0ac0b632 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Fri, 16 Aug 2019 20:54:38 -0700 Subject: [PATCH] kernel/sched: Add missing SMP thread abort case The loop in thread abort on SMP where we wait for the results on an IPI correctly handled the case where a thread running on another CPU gets its interrupt and self-aborts, but it missed the case where the other thread pends before receiving the interrupt. Signed-off-by: Andy Ross --- kernel/sched.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/sched.c b/kernel/sched.c index b85e0c641c4..4d5990fd5b3 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -1073,10 +1073,15 @@ void z_sched_abort(struct k_thread *thread) */ while ((thread->base.thread_state & _THREAD_DEAD) == 0U) { LOCKED(&sched_spinlock) { - if (z_is_thread_queued(thread)) { + if (z_is_thread_prevented_from_running(thread)) { + __ASSERT(!z_is_thread_queued(thread), ""); thread->base.thread_state |= _THREAD_DEAD; + } else if (z_is_thread_queued(thread)) { _priq_run_remove(&_kernel.ready_q.runq, thread); z_mark_thread_as_not_queued(thread); + thread->base.thread_state |= _THREAD_DEAD; + } else { + k_busy_wait(100); } } }