jlaitine commented on code in PR #16673:
URL: https://github.com/apache/nuttx/pull/16673#discussion_r2284171211


##########
sched/sched/sched_addreadytorun.c:
##########
@@ -114,170 +114,157 @@ 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:
- *
- *   1. The g_readytorun list if the task is ready-to-run but not running
- *      and not assigned to a CPU.
- *   2. The g_assignedtask[cpu] list if the task is running or if has been
- *      assigned to a CPU.
- *
- *   If the currently active task has preemption disabled and the new TCB
- *   would cause this task to be preempted, the new task is added to the
- *   g_pendingtasks list instead.  The pending tasks will be made
- *   ready-to-run when preemption isunlocked.
+ *   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 blocked TCB that is ready-to-run
+ *   cpu          - Always this_cpu(). Given as argument only for
+ *                  optimization
+ *   switch_equal - When true, switch away a task of equal priority compared
+ *                  to the pending one
  *
  * Returned Value:
- *   true if the currently active task (the head of the ready-to-run list)
- *   has changed.
+ *   true if the currently active task is switched
  *
  * Assumptions:
- * - The caller has established a critical section before calling this
- *   function (calling sched_lock() first is NOT a good idea -- use
- *   enter_critical_section()).
+ * - 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
- *   ready-to-run list has changed.
+ *   assigned tasks list has changed.
  *
  ****************************************************************************/
 
-#ifdef CONFIG_SMP
-bool nxsched_add_readytorun(FAR struct tcb_s *btcb)
+bool nxsched_switch_running(int cpu, bool switch_equal)
 {
-  FAR struct tcb_s *rtcb;
-  FAR struct tcb_s *headtcb;
-  FAR dq_queue_t *tasklist;
-  bool doswitch;
-  int task_state;
-  int cpu;
-  int me;
-
-  cpu = nxsched_select_cpu(btcb->affinity);
-
-  /* Get the task currently running on the CPU (may be the IDLE task) */
+  FAR struct tcb_s *rtcb = current_task(cpu);
+  int sched_priority = rtcb->sched_priority;
+  FAR struct tcb_s *btcb;
+  bool ret = false;
 
-  rtcb = current_task(cpu);
+  DEBUGASSERT(cpu == this_cpu());
 
-  /* Determine the desired new task state.  First, if the new task priority
-   * is higher then the priority of the lowest priority, running task, then
-   * the new task will be running and a context switch switch will be
-   * required.
-   */
-
-  if (rtcb->sched_priority < btcb->sched_priority)
+  if (nxsched_islocked_tcb(rtcb) ||
+      (!is_idle_task(rtcb) && (rtcb->flags & TCB_FLAG_CPU_LOCKED) != 0))

Review Comment:
   Right, I will re-check this part, thanks for the comment!



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

Reply via email to