kernel: Add z_sched_wake_thread API

This API wakes up a given thread and is also called from
z_thread_timeout()

Signed-off-by: Aastha Grover <aastha.grover@intel.com>
This commit is contained in:
Aastha Grover 2023-03-08 16:54:12 -05:00 committed by Carles Cufí
parent a2dccf1283
commit 5537776898
2 changed files with 34 additions and 13 deletions

View file

@ -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
*

View file

@ -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