hujun260 commented on code in PR #16673: URL: https://github.com/apache/nuttx/pull/16673#discussion_r2199638359
########## sched/sched/sched_addreadytorun.c: ########## @@ -114,14 +114,95 @@ bool nxsched_add_readytorun(FAR struct tcb_s *btcb) return ret; } -#endif /* !CONFIG_SMP */ + +#else /* !CONFIG_SMP */ /**************************************************************************** - * Name: nxsched_add_readytorun + * Name: nxsched_switch_running * * Description: - * This function adds a TCB to one of the ready to run lists. That might - * be: + * This function switches the head of the current CPU's assigned tasks + * list to the TCB given as parameter. The idle task is not switched out. + * If the running task can't be swapped out, the btcb is pushed to + * the ready-to-run list. + * + * Input Parameters: + * btcb - Points to the TCB that is ready-to-run + * cpu - Always this_cpu(). Given as argument only for optimization + * + * Returned Value: + * true if the currently active task is switched to the btcb + * + * Assumptions: + * - The caller has established a critical section + * - The caller has already removed the input rtcb from whatever list it + * was in. + * - The caller handles the condition that occurs if the head of the + * assigned tasks list has changed. + * + ****************************************************************************/ + +bool nxsched_switch_running(FAR struct tcb_s *btcb, int cpu) +{ + FAR struct tcb_s *rtcb = current_task(cpu); + bool ret = true; + + DEBUGASSERT(cpu == this_cpu()); + DEBUGASSERT(btcb->task_state != TSTATE_TASK_RUNNING); + + /* If the currently running task is locked, or is on higher priority than + * the requested one. Just add the btcb into ready-to-run list (not + * running) and return false + */ + + if (nxsched_islocked_tcb(rtcb) || + btcb->sched_priority <= rtcb->sched_priority || + ((1 << cpu) & btcb->affinity) == 0) + { + nxsched_add_prioritized(btcb, list_readytorun()); + btcb->task_state = TSTATE_TASK_READYTORUN; + ret = false; + } + else + { + FAR dq_queue_t *tasklist = list_assignedtasks(cpu); + + /* Only the idle task and one other are kept in g_assignedtasks. + * return the other tasks to unassigned list, so that they can be + * picked up by other CPUs + */ + + if (!is_idle_task(rtcb)) Review Comment: is_idle_task(rtcb)总是为true,如果从nxsched_remove_self 中调用 ########## sched/sched/sched_addreadytorun.c: ########## @@ -114,14 +114,95 @@ bool nxsched_add_readytorun(FAR struct tcb_s *btcb) return ret; } -#endif /* !CONFIG_SMP */ + +#else /* !CONFIG_SMP */ /**************************************************************************** - * Name: nxsched_add_readytorun + * Name: nxsched_switch_running * * Description: - * This function adds a TCB to one of the ready to run lists. That might - * be: + * This function switches the head of the current CPU's assigned tasks + * list to the TCB given as parameter. The idle task is not switched out. + * If the running task can't be swapped out, the btcb is pushed to + * the ready-to-run list. + * + * Input Parameters: + * btcb - Points to the TCB that is ready-to-run + * cpu - Always this_cpu(). Given as argument only for optimization + * + * Returned Value: + * true if the currently active task is switched to the btcb + * + * Assumptions: + * - The caller has established a critical section + * - The caller has already removed the input rtcb from whatever list it + * was in. + * - The caller handles the condition that occurs if the head of the + * assigned tasks list has changed. + * + ****************************************************************************/ + +bool nxsched_switch_running(FAR struct tcb_s *btcb, int cpu) +{ + FAR struct tcb_s *rtcb = current_task(cpu); + bool ret = true; + + DEBUGASSERT(cpu == this_cpu()); + DEBUGASSERT(btcb->task_state != TSTATE_TASK_RUNNING); + + /* If the currently running task is locked, or is on higher priority than + * the requested one. Just add the btcb into ready-to-run list (not + * running) and return false + */ + + if (nxsched_islocked_tcb(rtcb) || + btcb->sched_priority <= rtcb->sched_priority || + ((1 << cpu) & btcb->affinity) == 0) + { + nxsched_add_prioritized(btcb, list_readytorun()); + btcb->task_state = TSTATE_TASK_READYTORUN; + ret = false; + } + else + { + FAR dq_queue_t *tasklist = list_assignedtasks(cpu); + + /* Only the idle task and one other are kept in g_assignedtasks. + * return the other tasks to unassigned list, so that they can be + * picked up by other CPUs + */ + + if (!is_idle_task(rtcb)) Review Comment: is_idle_task(rtcb)总是为true,如果从nxsched_remove_self 中调用 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org