From eefdcb649034ae17c83f8564a00fbb8d9242a0ee Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 9 Feb 2016 02:17:22 -0800 Subject: [PATCH] Core: Put back sync handling in _waitUntilNotState --- src/core/thread.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/core/thread.c b/src/core/thread.c index 21de2f7af..88712a177 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -51,12 +51,31 @@ static void _waitOnInterrupt(struct mCoreThread* threadContext) { } 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) {