Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion include/nuttx/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down
86 changes: 48 additions & 38 deletions sched/sched/sched_sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,7 @@

static void nxsched_timeout(wdparm_t arg)
{
FAR struct tcb_s *wtcb;
irqstate_t flags;

/* Get waiting tcb from parameter */

wtcb = (FAR struct tcb_s *)(uintptr_t)arg;

/* We must be in a critical section in order to call up_switch_context()
* below.
*/

flags = enter_critical_section();

/* There may be a race condition -- make sure the task is
* still waiting for a signal
*/

if (wtcb->task_state == TSTATE_WAIT_SIG)
{
FAR struct tcb_s *rtcb = this_task();

/* Remove the task from waiting list */

dq_rem((FAR dq_entry_t *)wtcb, list_waitingforsignal());

/* Add the task to ready-to-run task list, and
* perform the context switch if one is needed
*/

if (nxsched_add_readytorun(wtcb))
{
up_switch_context(this_task(), rtcb);
}
}

leave_critical_section(flags);
nxsched_wakeup((FAR struct tcb_s *)(uintptr_t)arg);
}

/****************************************************************************
Expand Down Expand Up @@ -130,7 +95,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 */
Expand All @@ -143,9 +108,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
*
Expand Down
Loading