diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 42b2f02e489..f9b8635faff 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -499,7 +499,6 @@ struct task_group_s #ifndef CONFIG_DISABLE_PTHREAD /* Pthreads ***************************************************************/ - rmutex_t tg_joinlock; /* Synchronize access to tg_joinqueue */ sq_queue_t tg_joinqueue; /* List of join status of tcb */ #endif @@ -547,7 +546,8 @@ struct task_group_s struct mm_map_s tg_mm_map; /* Task group virtual memory mappings */ - spinlock_t tg_lock; /* lock */ + spinlock_t tg_lock; /* SpinLock for group */ + rmutex_t tg_mutex; /* Mutex for group */ }; /* struct tcb_s *************************************************************/ diff --git a/sched/group/group_create.c b/sched/group/group_create.c index a3c10de1d20..ceaf11bf7f6 100644 --- a/sched/group/group_create.c +++ b/sched/group/group_create.c @@ -178,10 +178,11 @@ int group_initialize(FAR struct task_tcb_s *tcb, uint8_t ttype) return ret; } + nxrmutex_init(&group->tg_mutex); + #ifndef CONFIG_DISABLE_PTHREAD /* Initialize the task group join */ - nxrmutex_init(&group->tg_joinlock); sq_init(&group->tg_joinqueue); #endif diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index e5e4c5a7060..a8e6dc0d057 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -74,6 +74,10 @@ static inline void group_release(FAR struct task_group_s *group, uint8_t ttype) { + /* Destroy the mutex */ + + nxrmutex_destroy(&group->tg_mutex); + task_uninit_info(group); #if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS) diff --git a/sched/pthread/pthread_completejoin.c b/sched/pthread/pthread_completejoin.c index 548e7360b51..99d9500195a 100644 --- a/sched/pthread/pthread_completejoin.c +++ b/sched/pthread/pthread_completejoin.c @@ -74,7 +74,7 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value) sinfo("pid=%d exit_value=%p\n", pid, exit_value); - nxrmutex_lock(&group->tg_joinlock); + nxrmutex_lock(&group->tg_mutex); if (!sq_empty(&tcb->join_queue)) { @@ -109,7 +109,7 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value) tcb->flags |= TCB_FLAG_JOIN_COMPLETED; - nxrmutex_unlock(&group->tg_joinlock); + nxrmutex_unlock(&group->tg_mutex); return ret; } @@ -126,7 +126,7 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value) * no thread ever calls pthread_join. In case, there is a memory leak! * * Assumptions: - * The caller holds tg_joinlock + * The caller holds tg_mutex * ****************************************************************************/ @@ -137,9 +137,9 @@ void pthread_destroyjoin(FAR struct task_group_s *group, /* Remove the join info from the set of joins */ - nxrmutex_lock(&group->tg_joinlock); + nxrmutex_lock(&group->tg_mutex); sq_rem(&pjoin->entry, &group->tg_joinqueue); - nxrmutex_unlock(&group->tg_joinlock); + nxrmutex_unlock(&group->tg_mutex); /* And deallocate the pjoin structure */ diff --git a/sched/pthread/pthread_detach.c b/sched/pthread/pthread_detach.c index 7b1c3b20795..9d8ac5ba14a 100644 --- a/sched/pthread/pthread_detach.c +++ b/sched/pthread/pthread_detach.c @@ -70,7 +70,7 @@ int pthread_detach(pthread_t thread) FAR struct tcb_s *tcb; int ret; - nxrmutex_lock(&group->tg_joinlock); + nxrmutex_lock(&group->tg_mutex); tcb = nxsched_get_tcb((pid_t)thread); if (tcb == NULL || (tcb->flags & TCB_FLAG_JOIN_COMPLETED) != 0) @@ -102,7 +102,7 @@ int pthread_detach(pthread_t thread) } errout: - nxrmutex_unlock(&group->tg_joinlock); + nxrmutex_unlock(&group->tg_mutex); sinfo("Returning %d\n", ret); return ret; diff --git a/sched/pthread/pthread_findjoininfo.c b/sched/pthread/pthread_findjoininfo.c index e2f19499588..30645d5c79c 100644 --- a/sched/pthread/pthread_findjoininfo.c +++ b/sched/pthread/pthread_findjoininfo.c @@ -76,7 +76,7 @@ int pthread_findjoininfo(FAR struct task_group_s *group, pid_t pid, FAR sq_entry_t *curr; FAR sq_entry_t *next; - nxrmutex_lock(&group->tg_joinlock); + nxrmutex_lock(&group->tg_mutex); sq_for_every_safe(&group->tg_joinqueue, curr, next) { @@ -88,7 +88,7 @@ int pthread_findjoininfo(FAR struct task_group_s *group, pid_t pid, } } - nxrmutex_unlock(&group->tg_joinlock); + nxrmutex_unlock(&group->tg_mutex); if (!create) { @@ -103,12 +103,12 @@ int pthread_findjoininfo(FAR struct task_group_s *group, pid_t pid, join->pid = pid; - nxrmutex_lock(&group->tg_joinlock); + nxrmutex_lock(&group->tg_mutex); sq_addfirst(&join->entry, &group->tg_joinqueue); found: - nxrmutex_unlock(&group->tg_joinlock); + nxrmutex_unlock(&group->tg_mutex); *pjoin = join; diff --git a/sched/pthread/pthread_join.c b/sched/pthread/pthread_join.c index a64d55d47c3..79e1bf0f63b 100644 --- a/sched/pthread/pthread_join.c +++ b/sched/pthread/pthread_join.c @@ -83,7 +83,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) enter_cancellation_point(); - nxrmutex_lock(&group->tg_joinlock); + nxrmutex_lock(&group->tg_mutex); tcb = nxsched_get_tcb((pid_t)thread); if (tcb == NULL || (tcb->flags & TCB_FLAG_JOIN_COMPLETED) != 0) @@ -136,7 +136,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) sq_addfirst(&rtcb->join_entry, &tcb->join_queue); - nxrmutex_unlock(&group->tg_joinlock); + nxrmutex_unlock(&group->tg_mutex); /* Take the thread's thread exit semaphore. We will sleep here * until the thread exits. We need to exercise caution because @@ -146,7 +146,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) nxsem_wait_uninterruptible(&rtcb->join_sem); - nxrmutex_lock(&group->tg_joinlock); + nxrmutex_lock(&group->tg_mutex); /* The thread has exited! Get the thread exit value */ @@ -156,7 +156,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value) } errout: - nxrmutex_unlock(&group->tg_joinlock); + nxrmutex_unlock(&group->tg_mutex); leave_cancellation_point(); diff --git a/sched/pthread/pthread_release.c b/sched/pthread/pthread_release.c index 867b62df98e..d8b89475871 100644 --- a/sched/pthread/pthread_release.c +++ b/sched/pthread/pthread_release.c @@ -75,8 +75,4 @@ void pthread_release(FAR struct task_group_s *group) kmm_free(container_of(curr, struct task_join_s, entry)); } - - /* Destroy the join list mutex */ - - nxrmutex_destroy(&group->tg_joinlock); }