pthread: Move condition variable implementation to userspace #18139
+209
−172
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 the NuttX pthread implementation by moving condition variable operations from kernel space to userspace. This change:
Changes Made
Core Migration:
sched/pthread/tolibs/libc/pthread/:pthread_condbroadcast.cpthread_condclockwait.cpthread_condsignal.cpthread_condwait.cKernel-side removals:
include/nuttx/pthread.hinclude/sys/syscall_lookup.h:pthread_cond_broadcastpthread_cond_signalpthread_cond_waitpthread_cond_clockwaitsched/pthread/build configurationUserspace additions:
libs/libc/pthread/pthread.hwith mutex/condition variable interface macroslibs/libc/pthread/CMakeLists.txtto include moved source fileslibs/libc/pthread/Make.defsto compile condition variable sourceslibs/libc/semaphore/sem_wait.cwith improved wait implementationBuild system updates:
include/sys/syscall_lookup.h,syscall/syscall.csv)Impact
Performance:
Code Size:
API Compatibility:
Architecture Benefits:
Technical Justification
Why move to userspace?
How does it work?
Testing Procedures
Functional Tests:
ostestwith pthread condition variable testspthreadtestto verify all condition variable operationsPerformance Tests:
Stress Tests:
Configuration Tests:
Verification Checklist
Files Modified Summary
Header Files:
include/nuttx/pthread.h(-54 lines) - Remove macros, move to libsinclude/sys/syscall_lookup.h(-4 lines) - Remove condition variable syscallsUserspace Library:
libs/libc/pthread/pthread.h(+99 lines) - New interface macroslibs/libc/pthread/CMakeLists.txt- Add condition variable sourceslibs/libc/pthread/Make.defs- Add condition variable sourceslibs/libc/pthread/pthread_cond*.c- Moved implementation fileslibs/libc/pthread/pthread_mutex*.c- Updated includeslibs/libc/semaphore/sem_wait.c(+72 lines) - Enhanced implementationKernel-side:
sched/pthread/CMakeLists.txt- Remove moved sourcessched/pthread/Make.defs- Remove moved sourcessched/pthread/pthread.h- Remove moved definitionssched/semaphore/sem_*.c- Remove duplicate codesyscall/syscall.csv- Remove condition variable syscallsTask System:
sched/task/task_recover.c- Update for new structureRelated Changes
This userspace migration aligns with other NuttX optimizations:
Migration Path