xiaoxiang781216 commented on code in PR #10380:
URL: https://github.com/apache/nuttx/pull/10380#discussion_r1325742162
##########
binfmt/binfmt_execmodule.c:
##########
@@ -96,6 +97,91 @@ static void exec_ctors(FAR void *arg)
}
#endif
+/****************************************************************************
+ * Name: exec_swap
+ *
+ * Description:
+ * swap the pid of tasks, and reverse parent-child relationship.
+ *
+ * Input Parameters:
+ * ptcb - parent task tcb.
+ * chtcb - child task tcb.
+ *
+ * Returned Value:
+ * none
+ *
+ ****************************************************************************/
+
+static void exec_swap(FAR struct tcb_s *ptcb, FAR struct tcb_s *chtcb)
+{
+ int pndx;
+ int chndx;
+ pid_t pid;
+ irqstate_t flags;
+#ifdef HAVE_GROUP_MEMBERS
+ FAR pid_t *tg_members;
+#endif
+#ifdef CONFIG_SCHED_HAVE_PARENT
+#ifdef CONFIG_SCHED_CHILD_STATUS
+ FAR struct child_status_s *tg_children;
+#else
+ uint16_t tg_nchildren;
+#endif
+#endif
+
+ DEBUGASSERT(ptcb);
+ DEBUGASSERT(chtcb);
+
+ flags = enter_critical_section();
+
+ pndx = PIDHASH(ptcb->pid);
+ chndx = PIDHASH(chtcb->pid);
+
+ DEBUGASSERT(g_pidhash[pndx]);
+ DEBUGASSERT(g_pidhash[chndx]);
+
+ /* Exchange g_pidhash index */
+
+ g_pidhash[pndx] = chtcb;
+ g_pidhash[chndx] = ptcb;
+
+ /* Exchange pid */
+
+ pid = chtcb->pid;
+ chtcb->pid = ptcb->pid;
+ ptcb->pid = pid;
+
+ /* Exchange group info. This will reverse parent-child relationship */
+
+ pid = chtcb->group->tg_pid;
+ chtcb->group->tg_pid = ptcb->group->tg_pid;
+ ptcb->group->tg_pid = pid;
+
+ pid = chtcb->group->tg_ppid;
+ chtcb->group->tg_ppid = ptcb->group->tg_ppid;
+ ptcb->group->tg_ppid = pid;
+
+#ifdef HAVE_GROUP_MEMBERS
+ tg_members = chtcb->group->tg_members;
+ chtcb->group->tg_members = ptcb->group->tg_members;
+ ptcb->group->tg_members = tg_members;
+#endif
+
+#ifdef CONFIG_SCHED_HAVE_PARENT
+#ifdef CONFIG_SCHED_CHILD_STATUS
+ tg_children = chtcb->group->tg_children;
+ chtcb->group->tg_children = ptcb->group->tg_children;
+ ptcb->group->tg_children = tg_children;
+#else
Review Comment:
ditto
##########
binfmt/binfmt_execmodule.c:
##########
@@ -96,6 +97,91 @@ static void exec_ctors(FAR void *arg)
}
#endif
+/****************************************************************************
+ * Name: exec_swap
+ *
+ * Description:
+ * swap the pid of tasks, and reverse parent-child relationship.
+ *
+ * Input Parameters:
+ * ptcb - parent task tcb.
+ * chtcb - child task tcb.
+ *
+ * Returned Value:
+ * none
+ *
+ ****************************************************************************/
+
+static void exec_swap(FAR struct tcb_s *ptcb, FAR struct tcb_s *chtcb)
+{
+ int pndx;
+ int chndx;
+ pid_t pid;
+ irqstate_t flags;
+#ifdef HAVE_GROUP_MEMBERS
+ FAR pid_t *tg_members;
+#endif
+#ifdef CONFIG_SCHED_HAVE_PARENT
+#ifdef CONFIG_SCHED_CHILD_STATUS
+ FAR struct child_status_s *tg_children;
+#else
+ uint16_t tg_nchildren;
+#endif
+#endif
+
+ DEBUGASSERT(ptcb);
+ DEBUGASSERT(chtcb);
+
+ flags = enter_critical_section();
+
+ pndx = PIDHASH(ptcb->pid);
+ chndx = PIDHASH(chtcb->pid);
+
+ DEBUGASSERT(g_pidhash[pndx]);
+ DEBUGASSERT(g_pidhash[chndx]);
+
+ /* Exchange g_pidhash index */
+
+ g_pidhash[pndx] = chtcb;
+ g_pidhash[chndx] = ptcb;
+
+ /* Exchange pid */
+
+ pid = chtcb->pid;
+ chtcb->pid = ptcb->pid;
+ ptcb->pid = pid;
+
+ /* Exchange group info. This will reverse parent-child relationship */
+
+ pid = chtcb->group->tg_pid;
+ chtcb->group->tg_pid = ptcb->group->tg_pid;
+ ptcb->group->tg_pid = pid;
+
+ pid = chtcb->group->tg_ppid;
+ chtcb->group->tg_ppid = ptcb->group->tg_ppid;
+ ptcb->group->tg_ppid = pid;
+
+#ifdef HAVE_GROUP_MEMBERS
+ tg_members = chtcb->group->tg_members;
+ chtcb->group->tg_members = ptcb->group->tg_members;
+ ptcb->group->tg_members = tg_members;
+#endif
+
+#ifdef CONFIG_SCHED_HAVE_PARENT
+#ifdef CONFIG_SCHED_CHILD_STATUS
Review Comment:
indent
##########
binfmt/binfmt_execmodule.c:
##########
@@ -96,6 +97,91 @@ static void exec_ctors(FAR void *arg)
}
#endif
+/****************************************************************************
+ * Name: exec_swap
+ *
+ * Description:
+ * swap the pid of tasks, and reverse parent-child relationship.
+ *
+ * Input Parameters:
+ * ptcb - parent task tcb.
+ * chtcb - child task tcb.
+ *
+ * Returned Value:
+ * none
+ *
+ ****************************************************************************/
+
+static void exec_swap(FAR struct tcb_s *ptcb, FAR struct tcb_s *chtcb)
+{
+ int pndx;
+ int chndx;
+ pid_t pid;
+ irqstate_t flags;
+#ifdef HAVE_GROUP_MEMBERS
+ FAR pid_t *tg_members;
+#endif
+#ifdef CONFIG_SCHED_HAVE_PARENT
+#ifdef CONFIG_SCHED_CHILD_STATUS
+ FAR struct child_status_s *tg_children;
+#else
+ uint16_t tg_nchildren;
+#endif
+#endif
+
+ DEBUGASSERT(ptcb);
+ DEBUGASSERT(chtcb);
+
+ flags = enter_critical_section();
+
+ pndx = PIDHASH(ptcb->pid);
+ chndx = PIDHASH(chtcb->pid);
+
+ DEBUGASSERT(g_pidhash[pndx]);
+ DEBUGASSERT(g_pidhash[chndx]);
+
+ /* Exchange g_pidhash index */
+
+ g_pidhash[pndx] = chtcb;
+ g_pidhash[chndx] = ptcb;
+
+ /* Exchange pid */
+
+ pid = chtcb->pid;
+ chtcb->pid = ptcb->pid;
+ ptcb->pid = pid;
+
+ /* Exchange group info. This will reverse parent-child relationship */
+
+ pid = chtcb->group->tg_pid;
+ chtcb->group->tg_pid = ptcb->group->tg_pid;
+ ptcb->group->tg_pid = pid;
+
+ pid = chtcb->group->tg_ppid;
+ chtcb->group->tg_ppid = ptcb->group->tg_ppid;
+ ptcb->group->tg_ppid = pid;
+
+#ifdef HAVE_GROUP_MEMBERS
+ tg_members = chtcb->group->tg_members;
+ chtcb->group->tg_members = ptcb->group->tg_members;
+ ptcb->group->tg_members = tg_members;
+#endif
+
+#ifdef CONFIG_SCHED_HAVE_PARENT
+#ifdef CONFIG_SCHED_CHILD_STATUS
+ tg_children = chtcb->group->tg_children;
+ chtcb->group->tg_children = ptcb->group->tg_children;
+ ptcb->group->tg_children = tg_children;
+#else
+ tg_nchildren = chtcb->group->tg_nchildren;
+ chtcb->group->tg_nchildren = ptcb->group->tg_nchildren;
+ ptcb->group->tg_nchildren = tg_nchildren;
+#endif
Review Comment:
ditto
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]