pthread: Optimize mutex robustness configuration and remove unnecessary tl_lock #18136
+39
−52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request optimizes NuttX pthread mutex implementation by:
These changes improve performance, reduce memory overhead, and simplify synchronization logic without compromising safety.
Changes Made
Commit 1: Remove tl_lock
tl_lockfield fromstruct tls_info_spthread_mutex_add()andpthread_mutex_remove()pthread_mutex_inconsistent()Commit 2: Change Default Mutex Robustness
PTHREAD_MUTEX_DEFAULT_ROBUSTtoPTHREAD_MUTEX_DEFAULT_UNSAFEpthread_mutex_add/removefunctions to optimize hot pathsImpact
Performance:
Memory:
Compatibility:
Files Modified
Core Synchronization (Commit 1):
include/nuttx/tls.h- Remove tl_lock fieldlibs/libc/pthread/pthread_mutex.c- Remove lock operationssched/pthread/pthread_mutexinconsistent.c- Remove lock operationssched/sched/sched_releasetcb.c- Remove lock destructionsched/tls/tls_dupinfo.c- Remove lock initializationsched/tls/tls_initinfo.c- Remove lock initializationConfiguration (Commit 2):
libs/libc/pthread/pthread_mutex.c- Inline functions, conditional trackingsched/Kconfig- Change default robustness modeTechnical Justification
Why is tl_lock unnecessary?
tls->tl_mheadhave no intra-thread conflictspthread_mutex_inconsistentcalled only during task exitWhy change default to UNSAFE?
Testing Procedures
Functionality Tests:
ostestandpthreadtestto verify normal operationPerformance Tests:
Stress Tests:
Configuration Tests:
CONFIG_PTHREAD_MUTEX_ROBUSTonlyCONFIG_PTHREAD_MUTEX_UNSAFEonlyCONFIG_PTHREAD_MUTEX_BOTH(default=UNSAFE)Verification Checklist
Related Changes
This optimization series improves pthread synchronization by: