From 082a3d3085eeb3c6db7c6dbc63daf14c3ef1b42b Mon Sep 17 00:00:00 2001 From: hujun5 Date: Fri, 15 Aug 2025 20:40:54 +0800 Subject: [PATCH] pthread: remove tl_lock This lock is currently used in three places, mainly to protect tls->tl_mhead. Among them, pthread_mutex_add and pthread_mutex_remove involve writing to tls->tl_mhead, and there is certainly no conflict within the same thread. As for pthread_mutex_inconsistent, it involves reading. Currently, it can only be called when the TCB task corresponding to this tls exits, and the TCB corresponding to the tls can no longer continue to run. It seems that adding the lock serves no real purpose. Signed-off-by: hujun5 --- include/nuttx/tls.h | 3 --- libs/libc/pthread/pthread_mutex.c | 5 ----- libs/libc/pthread/pthread_mutex_inconsistent.c | 4 ---- sched/sched/sched_releasetcb.c | 4 ---- sched/tls/tls_dupinfo.c | 4 ---- sched/tls/tls_initinfo.c | 4 ---- 6 files changed, 24 deletions(-) diff --git a/include/nuttx/tls.h b/include/nuttx/tls.h index e8af699b38c..e7b673aed5f 100644 --- a/include/nuttx/tls.h +++ b/include/nuttx/tls.h @@ -232,9 +232,6 @@ struct tls_info_s #if !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE) FAR struct pthread_mutex_s *tl_mhead; /* List of mutexes held by thread */ #endif -#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE - mutex_t tl_lock; -#endif }; /**************************************************************************** diff --git a/libs/libc/pthread/pthread_mutex.c b/libs/libc/pthread/pthread_mutex.c index 1d65d545916..d1b9a232d0b 100644 --- a/libs/libc/pthread/pthread_mutex.c +++ b/libs/libc/pthread/pthread_mutex.c @@ -66,10 +66,8 @@ static void pthread_mutex_add(FAR struct pthread_mutex_s *mutex) /* Add the mutex to the list of mutexes held by this pthread */ - nxmutex_lock(&tls->tl_lock); mutex->flink = tls->tl_mhead; tls->tl_mhead = mutex; - nxmutex_unlock(&tls->tl_lock); } /**************************************************************************** @@ -92,8 +90,6 @@ static void pthread_mutex_remove(FAR struct pthread_mutex_s *mutex) FAR struct pthread_mutex_s *curr; FAR struct pthread_mutex_s *prev; - nxmutex_lock(&tls->tl_lock); - /* Remove the mutex from the list of mutexes held by this task */ for (prev = NULL, curr = tls->tl_mhead; @@ -118,7 +114,6 @@ static void pthread_mutex_remove(FAR struct pthread_mutex_s *mutex) } mutex->flink = NULL; - nxmutex_unlock(&tls->tl_lock); } /**************************************************************************** diff --git a/libs/libc/pthread/pthread_mutex_inconsistent.c b/libs/libc/pthread/pthread_mutex_inconsistent.c index e310c5e35ab..d35a1914800 100644 --- a/libs/libc/pthread/pthread_mutex_inconsistent.c +++ b/libs/libc/pthread/pthread_mutex_inconsistent.c @@ -64,8 +64,6 @@ void pthread_mutex_inconsistent(FAR struct tls_info_s *tls) { FAR struct pthread_mutex_s *mutex; - nxmutex_lock(&tls->tl_lock); - /* Remove and process each mutex held by this task */ while (tls->tl_mhead != NULL) @@ -81,6 +79,4 @@ void pthread_mutex_inconsistent(FAR struct tls_info_s *tls) mutex->flags |= _PTHREAD_MFLAGS_INCONSISTENT; mutex_reset(&mutex->mutex); } - - nxmutex_unlock(&tls->tl_lock); } diff --git a/sched/sched/sched_releasetcb.c b/sched/sched/sched_releasetcb.c index 7d2b51816a7..96b3e736e79 100644 --- a/sched/sched/sched_releasetcb.c +++ b/sched/sched/sched_releasetcb.c @@ -118,10 +118,6 @@ int nxsched_release_tcb(FAR struct tcb_s *tcb, uint8_t ttype) timer_deleteall(tcb->pid); #endif -#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE - nxmutex_destroy(&nxsched_get_tls(tcb)->tl_lock); -#endif - /* Release the task's process ID if one was assigned. PID * zero is reserved for the IDLE task. The TCB of the IDLE * task is never release so a value of zero simply means that diff --git a/sched/tls/tls_dupinfo.c b/sched/tls/tls_dupinfo.c index c1c5fe8776b..5ee29d93de9 100644 --- a/sched/tls/tls_dupinfo.c +++ b/sched/tls/tls_dupinfo.c @@ -81,9 +81,5 @@ int tls_dup_info(FAR struct tcb_s *dst, FAR struct tcb_s *src) info->tl_tid = dst->pid; -#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE - nxmutex_init(&info->tl_lock); -#endif - return OK; } diff --git a/sched/tls/tls_initinfo.c b/sched/tls/tls_initinfo.c index 99ff59ad67e..c38704a19cf 100644 --- a/sched/tls/tls_initinfo.c +++ b/sched/tls/tls_initinfo.c @@ -84,9 +84,5 @@ int tls_init_info(FAR struct tcb_s *tcb) info->tl_argv = NULL; -#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE - nxmutex_init(&info->tl_lock); -#endif - return OK; }