all repos — mgba @ 0d6946dceecb7d364c13258b6d9cfc8a9eb20bd1

mGBA Game Boy Advance Emulator

3DS: Migrate to libctru CondVar
Vicki Pfau vi@endrift.com
Fri, 31 Jul 2020 19:16:45 -0700
commit

0d6946dceecb7d364c13258b6d9cfc8a9eb20bd1

parent

4617c40ac4647d2c9526e39bb6ff9b7d12fac1e0

1 files changed, 8 insertions(+), 33 deletions(-)

jump to
M include/mgba-util/platform/3ds/threading.hinclude/mgba-util/platform/3ds/threading.h

@@ -15,11 +15,7 @@ #define THREAD_ENTRY void

typedef ThreadFunc ThreadEntry; typedef LightLock Mutex; -typedef struct { - Mutex mutex; - Handle semaphore; - u32 waiting; -} Condition; +typedef CondVar Condition; static inline int MutexInit(Mutex* mutex) { LightLock_Init(mutex);

@@ -46,47 +42,26 @@ return 0;

} static inline int ConditionInit(Condition* cond) { - Result res = MutexInit(&cond->mutex); - if (res) { - return res; - } - res = svcCreateSemaphore(&cond->semaphore, 0, 1); - cond->waiting = 0; - return res; + CondVar_Init(cond); + return 0; } static inline int ConditionDeinit(Condition* cond) { - return svcCloseHandle(cond->semaphore); + UNUSED(cond); + return 0; } static inline int ConditionWait(Condition* cond, Mutex* mutex) { - MutexLock(&cond->mutex); - ++cond->waiting; - MutexUnlock(mutex); - MutexUnlock(&cond->mutex); - svcWaitSynchronization(cond->semaphore, U64_MAX); - MutexLock(mutex); + CondVar_Wait(cond, mutex); return 0; } static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) { - MutexLock(&cond->mutex); - ++cond->waiting; - MutexUnlock(mutex); - MutexUnlock(&cond->mutex); - svcWaitSynchronization(cond->semaphore, timeoutMs * 10000000LL); - MutexLock(mutex); - return 0; + return CondVar_WaitTimeout(cond, mutex, timeoutMs * 10000000LL); } static inline int ConditionWake(Condition* cond) { - MutexLock(&cond->mutex); - if (cond->waiting) { - --cond->waiting; - s32 count = 0; - svcReleaseSemaphore(&count, cond->semaphore, 1); - } - MutexUnlock(&cond->mutex); + CondVar_Signal(cond); return 0; }