From 27919549f1cf7ab2569838fa98e7e83e0a60367f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 6 Sep 2016 08:40:55 -0600 Subject: [PATCH] sched/: Simplify some child/parent logic --- sched/task/task_setup.c | 97 +++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 53 deletions(-) diff --git a/sched/task/task_setup.c b/sched/task/task_setup.c index e775fe6103..ec2883a06f 100644 --- a/sched/task/task_setup.c +++ b/sched/task/task_setup.c @@ -182,7 +182,7 @@ static inline void task_inherit_affinity(FAR struct tcb_s *tcb) * Name: task_saveparent * * Description: - * Save the task ID of the parent task in the child task's TCB and allocate + * Save the task ID of the parent task in the child task's group and allocate * a child status structure to catch the child task's exit status. * * Parameters: @@ -208,83 +208,74 @@ static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype) #else #endif -#ifdef HAVE_GROUP_MEMBERS - /* Save the ID of the parent tasks' task group in the child's task group. - * Do nothing for pthreads. The parent and the child are both members of - * the same task group. + /* Only newly created tasks (and kernel threads) have parents. None of + * this logic applies to pthreads with reside in the same group as the + * parent and share that same child/parent relationships. */ #ifndef CONFIG_DISABLE_PTHREAD if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD) #endif { - /* This is a new task in a new task group, we have to copy the ID from - * the parent's task group structure to child's task group. +#ifdef HAVE_GROUP_MEMBERS + /* Save the ID of the parent tasks' task group in the child's task + * group. Copy the ID from the parent's task group structure to + * child's task group. */ tcb->group->tg_pgid = rtcb->group->tg_gid; - } #else - DEBUGASSERT(tcb); + DEBUGASSERT(tcb); -#ifndef CONFIG_DISABLE_PTHREAD - if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD) -#endif - { /* Save the parent task's ID in the child task's group. */ tcb->group->tg_ppid = rtcb->pid; - } #endif #ifdef CONFIG_SCHED_CHILD_STATUS - /* Tasks can also suppress retention of their child status by applying - * the SA_NOCLDWAIT flag with sigaction(). - */ - - if ((rtcb->group->tg_flags && GROUP_FLAG_NOCLDWAIT) == 0) - { - FAR struct child_status_s *child; - - /* Make sure that there is not already a structure for this PID in the - * parent TCB. There should not be. + /* Tasks can also suppress retention of their child status by applying + * the SA_NOCLDWAIT flag with sigaction(). */ - child = group_findchild(rtcb->group, tcb->pid); - DEBUGASSERT(!child); - if (!child) + if ((rtcb->group->tg_flags && GROUP_FLAG_NOCLDWAIT) == 0) { - /* Allocate a new status structure */ + FAR struct child_status_s *child; - child = group_allocchild(); + /* Make sure that there is not already a structure for this PID in + * the parent TCB. There should not be. + */ + + child = group_findchild(rtcb->group, tcb->pid); + DEBUGASSERT(!child); + if (!child) + { + /* Allocate a new status structure */ + + child = group_allocchild(); + } + + /* Did we successfully find/allocate the child status structure? */ + + DEBUGASSERT(child); + if (child) + { + /* Yes.. Initialize the structure */ + + child->ch_flags = ttype; + child->ch_pid = tcb->pid; + child->ch_status = 0; + + /* Add the entry into the group's list of children */ + + group_addchild(rtcb->group, child); + } } - - /* Did we successfully find/allocate the child status structure? */ - - DEBUGASSERT(child); - if (child) - { - /* Yes.. Initialize the structure */ - - child->ch_flags = ttype; - child->ch_pid = tcb->pid; - child->ch_status = 0; - - /* Add the entry into the TCB list of children */ - - group_addchild(rtcb->group, child); - } - } #else - /* Child status is not retained. Simply keep track of the number - * child tasks (not pthreads) created. - */ + /* Child status is not retained. Simply keep track of the number + * child tasks created. + */ -#ifndef CONFIG_DISABLE_PTHREAD - if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD) -#endif - { DEBUGASSERT(rtcb->group != NULL && rtcb->group->tg_nchildren < UINT16_MAX);