all repos — mgba @ 3660246a83a60d756dfabd3264520531843d5edb

mGBA Game Boy Advance Emulator

Core: Fix some deadlocks (fixes #1173)
Vicki Pfau vi@endrift.com
Sat, 15 Sep 2018 19:52:26 -0700
commit

3660246a83a60d756dfabd3264520531843d5edb

parent

723ac4c17307f8cc7a57bf330b51b6e0b3df4495

1 files changed, 11 insertions(+), 0 deletions(-)

jump to
M src/core/thread.csrc/core/thread.c

@@ -60,6 +60,11 @@ bool videoFrameWait = threadContext->sync.videoFrameWait;

threadContext->sync.videoFrameWait = false; MutexUnlock(&threadContext->sync.videoFrameMutex); + MutexLock(&threadContext->sync.audioBufferMutex); + bool audioWait = threadContext->sync.audioWait; + threadContext->sync.audioWait = false; + MutexUnlock(&threadContext->sync.audioBufferMutex); + while (threadContext->state == oldState) { MutexUnlock(&threadContext->stateMutex);

@@ -76,6 +81,10 @@

MutexLock(&threadContext->stateMutex); ConditionWake(&threadContext->stateCond); } + + MutexLock(&threadContext->sync.audioBufferMutex); + threadContext->sync.audioWait = audioWait; + MutexUnlock(&threadContext->sync.audioBufferMutex); MutexLock(&threadContext->sync.videoFrameMutex); threadContext->sync.videoFrameWait = videoFrameWait;

@@ -228,8 +237,10 @@ while (impl->state >= THREAD_WAITING && impl->state <= THREAD_MAX_WAITING) {

ConditionWait(&impl->stateCond, &impl->stateMutex); if (impl->sync.audioWait) { + MutexUnlock(&impl->stateMutex); mCoreSyncLockAudio(&impl->sync); mCoreSyncProduceAudio(&impl->sync, core->getAudioChannel(core, 0), core->getAudioBufferSize(core)); + MutexLock(&impl->stateMutex); } } }