mirror of https://github.com/mgba-emu/mgba.git
Util: Add MutexTryLock
This commit is contained in:
parent
d52a7f3689
commit
aefb4b62a1
1
CHANGES
1
CHANGES
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue