diff --git a/nx/include/switch/kernel/mutex.h b/nx/include/switch/kernel/mutex.h index 99d4020f6..2e73b61f6 100644 --- a/nx/include/switch/kernel/mutex.h +++ b/nx/include/switch/kernel/mutex.h @@ -57,7 +57,6 @@ bool mutexIsLockedByCurrentThread(const Mutex* m); static inline void rmutexInit(RMutex* m) { m->lock = 0; - m->thread_tag = 0; m->counter = 0; } diff --git a/nx/source/kernel/mutex.c b/nx/source/kernel/mutex.c index 86ae2628e..028a71317 100644 --- a/nx/source/kernel/mutex.c +++ b/nx/source/kernel/mutex.c @@ -139,20 +139,15 @@ bool mutexIsLockedByCurrentThread(const Mutex* m) { } void rmutexLock(RMutex* m) { - if (m->thread_tag != _GetTag()) { + if (!mutexIsLockedByCurrentThread(&m->lock)) { mutexLock(&m->lock); - m->thread_tag = _GetTag(); + m->counter++; } - - m->counter++; } bool rmutexTryLock(RMutex* m) { - if (m->thread_tag != _GetTag()) { - if (!mutexTryLock(&m->lock)) { - return false; - } - m->thread_tag = _GetTag(); + if (!mutexIsLockedByCurrentThread(&m->lock)) { + return mutexTryLock(&m->lock); } m->counter++; @@ -161,7 +156,6 @@ bool rmutexTryLock(RMutex* m) { void rmutexUnlock(RMutex* m) { if (--m->counter == 0) { - m->thread_tag = 0; mutexUnlock(&m->lock); } } diff --git a/nx/source/runtime/newlib.c b/nx/source/runtime/newlib.c index 49d496d63..2215c88ee 100644 --- a/nx/source/runtime/newlib.c +++ b/nx/source/runtime/newlib.c @@ -108,17 +108,13 @@ int __syscall_cond_wait(_COND_T *cond, _LOCK_T *lock, uint64_t timeout_ns) int __syscall_cond_wait_recursive(_COND_T *cond, _LOCK_RECURSIVE_T *lock, uint64_t timeout_ns) { - uint32_t thread_tag_backup = 0; if (lock->counter != 1) return EBADF; - thread_tag_backup = lock->thread_tag; - lock->thread_tag = 0; lock->counter = 0; int errcode = errno_from_result(condvarWaitTimeout(cond, &lock->lock, timeout_ns)); - lock->thread_tag = thread_tag_backup; lock->counter = 1; return errcode;