summaryrefslogtreecommitdiff
path: root/nuttx/sched
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/sched')
-rw-r--r--nuttx/sched/clock_abstime2ticks.c2
-rw-r--r--nuttx/sched/clock_initialize.c2
-rw-r--r--nuttx/sched/env_getenv.c4
-rw-r--r--nuttx/sched/env_getenvironptr.c4
-rw-r--r--nuttx/sched/env_setenv.c4
-rw-r--r--nuttx/sched/group_create.c33
-rw-r--r--nuttx/sched/group_internal.h12
-rw-r--r--nuttx/sched/group_join.c20
-rw-r--r--nuttx/sched/group_setupstreams.c3
-rw-r--r--nuttx/sched/group_setuptaskfiles.c3
-rw-r--r--nuttx/sched/os_start.c4
-rw-r--r--nuttx/sched/pthread_create.c4
-rw-r--r--nuttx/sched/sched_wait.c3
-rw-r--r--nuttx/sched/sched_waitid.c3
-rw-r--r--nuttx/sched/task_create.c4
-rw-r--r--nuttx/sched/task_exithook.c11
-rw-r--r--nuttx/sched/task_init.c4
17 files changed, 71 insertions, 49 deletions
diff --git a/nuttx/sched/clock_abstime2ticks.c b/nuttx/sched/clock_abstime2ticks.c
index 2d7f7f480..c55865635 100644
--- a/nuttx/sched/clock_abstime2ticks.c
+++ b/nuttx/sched/clock_abstime2ticks.c
@@ -120,7 +120,7 @@ int clock_abstime2ticks(clockid_t clockid, FAR const struct timespec *abstime,
reltime.tv_sec -= 1;
}
- /* Convert this relative time into microseconds.*/
+ /* Convert this relative time into microseconds. */
return clock_time2ticks(&reltime, ticks);
}
diff --git a/nuttx/sched/clock_initialize.c b/nuttx/sched/clock_initialize.c
index 2e146bb47..85a7294ab 100644
--- a/nuttx/sched/clock_initialize.c
+++ b/nuttx/sched/clock_initialize.c
@@ -179,7 +179,7 @@ static inline void clock_basetime(FAR struct timespec *tp)
static void clock_inittime(void)
{
- /* (Re-)initialize the time value to match the RTC*/
+ /* (Re-)initialize the time value to match the RTC */
clock_basetime(&g_basetime);
g_system_timer = 0;
diff --git a/nuttx/sched/env_getenv.c b/nuttx/sched/env_getenv.c
index 0414e23aa..0b847950a 100644
--- a/nuttx/sched/env_getenv.c
+++ b/nuttx/sched/env_getenv.c
@@ -91,7 +91,7 @@ FAR char *getenv(const char *name)
goto errout;
}
- /* Get a reference to the thread-private environ in the TCB.*/
+ /* Get a reference to the thread-private environ in the TCB. */
sched_lock();
rtcb = (FAR struct tcb_s*)g_readytorun.head;
@@ -131,5 +131,3 @@ errout:
#endif /* CONFIG_DISABLE_ENVIRON */
-
-
diff --git a/nuttx/sched/env_getenvironptr.c b/nuttx/sched/env_getenvironptr.c
index 91f3940b6..5808dc5dd 100644
--- a/nuttx/sched/env_getenvironptr.c
+++ b/nuttx/sched/env_getenvironptr.c
@@ -83,7 +83,7 @@ FAR char **get_environ_ptr( void )
#else
- /* Return a reference to the thread-private environ in the TCB.*/
+ /* Return a reference to the thread-private environ in the TCB. */
FAR struct tcb_s *ptcb = (FAR struct tcb_s*)g_readytorun.head;
if (ptcb->envp)
@@ -100,5 +100,3 @@ FAR char **get_environ_ptr( void )
#endif /* CONFIG_DISABLE_ENVIRON */
-
-
diff --git a/nuttx/sched/env_setenv.c b/nuttx/sched/env_setenv.c
index 772b01160..7ce3e1a1f 100644
--- a/nuttx/sched/env_setenv.c
+++ b/nuttx/sched/env_setenv.c
@@ -121,7 +121,7 @@ int setenv(FAR const char *name, FAR const char *value, int overwrite)
}
}
- /* Get a reference to the thread-private environ in the TCB.*/
+ /* Get a reference to the thread-private environ in the TCB. */
sched_lock();
rtcb = (FAR struct tcb_s*)g_readytorun.head;
@@ -203,5 +203,3 @@ errout:
#endif /* CONFIG_DISABLE_ENVIRON */
-
-
diff --git a/nuttx/sched/group_create.c b/nuttx/sched/group_create.c
index 414fe1824..ccf2e7519 100644
--- a/nuttx/sched/group_create.c
+++ b/nuttx/sched/group_create.c
@@ -174,12 +174,12 @@ void group_assigngid(FAR struct task_group_s *group)
*
*****************************************************************************/
-int group_allocate(FAR struct tcb_s *tcb)
+int group_allocate(FAR struct task_tcb_s *tcb)
{
FAR struct task_group_s *group;
int ret;
- DEBUGASSERT(tcb && !tcb->group);
+ DEBUGASSERT(tcb && !tcb->cmn.group);
/* Allocate the group structure and assign it to the TCB */
@@ -191,7 +191,7 @@ int group_allocate(FAR struct tcb_s *tcb)
/* Attach the group to the TCB */
- tcb->group = group;
+ tcb->cmn.group = group;
/* Assign the group a unique ID. If g_gidcounter were to wrap before we
* finish with task creation, that would be a problem.
@@ -207,7 +207,7 @@ int group_allocate(FAR struct tcb_s *tcb)
if (ret < 0)
{
kfree(group);
- tcb->group = NULL;
+ tcb->cmn.group = NULL;
return ret;
}
@@ -241,15 +241,15 @@ int group_allocate(FAR struct tcb_s *tcb)
*
*****************************************************************************/
-int group_initialize(FAR struct tcb_s *tcb)
+int group_initialize(FAR struct task_tcb_s *tcb)
{
FAR struct task_group_s *group;
#ifdef HAVE_GROUP_MEMBERS
irqstate_t flags;
#endif
- DEBUGASSERT(tcb && tcb->group);
- group = tcb->group;
+ DEBUGASSERT(tcb && tcb->cmn.group);
+ group = tcb->cmn.group;
#ifdef HAVE_GROUP_MEMBERS
/* Allocate space to hold GROUP_INITIAL_MEMBERS members of the group */
@@ -261,9 +261,9 @@ int group_initialize(FAR struct tcb_s *tcb)
return -ENOMEM;
}
- /* Assign the PID of this new task as a member of the group*/
+ /* Assign the PID of this new task as a member of the group. */
- group->tg_members[0] = tcb->pid;
+ group->tg_members[0] = tcb->cmn.pid;
/* Initialize the non-zero elements of group structure and assign it to
* the tcb.
@@ -280,8 +280,21 @@ int group_initialize(FAR struct tcb_s *tcb)
#endif
- group->tg_nmembers = 1; /* Number of members in the group */
+ /* Save the ID of the main task within the group of threads. This needed
+ * for things like SIGCHILD. It ID is also saved in the TCB of the main
+ * task but is also retained in the group which may persist after the main
+ * task has exited.
+ */
+
+#if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_SCHED_HAVE_PARENT)
+ group->tg_task = tcb->cmn.pid;
+#endif
+
+ /* Mark that there is one member in the group, the main task */
+
+ group->tg_nmembers = 1;
return OK;
}
#endif /* HAVE_TASK_GROUP */
+
diff --git a/nuttx/sched/group_internal.h b/nuttx/sched/group_internal.h
index e79f96e8c..f29cb53de 100644
--- a/nuttx/sched/group_internal.h
+++ b/nuttx/sched/group_internal.h
@@ -76,16 +76,18 @@ extern FAR struct task_group_s *g_grouphead;
/* Task group data structure management */
#ifdef HAVE_TASK_GROUP
-int group_allocate(FAR struct tcb_s *tcb);
-int group_initialize(FAR struct tcb_s *tcb);
-int group_bind(FAR struct tcb_s *tcb);
-int group_join(FAR struct tcb_s *tcb);
+int group_allocate(FAR struct task_tcb_s *tcb);
+int group_initialize(FAR struct task_tcb_s *tcb);
+#ifndef CONFIG_DISABLE_PTHREAD
+int group_bind(FAR struct pthread_tcb_s *tcb);
+int group_join(FAR struct pthread_tcb_s *tcb);
+#endif
void group_leave(FAR struct tcb_s *tcb);
#ifdef HAVE_GROUP_MEMBERS
FAR struct task_group_s *group_find(gid_t gid);
int group_addmember(FAR struct task_group_s *group, pid_t pid);
-int group_removemember(FAR struct task_group_s *group, pid_t pid);
+int group_removemember(FAR struct task_group_s *group, pid_t pid);
#endif
/* Convenience functions */
diff --git a/nuttx/sched/group_join.c b/nuttx/sched/group_join.c
index 564fbe7e9..f6babb871 100644
--- a/nuttx/sched/group_join.c
+++ b/nuttx/sched/group_join.c
@@ -49,7 +49,7 @@
#include "group_internal.h"
#include "env_internal.h"
-#ifdef HAVE_TASK_GROUP
+#if defined(HAVE_TASK_GROUP) && !defined(CONFIG_DISABLE_PTHREAD)
/*****************************************************************************
* Pre-processor Definitions
@@ -99,15 +99,15 @@
*
*****************************************************************************/
-int group_bind(FAR struct tcb_s *tcb)
+int group_bind(FAR struct pthread_tcb_s *tcb)
{
FAR struct tcb_s *ptcb = (FAR struct tcb_s *)g_readytorun.head;
- DEBUGASSERT(ptcb && tcb && ptcb->group && !tcb->group);
+ DEBUGASSERT(ptcb && tcb && ptcb->group && !tcb->cmn.group);
/* Copy the group reference from the parent to the child */
- tcb->group = ptcb->group;
+ tcb->cmn.group = ptcb->group;
return OK;
}
@@ -136,24 +136,24 @@ int group_bind(FAR struct tcb_s *tcb)
*
*****************************************************************************/
-int group_join(FAR struct tcb_s *tcb)
+int group_join(FAR struct pthread_tcb_s *tcb)
{
FAR struct task_group_s *group;
#ifdef HAVE_GROUP_MEMBERS
int ret;
#endif
- DEBUGASSERT(tcb && tcb->group &&
- tcb->group->tg_nmembers < UINT8_MAX);
+ DEBUGASSERT(tcb && tcb->cmn.group &&
+ tcb->cmn.group->tg_nmembers < UINT8_MAX);
/* Get the group from the TCB */
- group = tcb->group;
+ group = tcb->cmn.group;
#ifdef HAVE_GROUP_MEMBERS
/* Add the member to the group */
- ret = group_addmember(group, tcb->pid);
+ ret = group_addmember(group, tcb->cmn.pid);
if (ret < 0)
{
return ret;
@@ -224,4 +224,4 @@ int group_addmember(FAR struct task_group_s *group, pid_t pid)
}
#endif /* HAVE_GROUP_MEMBERS */
-#endif /* HAVE_TASK_GROUP */
+#endif /* HAVE_TASK_GROUP && !CONFIG_DISABLE_PTHREAD */
diff --git a/nuttx/sched/group_setupstreams.c b/nuttx/sched/group_setupstreams.c
index 217decd57..4a9fa5762 100644
--- a/nuttx/sched/group_setupstreams.c
+++ b/nuttx/sched/group_setupstreams.c
@@ -96,4 +96,5 @@ int group_setupstreams(FAR struct task_tcb_s *tcb)
}
#endif /* CONFIG_NFILE_STREAMS > 0 */
-#endif /* CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0*/
+#endif /* CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 */
+
diff --git a/nuttx/sched/group_setuptaskfiles.c b/nuttx/sched/group_setuptaskfiles.c
index 269485ea4..6809f9784 100644
--- a/nuttx/sched/group_setuptaskfiles.c
+++ b/nuttx/sched/group_setuptaskfiles.c
@@ -246,4 +246,5 @@ int group_setuptaskfiles(FAR struct task_tcb_s *tcb)
#endif
}
-#endif /* CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0*/
+#endif /* CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 */
+
diff --git a/nuttx/sched/os_start.c b/nuttx/sched/os_start.c
index ace475ba1..86b40bfbb 100644
--- a/nuttx/sched/os_start.c
+++ b/nuttx/sched/os_start.c
@@ -330,7 +330,7 @@ void os_start(void)
/* Allocate the IDLE group and suppress child status. */
#ifdef HAVE_TASK_GROUP
- (void)group_allocate(&g_idletcb.cmn);
+ (void)group_allocate(&g_idletcb);
#endif
/* Initialize the interrupt handling subsystem (if included) */
@@ -456,7 +456,7 @@ void os_start(void)
*/
#ifdef HAVE_TASK_GROUP
- (void)group_initialize(&g_idletcb.cmn);
+ (void)group_initialize(&g_idletcb);
g_idletcb.cmn.group->tg_flags = GROUP_FLAG_NOCLDWAIT;
#endif
diff --git a/nuttx/sched/pthread_create.c b/nuttx/sched/pthread_create.c
index 70b5ceb49..696e2c06c 100644
--- a/nuttx/sched/pthread_create.c
+++ b/nuttx/sched/pthread_create.c
@@ -255,7 +255,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
*/
#ifdef HAVE_TASK_GROUP
- ret = group_bind((FAR struct tcb_s *)ptcb);
+ ret = group_bind(ptcb);
if (ret < 0)
{
errcode = ENOMEM;
@@ -354,7 +354,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
/* Join the parent's task group */
#ifdef HAVE_TASK_GROUP
- ret = group_join((FAR struct tcb_s *)ptcb);
+ ret = group_join(ptcb);
if (ret < 0)
{
errcode = ENOMEM;
diff --git a/nuttx/sched/sched_wait.c b/nuttx/sched/sched_wait.c
index 813d4f842..9a6265e70 100644
--- a/nuttx/sched/sched_wait.c
+++ b/nuttx/sched/sched_wait.c
@@ -87,4 +87,5 @@ pid_t wait(FAR int *stat_loc)
return waitpid((pid_t)-1, stat_loc, 0);
}
-#endif /* CONFIG_SCHED_WAITPID && CONFIG_SCHED_HAVE_PARENT*/
+#endif /* CONFIG_SCHED_WAITPID && CONFIG_SCHED_HAVE_PARENT */
+
diff --git a/nuttx/sched/sched_waitid.c b/nuttx/sched/sched_waitid.c
index e75cf4987..545353e8b 100644
--- a/nuttx/sched/sched_waitid.c
+++ b/nuttx/sched/sched_waitid.c
@@ -405,4 +405,5 @@ errout:
return ERROR;
}
-#endif /* CONFIG_SCHED_WAITPID && CONFIG_SCHED_HAVE_PARENT*/
+#endif /* CONFIG_SCHED_WAITPID && CONFIG_SCHED_HAVE_PARENT */
+
diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c
index 30fc1354f..15bdebdb9 100644
--- a/nuttx/sched/task_create.c
+++ b/nuttx/sched/task_create.c
@@ -123,7 +123,7 @@ static int thread_create(const char *name, uint8_t ttype, int priority,
/* Allocate a new task group */
#ifdef HAVE_TASK_GROUP
- ret = group_allocate((FAR struct tcb_s *)tcb);
+ ret = group_allocate(tcb);
if (ret < 0)
{
errcode = -ret;
@@ -169,7 +169,7 @@ static int thread_create(const char *name, uint8_t ttype, int priority,
/* Now we have enough in place that we can join the group */
#ifdef HAVE_TASK_GROUP
- ret = group_initialize((FAR struct tcb_s *)tcb);
+ ret = group_initialize(tcb);
if (ret < 0)
{
errcode = -ret;
diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c
index 1c2137545..688c25c44 100644
--- a/nuttx/sched/task_exithook.c
+++ b/nuttx/sched/task_exithook.c
@@ -343,7 +343,11 @@ static inline void task_sigchild(gid_t pgid, FAR struct tcb_s *ctcb, int status)
info.si_signo = SIGCHLD;
info.si_code = CLD_EXITED;
info.si_value.sival_ptr = NULL;
+#ifndef CONFIG_DISABLE_PTHREAD
+ info.si_pid = chgrp->tg_task;
+#else
info.si_pid = ctcb->pid;
+#endif
info.si_status = status;
/* Send the signal. We need to use this internal interface so that we
@@ -356,7 +360,8 @@ static inline void task_sigchild(gid_t pgid, FAR struct tcb_s *ctcb, int status)
#else /* HAVE_GROUP_MEMBERS */
-static inline void task_sigchild(FAR struct tcb_s *ptcb, FAR struct tcb_s *ctcb, int status)
+static inline void task_sigchild(FAR struct tcb_s *ptcb,
+ FAR struct tcb_s *ctcb, int status)
{
siginfo_t info;
@@ -391,7 +396,11 @@ static inline void task_sigchild(FAR struct tcb_s *ptcb, FAR struct tcb_s *ctcb,
info.si_signo = SIGCHLD;
info.si_code = CLD_EXITED;
info.si_value.sival_ptr = NULL;
+#ifndef CONFIG_DISABLE_PTHREAD
+ info.si_pid = chgrp->tg_task;
+#else
info.si_pid = ctcb->pid;
+#endif
info.si_status = status;
/* Send the signal. We need to use this internal interface so that we
diff --git a/nuttx/sched/task_init.c b/nuttx/sched/task_init.c
index 802d0748d..79189f6cc 100644
--- a/nuttx/sched/task_init.c
+++ b/nuttx/sched/task_init.c
@@ -134,7 +134,7 @@ int task_init(FAR struct tcb_s *tcb, const char *name, int priority,
/* Create a new task group */
#ifdef HAVE_TASK_GROUP
- ret = group_allocate(tcb);
+ ret = group_allocate(ttcb);
if (ret < 0)
{
errcode = -ret;
@@ -176,7 +176,7 @@ int task_init(FAR struct tcb_s *tcb, const char *name, int priority,
/* Now we have enough in place that we can join the group */
#ifdef HAVE_TASK_GROUP
- ret = group_initialize(tcb);
+ ret = group_initialize(ttcb);
if (ret < 0)
{
errcode = -ret;