Util: Add MutexTryLock

This commit is contained in:
Jeffrey Pfau 2015-11-12 22:50:09 -08:00
parent d52a7f3689
commit aefb4b62a1
7 changed files with 33 additions and 6 deletions

View File

@ -44,6 +44,7 @@ Misc:
- 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:

View File

@ -71,13 +71,15 @@ static void _waitUntilNotState(struct GBAThread* threadContext, enum ThreadState
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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -32,6 +32,13 @@ static inline int MutexLock(Mutex* 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();

View File

@ -41,6 +41,11 @@ static inline int MutexLock(Mutex* mutex) {
return 0;
}
static inline int MutexTryLock(Mutex* mutex) {
UNUSED(mutex);
return 0;
}
static inline int MutexUnlock(Mutex* mutex) {
UNUSED(mutex);
return 0;