Integrate nxmutex support fully into nxsem

This puts the mutex support fully inside nxsem, allowing
locking the mutex and setting the holder with single atomic
operation.

This enables fast mutex locking from userspace, avoiding taking
critical_sections, which may be heavy in SMP and cleanup
of nxmutex library in the future.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
This commit is contained in:
Jukka Laitinen
2025-03-31 08:37:10 +03:00
committed by Xiang Xiao
parent 5c188b6625
commit b6f2729730
19 changed files with 364 additions and 119 deletions
+4 -2
View File
@@ -30,6 +30,7 @@
#include <assert.h>
#include <sched.h>
#include <nuttx/sched.h>
#include <nuttx/init.h>
#include <nuttx/cancelpt.h>
#include <nuttx/semaphore.h>
@@ -156,8 +157,9 @@ int nxsem_wait(FAR sem_t *sem)
# endif
)
{
int32_t old = 1;
if (atomic_try_cmpxchg_acquire(NXSEM_COUNT(sem), &old, 0))
int32_t tid = _SCHED_GETTID();
int32_t old = NXSEM_NO_MHOLDER;
if (atomic_try_cmpxchg_acquire(NXSEM_MHOLDER(sem), &old, tid))
{
return OK;
}