CoreMutex cleanup and add to build
This commit is contained in:
parent
8b45f56bf5
commit
bdb6a08704
@ -2,14 +2,14 @@
|
||||
#ifndef __CORE_MUTEX_H__
|
||||
#define __CORE_MUTEX_H__
|
||||
|
||||
typedef struct Mutex {
|
||||
typedef struct CoreMutex {
|
||||
uint64_t lock;
|
||||
} Mutex;
|
||||
} CoreMutex;
|
||||
|
||||
int CoreMutex_Init(Mutex *mtx);
|
||||
void CoreMutex_Lock(Mutex *mtx);
|
||||
bool CoreMutex_TryLock(Mutex *mtx);
|
||||
void CoreMutex_Unlock(Mutex *mtx);
|
||||
void CoreMutex_Init(CoreMutex *mtx);
|
||||
void CoreMutex_Lock(CoreMutex *mtx);
|
||||
bool CoreMutex_TryLock(CoreMutex *mtx);
|
||||
void CoreMutex_Unlock(CoreMutex *mtx);
|
||||
|
||||
#endif /* __CORE_MUTEX_H__ */
|
||||
|
||||
|
@ -9,6 +9,7 @@ src = [ ]
|
||||
src_common = [
|
||||
"abort.c",
|
||||
"assert.c",
|
||||
"core/mutex.c",
|
||||
"dir.c",
|
||||
"exit.c",
|
||||
"file.c",
|
||||
|
@ -2,23 +2,26 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <syscall.h>
|
||||
#include <core/mutex.h>
|
||||
|
||||
int
|
||||
CoreMutex_Init(Mutex *mtx)
|
||||
void
|
||||
CoreMutex_Init(CoreMutex *mtx)
|
||||
{
|
||||
mtx->lock = 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CoreMutex_Lock(Mutex *mtx)
|
||||
CoreMutex_Lock(CoreMutex *mtx)
|
||||
{
|
||||
while (__sync_lock_test_and_set(&mtx->lock, 1) == 1) {
|
||||
OSThreadSleep(0);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
CoreMutex_TryLock(Mutex *mtx)
|
||||
CoreMutex_TryLock(CoreMutex *mtx)
|
||||
{
|
||||
if (__sync_lock_test_and_set(&mtx->lock, 1) == 1) {
|
||||
return false;
|
||||
@ -28,7 +31,7 @@ CoreMutex_TryLock(Mutex *mtx)
|
||||
}
|
||||
|
||||
void
|
||||
CoreMutex_Unlock(Mutex *mtx)
|
||||
CoreMutex_Unlock(CoreMutex *mtx)
|
||||
{
|
||||
__sync_lock_release(&mtx->lock);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user