Core: Fix some deadlocks (fixes #1173)
Vicki Pfau vi@endrift.com
Sat, 15 Sep 2018 19:52:26 -0700
1 files changed,
11 insertions(+),
0 deletions(-)
jump to
M
src/core/thread.c
→
src/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); } } }