Core: Fix some deadlocks (fixes #1173)

This commit is contained in:
Vicki Pfau 2018-09-15 19:52:26 -07:00
parent 723ac4c173
commit 3660246a83
1 changed files with 11 additions and 0 deletions

View File

@ -60,6 +60,11 @@ static void _waitUntilNotState(struct mCoreThreadInternal* threadContext, enum m
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);
@ -77,6 +82,10 @@ static void _waitUntilNotState(struct mCoreThreadInternal* threadContext, enum m
ConditionWake(&threadContext->stateCond);
}
MutexLock(&threadContext->sync.audioBufferMutex);
threadContext->sync.audioWait = audioWait;
MutexUnlock(&threadContext->sync.audioBufferMutex);
MutexLock(&threadContext->sync.videoFrameMutex);
threadContext->sync.videoFrameWait = videoFrameWait;
MutexUnlock(&threadContext->sync.videoFrameMutex);
@ -228,8 +237,10 @@ static THREAD_ENTRY _mCoreThreadRun(void* context) {
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);
}
}
}