all repos — mgba @ eefdcb649034ae17c83f8564a00fbb8d9242a0ee

mGBA Game Boy Advance Emulator

Core: Put back sync handling in _waitUntilNotState
Jeffrey Pfau jeffrey@endrift.com
Tue, 09 Feb 2016 02:17:22 -0800
commit

eefdcb649034ae17c83f8564a00fbb8d9242a0ee

parent

32f5bb985d87913fed348609053f3944ecca604b

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

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

@@ -51,12 +51,31 @@ }

} static void _waitUntilNotState(struct mCoreThread* threadContext, enum mCoreThreadState oldState) { + MutexLock(&threadContext->sync.videoFrameMutex); + bool videoFrameWait = threadContext->sync.videoFrameWait; + threadContext->sync.videoFrameWait = false; + MutexUnlock(&threadContext->sync.videoFrameMutex); + while (threadContext->state == oldState) { MutexUnlock(&threadContext->stateMutex); + if (!MutexTryLock(&threadContext->sync.videoFrameMutex)) { + ConditionWake(&threadContext->sync.videoFrameRequiredCond); + MutexUnlock(&threadContext->sync.videoFrameMutex); + } + + if (!MutexTryLock(&threadContext->sync.audioBufferMutex)) { + ConditionWake(&threadContext->sync.audioRequiredCond); + MutexUnlock(&threadContext->sync.audioBufferMutex); + } + MutexLock(&threadContext->stateMutex); ConditionWake(&threadContext->stateCond); } + + MutexLock(&threadContext->sync.videoFrameMutex); + threadContext->sync.videoFrameWait = videoFrameWait; + MutexUnlock(&threadContext->sync.videoFrameMutex); } static void _pauseThread(struct mCoreThread* threadContext, bool onThread) {