jlaitine commented on code in PR #16673: URL: https://github.com/apache/nuttx/pull/16673#discussion_r2185295638
########## sched/sched/sched_mergepending.c: ########## @@ -190,96 +190,90 @@ bool nxsched_merge_pending(void) { FAR struct tcb_s *rtcb; FAR struct tcb_s *ptcb; - FAR struct tcb_s *tcb; + FAR struct tcb_s *next; bool ret = false; int cpu; + int minprio; - /* Remove and process every TCB in the g_pendingtasks list. + ptcb = (FAR struct tcb_s *)dq_peek(list_pendingtasks()); + if (ptcb == NULL) + { + /* The pending task list is empty */ + + return false; + } + + /* Find the CPU that is executing the lowest priority task */ + + cpu = nxsched_select_cpu(ALL_CPUS); + rtcb = current_task(cpu); + minprio = rtcb->sched_priority; + + /* Loop while there is a higher priority task in the pending task list + * than in the lowest executing task. If the task on the selected cpu + * is locked, leave the task in the pending list. * - * Do nothing if (1) pre-emption is still disabled (by any CPU), or (2) if - * some CPU other than this one is in a critical section. + * Normally, this loop should execute no more than CONFIG_SMP_NCPUS + * times. That number could be larger, however, if the CPU affinity + * sets do not include all CPUs. In that case, the excess TCBs will + * end up in the g_readytorun list. */ - if (!nxsched_islocked_tcb(this_task())) Review Comment: An even simpler way to do this would probably be to just move the pending list to a temporary one, and then go through the temporary list and call "nxsched_add_readytorun()" for every item. nxsched_add_readytorun would then put items to correct lists. Checking the priorities, affinity, sched locks etc. is all something that is done in nxsched_add_readytorun anyhow. -- 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