mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
Change type of TryLock to bool
This commit is contained in:
parent
e966f21800
commit
20f3e87d11
@ -6,7 +6,7 @@
|
||||
*/
|
||||
#pragma once
|
||||
#include <sys/lock.h>
|
||||
#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.
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user