Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion nx/include/switch/kernel/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
14 changes: 4 additions & 10 deletions nx/source/kernel/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -161,7 +156,6 @@ bool rmutexTryLock(RMutex* m) {

void rmutexUnlock(RMutex* m) {
if (--m->counter == 0) {
m->thread_tag = 0;
mutexUnlock(&m->lock);
}
}
4 changes: 0 additions & 4 deletions nx/source/runtime/newlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading