This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 5c6763d54b3 sched/task: stop linking new tasks into the inactive list
5c6763d54b3 is described below

commit 5c6763d54b38665f7e1bcef5c077bc5387e51c7b
Author: jingfei <[email protected]>
AuthorDate: Wed Oct 14 23:15:38 2026 +0800

    sched/task: stop linking new tasks into the inactive list
    
    Tasks between setup and activation are added to g_inactivetasks and
    removed again on activation or teardown, but nothing walks that list:
    tasks are found through g_pidhash. The extra critical section and list
    operations add code to every task creation path.
    
    Keep TSTATE_TASK_INACTIVE and its now always empty list so the generic
    blocked-list helpers keep working. A TCB entering that state has NULL
    links (zero-allocated, or just unlinked by dq_rem()), so removing it
    from the empty list is a no-op.
    
    Update the tasking documentation to match.
    
    stm32f103-minimum:nsh: flash -72 bytes.
    Signed-off-by: jingfei <[email protected]>
---
 Documentation/os/scheduling/nuttx_tasking.rst | 11 ++++-------
 sched/init/nx_start.c                         |  6 ++++--
 sched/task/task_fork.c                        |  4 ----
 sched/task/task_init.c                        |  6 ------
 sched/task/task_restart.c                     |  3 ---
 sched/task/task_setup.c                       |  6 ------
 6 files changed, 8 insertions(+), 28 deletions(-)

diff --git a/Documentation/os/scheduling/nuttx_tasking.rst 
b/Documentation/os/scheduling/nuttx_tasking.rst
index daecbd99952..a0fe517af11 100644
--- a/Documentation/os/scheduling/nuttx_tasking.rst
+++ b/Documentation/os/scheduling/nuttx_tasking.rst
@@ -62,14 +62,11 @@ so that common list handling logic can be used (only the 
``g_readytorun``
 and ``g_pendingtasks`` lists, and the wait lists in each semaphore, event and
 message queue, need to be prioritized).
 
-All new tasks start in an initial, non-running state:
+All new tasks start in an initial, non-running state
+(``TSTATE_TASK_INACTIVE``):
 
-.. code-block:: c
-
-  volatile dq_queue_t g_inactivetasks;
-
-* This is the list of all tasks that have been initialized, but not yet
-  activated. NOTE: This is the only list that is not prioritized.
+* Tasks that have been initialized, but not yet activated, are not kept
+  in any task list. They are only reachable through the PID hash table.
 
 * When the task is initialized, it is moved to a ready-to-run list.
   There are two lists representing ready-to-run threads and several
diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c
index 777e0174950..ba030fc142b 100644
--- a/sched/init/nx_start.c
+++ b/sched/init/nx_start.c
@@ -152,8 +152,10 @@ dq_queue_t g_waitingforfill;
 dq_queue_t g_stoppedtasks;
 #endif
 
-/* This list of all tasks that have been initialized, but not yet
- * activated. NOTE:  This is the only list that is not prioritized.
+/* Task list for TSTATE_TASK_INACTIVE.  Initialized but not yet activated
+ * tasks are never linked into it, so it stays empty and removing such a
+ * TCB (whose links are NULL) through the generic task list helpers is a
+ * no-op.
  */
 
 dq_queue_t g_inactivetasks;
diff --git a/sched/task/task_fork.c b/sched/task/task_fork.c
index 96bc689af17..0c36ca9ba95 100644
--- a/sched/task/task_fork.c
+++ b/sched/task/task_fork.c
@@ -658,10 +658,6 @@ void nxtask_abort_fork(FAR struct tcb_s *child, int 
errcode)
     }
 #endif
 
-  /* The TCB was added to the active task list by nxtask_setup_scheduler() */
-
-  dq_rem((FAR dq_entry_t *)child, list_inactivetasks());
-
   /* Release the TCB */
 
   nxsched_release_tcb(child, child->flags & TCB_FLAG_TTYPE_MASK);
diff --git a/sched/task/task_init.c b/sched/task/task_init.c
index 1b5730a0dc1..9d590079589 100644
--- a/sched/task/task_init.c
+++ b/sched/task/task_init.c
@@ -288,12 +288,6 @@ errout_with_group:
 
 void nxtask_uninit(FAR struct tcb_s *tcb)
 {
-  /* The TCB was added to the inactive task list by
-   * nxtask_setup_scheduler().
-   */
-
-  dq_rem((FAR dq_entry_t *)tcb, list_inactivetasks());
-
   /* Release all resources associated with the TCB... Including the TCB
    * itself.
    */
diff --git a/sched/task/task_restart.c b/sched/task/task_restart.c
index f468eb34d5c..dc10c5c695c 100644
--- a/sched/task/task_restart.c
+++ b/sched/task/task_restart.c
@@ -159,9 +159,6 @@ static void nxtask_reset_task(FAR struct tcb_s *tcb, bool 
remove)
 
   up_initial_state(tcb);
 
-  /* Add the task to the inactive task list */
-
-  dq_addfirst((FAR dq_entry_t *)tcb, list_inactivetasks());
   tcb->task_state = TSTATE_TASK_INACTIVE;
 }
 
diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c
index 82c2802c3e6..b9e9be6f3ac 100644
--- a/sched/task/task_setup.c
+++ b/sched/task/task_setup.c
@@ -398,7 +398,6 @@ static int nxthread_setup_scheduler(FAR struct tcb_s *tcb, 
int priority,
                                     start_t start, CODE void *entry,
                                     uint8_t ttype)
 {
-  irqstate_t flags;
   int ret;
 
   /* Assign a unique task ID to the task. */
@@ -476,12 +475,7 @@ static int nxthread_setup_scheduler(FAR struct tcb_s *tcb, 
int priority,
 
       up_initial_state(tcb);
 
-      /* Add the task to the inactive task list */
-
-      flags = enter_critical_section();
-      dq_addfirst((FAR dq_entry_t *)tcb, list_inactivetasks());
       tcb->task_state = TSTATE_TASK_INACTIVE;
-      leave_critical_section(flags);
     }
 
   return ret;

Reply via email to