Util: Add MutexTryLock
Jeffrey Pfau jeffrey@endrift.com
Thu, 12 Nov 2015 22:50:09 -0800
7 files changed,
33 insertions(+),
6 deletions(-)
M
CHANGES
→
CHANGES
@@ -44,6 +44,7 @@ - Util: Use VFile for configuration
- GBA Memory: Implement several unimplemented memory access types - GBA: Implement bad I/O register loading - GBA Memory: Add GBAView* functions for viewing memory directly without bus issues + - Util: Add MutexTryLock 0.3.1: (2015-10-24) Bugfixes:
M
src/gba/supervisor/thread.c
→
src/gba/supervisor/thread.c
@@ -71,13 +71,15 @@
while (threadContext->state == oldState) { MutexUnlock(&threadContext->stateMutex); - MutexLock(&threadContext->sync.videoFrameMutex); - ConditionWake(&threadContext->sync.videoFrameRequiredCond); - MutexUnlock(&threadContext->sync.videoFrameMutex); + if (!MutexTryLock(&threadContext->sync.videoFrameMutex)) { + ConditionWake(&threadContext->sync.videoFrameRequiredCond); + MutexUnlock(&threadContext->sync.videoFrameMutex); + } - MutexLock(&threadContext->sync.audioBufferMutex); - ConditionWake(&threadContext->sync.audioRequiredCond); - MutexUnlock(&threadContext->sync.audioBufferMutex); + if (!MutexLock(&threadContext->sync.audioBufferMutex)) { + ConditionWake(&threadContext->sync.audioRequiredCond); + MutexUnlock(&threadContext->sync.audioBufferMutex); + } MutexLock(&threadContext->stateMutex); ConditionWake(&threadContext->stateCond);
M
src/platform/3ds/threading.h
→
src/platform/3ds/threading.h
@@ -37,6 +37,10 @@ static inline int MutexLock(Mutex* mutex) {
return svcWaitSynchronization(*mutex, U64_MAX); } +static inline int MutexTryLock(Mutex* mutex) { + return svcWaitSynchronization(*mutex, 10); +} + static inline int MutexUnlock(Mutex* mutex) { return svcReleaseMutex(*mutex); }
M
src/platform/posix/threading.h
→
src/platform/posix/threading.h
@@ -33,6 +33,10 @@ static inline int MutexLock(Mutex* mutex) {
return pthread_mutex_lock(mutex); } +static inline int MutexTryLock(Mutex* mutex) { + return pthread_mutex_trylock(mutex); +} + static inline int MutexUnlock(Mutex* mutex) { return pthread_mutex_unlock(mutex); }
M
src/platform/psp2/threading.h
→
src/platform/psp2/threading.h
@@ -35,6 +35,10 @@ static inline int MutexLock(Mutex* mutex) {
return sceKernelLockMutex(*mutex, 1, 0); } +static inline int MutexTryLock(Mutex* mutex) { + return sceKernelTryLockMutex(*mutex, 1); +} + static inline int MutexUnlock(Mutex* mutex) { return sceKernelUnlockMutex(*mutex, 1); }
M
src/platform/windows/threading.h
→
src/platform/windows/threading.h
@@ -32,6 +32,13 @@ EnterCriticalSection(mutex);
return GetLastError(); } +static inline int MutexTryLock(Mutex* mutex) { + if (TryEnterCriticalSection(mutex)) { + return GetLastError(); + } + return 1; +} + static inline int MutexUnlock(Mutex* mutex) { LeaveCriticalSection(mutex); return GetLastError();
M
src/util/threading.h
→
src/util/threading.h
@@ -41,6 +41,11 @@ UNUSED(mutex);
return 0; } +static inline int MutexTryLock(Mutex* mutex) { + UNUSED(mutex); + return 0; +} + static inline int MutexUnlock(Mutex* mutex) { UNUSED(mutex); return 0;