sched/sched: Introduce nxsched_wakeup()

Add a new function nxsched_wakeup() to the scheduler,
    which allows waking up a sleeping task before its timeout.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
This commit is contained in:
wangchengdong
2025-10-27 09:17:00 +08:00
committed by archer
parent 201406b22b
commit 5beb4ae6d5
2 changed files with 69 additions and 3 deletions

View File

@@ -264,7 +264,8 @@ enum tstate_e
TSTATE_TASK_STOPPED, /* BLOCKED - Waiting for SIGCONT */
#endif
NUM_TASK_STATES /* Must be last */
NUM_TASK_STATES,
TSTATE_SLEEPING = TSTATE_WAIT_SIG /* Map TSTATE_SLEEPING to TSTATE_WAIT_SIG */
};
typedef enum tstate_e tstate_t;
@@ -1733,6 +1734,26 @@ int nxsched_smp_call_async(cpu_set_t cpuset,
void nxsched_ticksleep(unsigned int ticks);
/****************************************************************************
* Name: nxsched_wakeup
*
* Description:
* The nxsched_wakeup() function is used to wake up a task that is
* currently in the sleeping state before its timeout expires.
*
* This function can be used by internal scheduler logic or by
* system-level components that need to resume a sleeping task early.
*
* Input Parameters:
* tcb - Pointer to the TCB of the task to be awakened.
*
* Returned Value:
* None
*
****************************************************************************/
void nxsched_wakeup(FAR struct tcb_s *tcb);
/****************************************************************************
* Name: nxsched_usleep
*

View File

@@ -130,7 +130,7 @@ void nxsched_ticksleep(unsigned int ticks)
/* Add the task to the specified blocked task list */
rtcb->task_state = TSTATE_WAIT_SIG;
rtcb->task_state = TSTATE_SLEEPING;
dq_addlast((FAR dq_entry_t *)rtcb, list_waitingforsignal());
/* Now, perform the context switch if one is needed */
@@ -143,9 +143,54 @@ void nxsched_ticksleep(unsigned int ticks)
}
/****************************************************************************
* Public Functions
* Name: nxsched_wakeup
*
* Description:
* The nxsched_wakeup() function is used to wake up a task that is
* currently in the sleeping state before its timeout expires.
*
* This function can be used by internal scheduler logic or by
* system-level components that need to resume a sleeping task early.
*
* Input Parameters:
* tcb - Pointer to the TCB of the task to be awakened.
*
* Returned Value:
* None
*
****************************************************************************/
void nxsched_wakeup(FAR struct tcb_s *tcb)
{
irqstate_t flags;
DEBUGASSERT(tcb != NULL);
flags = enter_critical_section();
if (tcb->task_state == TSTATE_SLEEPING)
{
FAR struct tcb_s *rtcb = this_task();
/* Remove the task from sleeping list */
dq_rem((FAR dq_entry_t *)tcb, list_waitingforsignal());
wd_cancel(&tcb->waitdog);
/* Add the task to ready-to-run task list, and
* perform the context switch if one is needed
*/
if (nxsched_add_readytorun(tcb))
{
up_switch_context(this_task(), rtcb);
}
}
leave_critical_section(flags);
}
/****************************************************************************
* Name: nxsched_usleep
*