From c94d7c870c456005b3e87d71acba8f7f9ea2b5ec Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 4 Feb 2013 16:02:20 +0000 Subject: Move waitpid() data structures to task group; The caller of waitpid() is now only awakened when the final thread of the task group exits git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5608 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/sched/sched_waitpid.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'nuttx/sched/sched_waitpid.c') diff --git a/nuttx/sched/sched_waitpid.c b/nuttx/sched/sched_waitpid.c index e44ef6e21..e79dded4c 100644 --- a/nuttx/sched/sched_waitpid.c +++ b/nuttx/sched/sched_waitpid.c @@ -182,7 +182,8 @@ #ifndef CONFIG_SCHED_HAVE_PARENT pid_t waitpid(pid_t pid, int *stat_loc, int options) { - _TCB *ctcb; + FAR _TCB *ctcb; + FAR struct task_group_s *group; bool mystat; int err; int ret; @@ -212,21 +213,26 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) goto errout_with_errno; } + /* The the task group corresponding to this PID */ + + group = ctcb->group; + DEBUGASSERT(group); + /* "If more than one thread is suspended in waitpid() awaiting termination of * the same process, exactly one thread will return the process status at the * time of the target process termination." Hmmm.. what do we return to the * others? */ - if (stat_loc != NULL && ctcb->stat_loc == NULL) + if (stat_loc != NULL && group->tg_statloc == NULL) { - ctcb->stat_loc = stat_loc; - mystat = true; + group->tg_statloc = stat_loc; + mystat = true; } /* Then wait for the task to exit */ - ret = sem_wait(&ctcb->exitsem); + ret = sem_wait(&group->tg_exitsem); if (ret < 0) { /* Unlock pre-emption and return the ERROR (sem_wait has already set @@ -236,7 +242,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) if (mystat) { - ctcb->stat_loc = NULL; + group->tg_statloc = NULL; } goto errout; -- cgit v1.2.3