group: use tg_mutex to replace tg_joinlock
Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
parent
544da3c64c
commit
fcfc300f7a
8 changed files with 23 additions and 22 deletions
|
|
@ -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 *************************************************************/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue