From 4ed842e16352484d3d8e1e590f3d266f3fd4ca55 Mon Sep 17 00:00:00 2001 From: Yanfeng Liu Date: Tue, 25 Jun 2024 16:36:13 +0800 Subject: [PATCH] sched/tcb: fix 12320 regression This patch attempts to fix regressions reported for pull# 12320. Signed-off-by: Yanfeng Liu --- sched/init/nx_bringup.c | 6 ++++-- sched/sched/sched_releasetcb.c | 5 +++-- sched/task/exit.c | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sched/init/nx_bringup.c b/sched/init/nx_bringup.c index c1944a45be4d7..152dcc8ab236e 100644 --- a/sched/init/nx_bringup.c +++ b/sched/init/nx_bringup.c @@ -529,9 +529,11 @@ int nx_bringup(void) #if !defined(CONFIG_DISABLE_ENVIRON) && (defined(CONFIG_PATH_INITIAL) || \ defined(CONFIG_LDPATH_INITIAL)) - /* We an save a few bytes by discarding the IDLE thread's environment. */ + /* We would save a few bytes by discarding the IDLE thread's environment. + * But when kthreads share the same group, this is no longer proper, so + * we can't do clearenv() now. + */ - clearenv(); #endif sched_trace_end(); diff --git a/sched/sched/sched_releasetcb.c b/sched/sched/sched_releasetcb.c index 9c74bf11546c6..8a8d6a6851d09 100644 --- a/sched/sched/sched_releasetcb.c +++ b/sched/sched/sched_releasetcb.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -170,9 +171,9 @@ int nxsched_release_tcb(FAR struct tcb_s *tcb, uint8_t ttype) nxtask_joindestroy(tcb); - /* Kernel thread and group still reference by pthread */ + /* Task still referenced by pthread */ - if (ttype != TCB_FLAG_TTYPE_PTHREAD) + if (ttype == TCB_FLAG_TTYPE_TASK) { ttcb = (FAR struct task_tcb_s *)tcb; if (!sq_empty(&ttcb->group.tg_members) diff --git a/sched/task/exit.c b/sched/task/exit.c index 794bc6e2b4313..6773d6bebfd04 100644 --- a/sched/task/exit.c +++ b/sched/task/exit.c @@ -64,7 +64,11 @@ void _exit(int status) * exit through a different mechanism. */ - group_kill_children(tcb); + if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_TASK) + { + group_kill_children(tcb); + } + #endif /* Perform common task termination logic. This will get called again later