mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
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:
committed by
Xiang Xiao
parent
5c188b6625
commit
b6f2729730
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user