Change type of TryLock to bool

This commit is contained in:
plutoo 2018-02-28 18:22:28 +01:00
parent e966f21800
commit 20f3e87d11
2 changed files with 9 additions and 9 deletions

View File

@ -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.

View File

@ -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) {