pthread: make PTHREAD_MUTEX_DEFAULT_UNSAFE default true

Change the default pthread mutex robustness from ROBUST to UNSAFE when
CONFIG_PTHREAD_MUTEX_BOTH is enabled. This reflects the practical default
and allows removal of tracking code for non-robust mutexes, improving
performance and reducing memory overhead.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2025-08-17 10:47:26 +08:00
committed by Xiang Xiao
parent 082a3d3085
commit 6e8ae12ef1
2 changed files with 43 additions and 32 deletions
+41 -30
View File
@@ -58,16 +58,21 @@
*
****************************************************************************/
static void pthread_mutex_add(FAR struct pthread_mutex_s *mutex)
static inline_function
void pthread_mutex_add(FAR struct pthread_mutex_s *mutex)
{
FAR struct tls_info_s *tls = tls_get_info();
FAR struct tls_info_s *tls;
DEBUGASSERT(mutex->flink == NULL);
if ((mutex->flags & _PTHREAD_MFLAGS_ROBUST) != 0)
{
tls = tls_get_info();
DEBUGASSERT(mutex->flink == NULL);
/* Add the mutex to the list of mutexes held by this pthread */
/* Add the mutex to the list of mutexes held by this pthread */
mutex->flink = tls->tl_mhead;
tls->tl_mhead = mutex;
mutex->flink = tls->tl_mhead;
tls->tl_mhead = mutex;
}
}
/****************************************************************************
@@ -84,36 +89,42 @@ static void pthread_mutex_add(FAR struct pthread_mutex_s *mutex)
*
****************************************************************************/
static void pthread_mutex_remove(FAR struct pthread_mutex_s *mutex)
static inline_function
void pthread_mutex_remove(FAR struct pthread_mutex_s *mutex)
{
FAR struct tls_info_s *tls = tls_get_info();
FAR struct tls_info_s *tls;
FAR struct pthread_mutex_s *curr;
FAR struct pthread_mutex_s *prev;
/* Remove the mutex from the list of mutexes held by this task */
for (prev = NULL, curr = tls->tl_mhead;
curr != NULL && curr != mutex;
prev = curr, curr = curr->flink)
if ((mutex->flags & _PTHREAD_MFLAGS_ROBUST) != 0)
{
tls = tls_get_info();
/* Remove the mutex from the list of mutexes held by this task */
for (prev = NULL, curr = tls->tl_mhead;
curr != NULL && curr != mutex;
prev = curr, curr = curr->flink)
{
}
DEBUGASSERT(curr == mutex);
/* Remove the mutex from the list. prev == NULL means that the mutex
* to be removed is at the head of the list.
*/
if (prev == NULL)
{
tls->tl_mhead = mutex->flink;
}
else
{
prev->flink = mutex->flink;
}
mutex->flink = NULL;
}
DEBUGASSERT(curr == mutex);
/* Remove the mutex from the list. prev == NULL means that the mutex
* to be removed is at the head of the list.
*/
if (prev == NULL)
{
tls->tl_mhead = mutex->flink;
}
else
{
prev->flink = mutex->flink;
}
mutex->flink = NULL;
}
/****************************************************************************
+2 -2
View File
@@ -828,7 +828,7 @@ config PTHREAD_MUTEX_TYPES
choice
prompt "pthread mutex robustness"
default PTHREAD_MUTEX_ROBUST if !DEFAULT_SMALL
default PTHREAD_MUTEX_BOTH if !DEFAULT_SMALL
default PTHREAD_MUTEX_UNSAFE if DEFAULT_SMALL
config PTHREAD_MUTEX_ROBUST
@@ -853,7 +853,7 @@ endchoice # pthread mutex robustness
choice
prompt "Default NORMAL mutex robustness"
default PTHREAD_MUTEX_DEFAULT_ROBUST
default PTHREAD_MUTEX_DEFAULT_UNSAFE
depends on PTHREAD_MUTEX_BOTH
config PTHREAD_MUTEX_DEFAULT_ROBUST