mirror of https://github.com/mgba-emu/mgba.git
3DS: Convert mutexes to light locks
This commit is contained in:
parent
98fd8a7532
commit
8a68de198c
|
@ -23,7 +23,7 @@ typedef struct {
|
||||||
Handle handle;
|
Handle handle;
|
||||||
u8* stack;
|
u8* stack;
|
||||||
} Thread;
|
} Thread;
|
||||||
typedef Handle Mutex;
|
typedef LightLock Mutex;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
Handle semaphore;
|
Handle semaphore;
|
||||||
|
@ -31,40 +31,40 @@ typedef struct {
|
||||||
} Condition;
|
} Condition;
|
||||||
|
|
||||||
static inline int MutexInit(Mutex* mutex) {
|
static inline int MutexInit(Mutex* mutex) {
|
||||||
return svcCreateMutex(mutex, false);
|
LightLock_Init(mutex);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int MutexDeinit(Mutex* mutex) {
|
static inline int MutexDeinit(Mutex* mutex) {
|
||||||
return svcCloseHandle(*mutex);
|
UNUSED(mutex);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int MutexLock(Mutex* mutex) {
|
static inline int MutexLock(Mutex* mutex) {
|
||||||
return svcWaitSynchronization(*mutex, U64_MAX);
|
LightLock_Lock(mutex);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int MutexTryLock(Mutex* mutex) {
|
static inline int MutexTryLock(Mutex* mutex) {
|
||||||
return svcWaitSynchronization(*mutex, 10);
|
return LightLock_TryLock(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int MutexUnlock(Mutex* mutex) {
|
static inline int MutexUnlock(Mutex* mutex) {
|
||||||
return svcReleaseMutex(*mutex);
|
LightLock_Unlock(mutex);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ConditionInit(Condition* cond) {
|
static inline int ConditionInit(Condition* cond) {
|
||||||
Result res = svcCreateMutex(&cond->mutex, false);
|
Result res = MutexInit(&cond->mutex);
|
||||||
if (res) {
|
if (res) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
res = svcCreateSemaphore(&cond->semaphore, 0, 1);
|
res = svcCreateSemaphore(&cond->semaphore, 0, 1);
|
||||||
if (res) {
|
|
||||||
svcCloseHandle(cond->mutex);
|
|
||||||
}
|
|
||||||
cond->waiting = 0;
|
cond->waiting = 0;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ConditionDeinit(Condition* cond) {
|
static inline int ConditionDeinit(Condition* cond) {
|
||||||
svcCloseHandle(cond->mutex);
|
|
||||||
return svcCloseHandle(cond->semaphore);
|
return svcCloseHandle(cond->semaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue