From 5ea77118aaae09c29cea6e7fd543bf409d317fbc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 10 Aug 2016 07:37:25 -0600 Subject: [PATCH] Explicitly initialize the group tg_exitsem with sem_init(). The existing logic worked because the correct initialization value is all zero, but it is better to initialize the semaphore explicitly. Noted by Jouko Holopainen. --- sched/group/group_create.c | 8 +++++++- sched/signal/sig_nanosleep.c | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sched/group/group_create.c b/sched/group/group_create.c index 3b3cb6be08..2aecb9c12b 100644 --- a/sched/group/group_create.c +++ b/sched/group/group_create.c @@ -241,12 +241,18 @@ int group_allocate(FAR struct task_tcb_s *tcb, uint8_t ttype) return ret; } +#ifndef CONFIG_DISABLE_PTHREAD /* Initialize the pthread join semaphore */ -#ifndef CONFIG_DISABLE_PTHREAD (void)sem_init(&group->tg_joinsem, 0, 1); #endif +#if defined(CONFIG_SCHED_WAITPID) && !defined(CONFIG_SCHED_HAVE_PARENT) + /* Initialize the exit/wait semaphores */ + + (void)sem_init(&group->tg_exitsem, 0, 0); +#endif + return OK; } diff --git a/sched/signal/sig_nanosleep.c b/sched/signal/sig_nanosleep.c index 0ac8e7fadb..4a492f0c85 100644 --- a/sched/signal/sig_nanosleep.c +++ b/sched/signal/sig_nanosleep.c @@ -167,6 +167,11 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) systime_t remaining; int ticks; + /* REVISIT: The conversion from time to ticks and back could + * be avoided. clock_timespec_subtract() would be used instead + * to get the time difference. + */ + /* First get the number of clock ticks that we were requested to * wait. */