sched/: Move fields related to parent/child task relationship out of TCB into group structure.
This commit is contained in:
parent
858af4295c
commit
05aa586aa6
@ -447,7 +447,7 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile,
|
||||
group->tg_pgid);
|
||||
#else
|
||||
linesize = snprintf(procfile->line, STATUS_LINELEN, "%-12s%d\n", "PPID:",
|
||||
tcb->ppid);
|
||||
group->tg_ppid);
|
||||
#endif
|
||||
|
||||
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, &offset);
|
||||
|
@ -422,12 +422,21 @@ struct task_group_s
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
|
||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
||||
/* Child exit status **********************************************************/
|
||||
|
||||
#ifdef CONFIG_SCHED_CHILD_STATUS
|
||||
FAR struct child_status_s *tg_children; /* Head of a list of child status */
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GROUP_MEMBERS
|
||||
pid_t tg_ppid; /* This is the ID of the parent thread */
|
||||
#ifndef CONFIG_SCHED_CHILD_STATUS
|
||||
uint16_t tg_nchildren; /* This is the number active children */
|
||||
#endif
|
||||
#endif /* HAVE_GROUP_MEMBERS */
|
||||
#endif /* CONFIG_SCHED_HAVE_PARENT */
|
||||
|
||||
#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT)
|
||||
/* waitpid support ************************************************************/
|
||||
/* Simple mechanism used only when there is no support for SIGCHLD */
|
||||
@ -537,16 +546,6 @@ struct tcb_s
|
||||
/* Task Management Fields *****************************************************/
|
||||
|
||||
pid_t pid; /* This is the ID of the thread */
|
||||
|
||||
#ifdef CONFIG_SCHED_HAVE_PARENT /* Support parent-child relationship */
|
||||
#ifndef HAVE_GROUP_MEMBERS /* Don't know pids of group members */
|
||||
pid_t ppid; /* This is the ID of the parent thread */
|
||||
#ifndef CONFIG_SCHED_CHILD_STATUS /* Retain child thread status */
|
||||
uint16_t nchildren; /* This is the number active children */
|
||||
#endif
|
||||
#endif
|
||||
#endif /* CONFIG_SCHED_HAVE_PARENT */
|
||||
|
||||
start_t start; /* Thread start function */
|
||||
entry_t entry; /* Entry Point into the thread */
|
||||
uint8_t sched_priority; /* Current priority of the thread */
|
||||
|
@ -210,13 +210,16 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
|
||||
}
|
||||
else if (idtype == P_PID)
|
||||
{
|
||||
/* Get the TCB corresponding to this PID and make sure it is our child. */
|
||||
/* Get the TCB corresponding to this PID and make sure that the
|
||||
* thread it is our child.
|
||||
*/
|
||||
|
||||
ctcb = sched_gettcb((pid_t)id);
|
||||
|
||||
#ifdef HAVE_GROUP_MEMBERS
|
||||
if (!ctcb || ctcb->group->tg_pgid != rtcb->group->tg_gid)
|
||||
if (ctcb == NULL || ctcb->group->tg_pgid != rtcb->group->tg_gid)
|
||||
#else
|
||||
if (!ctcb || ctcb->ppid != rtcb->pid)
|
||||
if (ctcb == NULL || ctcb->group>tg_ppid != rtcb->pid)
|
||||
#endif
|
||||
{
|
||||
errcode = ECHILD;
|
||||
@ -241,7 +244,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
|
||||
#else
|
||||
/* Child status is not retained. */
|
||||
|
||||
if (rtcb->nchildren == 0)
|
||||
if (rtcb->group->tg_nchildren == 0)
|
||||
{
|
||||
/* There are no children */
|
||||
|
||||
@ -250,13 +253,16 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
|
||||
}
|
||||
else if (idtype == P_PID)
|
||||
{
|
||||
/* Get the TCB corresponding to this PID and make sure it is our child. */
|
||||
/* Get the TCB corresponding to this PID and make sure that the
|
||||
* thread is our child.
|
||||
*/
|
||||
|
||||
ctcb = sched_gettcb((pid_t)id);
|
||||
|
||||
#ifdef HAVE_GROUP_MEMBERS
|
||||
if (!ctcb || ctcb->group->tg_pgid != rtcb->group->tg_gid)
|
||||
if (ctcb == NULL || ctcb->group->tg_pgid != rtcb->group->tg_gid)
|
||||
#else
|
||||
if (!ctcb || ctcb->ppid != rtcb->pid)
|
||||
if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid)
|
||||
#endif
|
||||
{
|
||||
errcode = ECHILD;
|
||||
@ -340,7 +346,7 @@ int waitid(idtype_t idtype, id_t id, FAR siginfo_t *info, int options)
|
||||
* instead).
|
||||
*/
|
||||
|
||||
if (rtcb->nchildren == 0 ||
|
||||
if (rtcb->group->tg_nchildren == 0 ||
|
||||
(idtype == P_PID && (ret = kill((pid_t)id, 0)) < 0))
|
||||
{
|
||||
/* We know that the child task was running okay we stared,
|
||||
|
@ -202,7 +202,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
|
||||
/* Get the TCB corresponding to this PID */
|
||||
|
||||
ctcb = sched_gettcb(pid);
|
||||
if (!ctcb)
|
||||
if (ctcb == NULL)
|
||||
{
|
||||
errcode = ECHILD;
|
||||
goto errout_with_errno;
|
||||
@ -342,13 +342,16 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
|
||||
}
|
||||
else if (pid != (pid_t)-1)
|
||||
{
|
||||
/* Get the TCB corresponding to this PID and make sure it is our child. */
|
||||
/* Get the TCB corresponding to this PID and make sure that the
|
||||
* thread it is our child.
|
||||
*/
|
||||
|
||||
ctcb = sched_gettcb(pid);
|
||||
|
||||
#ifdef HAVE_GROUP_MEMBERS
|
||||
if (!ctcb || ctcb->group->tg_pgid != rtcb->group->tg_gid)
|
||||
if (ctcb == NULL || ctcb->group->tg_pgid != rtcb->group->tg_gid)
|
||||
#else
|
||||
if (!ctcb || ctcb->ppid != rtcb->pid)
|
||||
if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid)
|
||||
#endif
|
||||
{
|
||||
errcode = ECHILD;
|
||||
@ -371,7 +374,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
|
||||
|
||||
#else /* CONFIG_SCHED_CHILD_STATUS */
|
||||
|
||||
if (rtcb->nchildren == 0)
|
||||
if (rtcb->group->tg_nchildren == 0)
|
||||
{
|
||||
/* There are no children */
|
||||
|
||||
@ -380,14 +383,16 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
|
||||
}
|
||||
else if (pid != (pid_t)-1)
|
||||
{
|
||||
/* Get the TCB corresponding to this PID and make sure it is our child. */
|
||||
/* Get the TCB corresponding to this PID and make sure that the
|
||||
* thread it is our child.
|
||||
*/
|
||||
|
||||
ctcb = sched_gettcb(pid);
|
||||
|
||||
#ifdef HAVE_GROUP_MEMBERS
|
||||
if (!ctcb || ctcb->group->tg_pgid != rtcb->group->tg_gid)
|
||||
if (ctcb == NULL || ctcb->group->tg_pgid != rtcb->group->tg_gid)
|
||||
#else
|
||||
if (!ctcb || ctcb->ppid != rtcb->pid)
|
||||
if (ctcb == NULL || ctcb->group->tg_ppid != rtcb->pid)
|
||||
#endif
|
||||
{
|
||||
errcode = ECHILD;
|
||||
@ -486,7 +491,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options)
|
||||
* instead).
|
||||
*/
|
||||
|
||||
if (rtcb->nchildren == 0 ||
|
||||
if (rtcb->group->tg_nchildren == 0 ||
|
||||
(pid != (pid_t)-1 && (ret = kill(pid, 0)) < 0))
|
||||
{
|
||||
/* We know that the child task was running okay we stared,
|
||||
|
@ -360,11 +360,12 @@ static inline void task_sigchild(FAR struct tcb_s *ptcb,
|
||||
task_exitstatus(ptcb->group, status);
|
||||
|
||||
#else /* CONFIG_SCHED_CHILD_STATUS */
|
||||
/* Exit status is not retained. Just decrement the number of
|
||||
* children from this parent.
|
||||
*/
|
||||
|
||||
/* Decrement the number of children from this parent */
|
||||
|
||||
DEBUGASSERT(ptcb->nchildren > 0);
|
||||
ptcb->nchildren--;
|
||||
DEBUGASSERT(ptcb->group != NULL && ptcb->group->tg_nchildren > 0);
|
||||
ptcb->group->tg_nchildren--;
|
||||
|
||||
#endif /* CONFIG_SCHED_CHILD_STATUS */
|
||||
|
||||
@ -429,13 +430,13 @@ static inline void task_signalparent(FAR struct tcb_s *ctcb, int status)
|
||||
sched_lock();
|
||||
|
||||
/* Get the TCB of the receiving, parent task. We do this early to
|
||||
* handle multiple calls to task_signalparent. ctcb->ppid is set to an
|
||||
* invalid value below and the following call will fail if we are
|
||||
* called again.
|
||||
* handle multiple calls to task_signalparent. ctcb->group->tg_ppid is
|
||||
* set to an invalid value below and the following call will fail if we
|
||||
* are called again.
|
||||
*/
|
||||
|
||||
ptcb = sched_gettcb(ctcb->ppid);
|
||||
if (!ptcb)
|
||||
ptcb = sched_gettcb(ctcb->group->tg_ppid);
|
||||
if (ptcb == NULL)
|
||||
{
|
||||
/* The parent no longer exists... bail */
|
||||
|
||||
@ -449,7 +450,7 @@ static inline void task_signalparent(FAR struct tcb_s *ctcb, int status)
|
||||
|
||||
/* Forget who our parent was */
|
||||
|
||||
ctcb->ppid = INVALID_PROCESS_ID;
|
||||
ctcb->group->tg_ppid = INVALID_PROCESS_ID;
|
||||
sched_unlock();
|
||||
#endif
|
||||
}
|
||||
|
@ -192,10 +192,10 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
||||
#else /* CONFIG_SCHED_CHILD_STATUS */
|
||||
/* Child task exit status is not retained */
|
||||
|
||||
DEBUGASSERT(otcb->nchildren > 0);
|
||||
DEBUGASSERT(ogrp->tg_nchildren > 0);
|
||||
|
||||
otcb->nchildren--; /* The orignal parent now has one few children */
|
||||
ptcb->nchildren++; /* The new parent has one additional child */
|
||||
ogrp->tg_nchildren--; /* The orignal parent now has one few children */
|
||||
pgrp->tg_nchildren++; /* The new parent has one additional child */
|
||||
ret = OK;
|
||||
|
||||
#endif /* CONFIG_SCHED_CHILD_STATUS */
|
||||
@ -234,7 +234,7 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
||||
|
||||
/* Get the PID of the child task's parent (opid) */
|
||||
|
||||
opid = chtcb->ppid;
|
||||
opid = chtcb->group->tg_ppid;
|
||||
|
||||
/* Get the TCB of the child task's parent (otcb) */
|
||||
|
||||
@ -245,14 +245,14 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
||||
goto errout_with_ints;
|
||||
}
|
||||
|
||||
/* If new parent task's PID (ppid) is zero, then new parent is the
|
||||
/* If new parent task's PID (tg_ppid) is zero, then new parent is the
|
||||
* grandparent will be the new parent, i.e., the parent of the current
|
||||
* parent task.
|
||||
*/
|
||||
|
||||
if (ppid == 0)
|
||||
{
|
||||
ppid = otcb->ppid;
|
||||
ppid = otcb->group->tg_ppid;
|
||||
}
|
||||
|
||||
/* Get the new parent task's TCB (ptcb) */
|
||||
@ -264,9 +264,9 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
||||
goto errout_with_ints;
|
||||
}
|
||||
|
||||
/* Then reparent the child */
|
||||
/* Then reparent the child. The task specified by ppid is the new parent. */
|
||||
|
||||
chtcb->ppid = ppid; /* The task specified by ppid is the new parent */
|
||||
chtcb->group->tg_ppid = ppid;
|
||||
|
||||
#ifdef CONFIG_SCHED_CHILD_STATUS
|
||||
/* Remove the child status entry from old parent TCB */
|
||||
@ -305,10 +305,10 @@ int task_reparent(pid_t ppid, pid_t chpid)
|
||||
#else /* CONFIG_SCHED_CHILD_STATUS */
|
||||
/* Child task exit status is not retained */
|
||||
|
||||
DEBUGASSERT(otcb->nchildren > 0);
|
||||
DEBUGASSERT(otcb->group != NULL && otcb->group->tg_nchildren > 0);
|
||||
|
||||
otcb->nchildren--; /* The orignal parent now has one few children */
|
||||
ptcb->nchildren++; /* The new parent has one additional child */
|
||||
otcb->group->tg_nchildren--; /* The orignal parent now has one few children */
|
||||
ptcb->group->tg_nchildren++; /* The new parent has one additional child */
|
||||
ret = OK;
|
||||
|
||||
#endif /* CONFIG_SCHED_CHILD_STATUS */
|
||||
|
@ -204,7 +204,7 @@ static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype)
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
|
||||
#if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_SCHED_CHILD_STATUS)
|
||||
DEBUGASSERT(tcb && tcb->group && rtcb->group);
|
||||
DEBUGASSERT(tcb != NULL && tcb->group != NULL && rtcb->group != NULL);
|
||||
#else
|
||||
#endif
|
||||
|
||||
@ -228,12 +228,14 @@ static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype)
|
||||
#else
|
||||
DEBUGASSERT(tcb);
|
||||
|
||||
/* Save the parent task's ID in the child task's TCB. I am not sure if
|
||||
* this makes sense for the case of pthreads or not, but I don't think it
|
||||
* is harmful in any event.
|
||||
*/
|
||||
#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->ppid = rtcb->pid;
|
||||
tcb->group->tg_ppid = rtcb->pid;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SCHED_CHILD_STATUS
|
||||
@ -283,8 +285,10 @@ static inline void task_saveparent(FAR struct tcb_s *tcb, uint8_t ttype)
|
||||
if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_PTHREAD)
|
||||
#endif
|
||||
{
|
||||
DEBUGASSERT(rtcb->nchildren < UINT16_MAX);
|
||||
rtcb->nchildren++;
|
||||
DEBUGASSERT(rtcb->group != NULL &&
|
||||
rtcb->group->tg_nchildren < UINT16_MAX);
|
||||
|
||||
rtcb->group->tg_nchildren++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user