diff --git a/kernel/include/ksched.h b/kernel/include/ksched.h index 56fa7aac817..0ec1897a2f3 100644 --- a/kernel/include/ksched.h +++ b/kernel/include/ksched.h @@ -315,6 +315,18 @@ static ALWAYS_INLINE bool z_is_thread_timeout_expired(struct k_thread *thread) */ bool z_sched_wake(_wait_q_t *wait_q, int swap_retval, void *swap_data); +/** + * Wakes the specified thread. + * + * Given a specific thread, wake it up. This routine assumes that the given + * thread is not on the timeout queue. + * + * @param thread Given thread to wake up. + * @param is_timeout True if called from the timer ISR; false otherwise. + * + */ +void z_sched_wake_thread(struct k_thread *thread, bool is_timeout); + /** * Wake up all threads pending on the provided wait queue * diff --git a/kernel/sched.c b/kernel/sched.c index 4367b0b4dc1..e1a79525bca 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -799,6 +799,27 @@ ALWAYS_INLINE void z_unpend_thread_no_timeout(struct k_thread *thread) } } +void z_sched_wake_thread(struct k_thread *thread, bool is_timeout) +{ + LOCKED(&sched_spinlock) { + bool killed = ((thread->base.thread_state & _THREAD_DEAD) || + (thread->base.thread_state & _THREAD_ABORTING)); + + if (!killed) { + /* The thread is not being killed */ + if (thread->base.pended_on != NULL) { + unpend_thread_no_timeout(thread); + } + z_mark_thread_as_started(thread); + if (is_timeout) { + z_mark_thread_as_not_suspended(thread); + } + ready_thread(thread); + } + } + +} + #ifdef CONFIG_SYS_CLOCK_EXISTS /* Timeout handler for *_thread_timeout() APIs */ void z_thread_timeout(struct _timeout *timeout) @@ -806,19 +827,7 @@ void z_thread_timeout(struct _timeout *timeout) struct k_thread *thread = CONTAINER_OF(timeout, struct k_thread, base.timeout); - LOCKED(&sched_spinlock) { - bool killed = ((thread->base.thread_state & _THREAD_DEAD) || - (thread->base.thread_state & _THREAD_ABORTING)); - - if (!killed) { - if (thread->base.pended_on != NULL) { - unpend_thread_no_timeout(thread); - } - z_mark_thread_as_started(thread); - z_mark_thread_as_not_suspended(thread); - ready_thread(thread); - } - } + z_sched_wake_thread(thread, true); } #endif