From 20f3e87d11557ae909bb9aedf25a1d48879b009f Mon Sep 17 00:00:00 2001 From: plutoo Date: Wed, 28 Feb 2018 18:22:28 +0100 Subject: [PATCH] Change type of TryLock to bool --- nx/include/switch/kernel/mutex.h | 6 +++--- nx/source/kernel/mutex.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nx/include/switch/kernel/mutex.h b/nx/include/switch/kernel/mutex.h index 73fbc1e5..fe6ca3a3 100644 --- a/nx/include/switch/kernel/mutex.h +++ b/nx/include/switch/kernel/mutex.h @@ -6,7 +6,7 @@ */ #pragma once #include -#include "../types.h" // not needed in this file, still including it +#include "../types.h" /// Mutex datatype, defined in newlib. typedef _LOCK_T Mutex; @@ -34,7 +34,7 @@ void mutexLock(Mutex* m); * @param m Mutex object. * @return 1 if the mutex has been acquired successfully, and 0 on contention. */ -u32 mutexTryLock(Mutex* m); +bool mutexTryLock(Mutex* m); /** * @brief Unlocks a mutex. @@ -65,7 +65,7 @@ void rmutexLock(RMutex* m); * @param m Recursive mutex object. * @return 1 if the mutex has been acquired successfully, and 0 on contention. */ -u32 rmutexTryLock(RMutex* m); +bool rmutexTryLock(RMutex* m); /** * @brief Unlocks a recursive mutex. diff --git a/nx/source/kernel/mutex.c b/nx/source/kernel/mutex.c index 5213e926..2152a8d8 100644 --- a/nx/source/kernel/mutex.c +++ b/nx/source/kernel/mutex.c @@ -41,18 +41,18 @@ void mutexLock(Mutex* m) { } } -u32 mutexTryLock(Mutex* m) { +bool mutexTryLock(Mutex* m) { u32 self = _GetTag(); u32 cur = __sync_val_compare_and_swap((u32*)m, 0, self); if (cur == 0) { // We won the race! - return 1; + return true; } if ((cur &~ HAS_LISTENERS) == self) { // Kernel assigned it to us! - return 1; + return true; } return 0; @@ -75,16 +75,16 @@ void rmutexLock(RMutex* m) { m->counter++; } -u32 rmutexTryLock(RMutex* m) { +bool rmutexTryLock(RMutex* m) { if (m->thread_tag != _GetTag()) { if (!mutexTryLock(&m->lock)) { - return 0; + return false; } m->thread_tag = _GetTag(); } m->counter++; - return 1; + return true; } void rmutexUnlock(RMutex* m) {