This is an automated email from the ASF dual-hosted git repository.
ligd 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 79c349b7790 sched/task: fix task_exit regression with critical section
state
79c349b7790 is described below
commit 79c349b77909e38ed55359a08bdf1e14d6dd3960
Author: hujun5 <[email protected]>
AuthorDate: Sun Jan 26 09:52:49 2025 +0800
sched/task: fix task_exit regression with critical section state
Move nxsched_switch_context() call after setting TSTATE_TASK_INACTIVE to
ensure
proper IRQ count state before context switching, preventing assertion
failures
in enter_critical_section() when rtcb->irqcount is incorrectly zero during
termination.
Signed-off-by: hujun5 <[email protected]>
---
sched/task/task_exit.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c
index f2df5d6c4be..ec8d9e319be 100644
--- a/sched/task/task_exit.c
+++ b/sched/task/task_exit.c
@@ -108,16 +108,6 @@ int nxtask_exit(void)
rtcb = this_task();
#endif
- /* Update scheduler parameters.
- *
- * When the thread exits, SYS_restore_context is called to
- * restore the context, which does not update the scheduling
- * information.
- * We need to update the scheduling information before tcb is released.
- */
-
- nxsched_switch_context(dtcb, rtcb);
-
/* We are now in a bad state -- the head of the ready to run task list
* does not correspond to the thread that is running. Disabling pre-
* emption on this TCB and marking the new ready-to-run task as not
@@ -143,6 +133,17 @@ int nxtask_exit(void)
#endif
dtcb->task_state = TSTATE_TASK_INACTIVE;
+
+ /* Update scheduler parameters.
+ *
+ * When the thread exits, SYS_restore_context is called to
+ * restore the context, which does not update the scheduling
+ * information.
+ * We need to update the scheduling information before tcb is released.
+ */
+
+ nxsched_switch_context(dtcb, rtcb);
+
sched_note_stop(dtcb);
ret = nxsched_release_tcb(dtcb, dtcb->flags & TCB_FLAG_TTYPE_MASK);