mirror of https://github.com/mgba-emu/mgba.git
Core: Fix some deadlocks (fixes #1173)
This commit is contained in:
parent
723ac4c173
commit
3660246a83
src/core
|
@ -60,6 +60,11 @@ static void _waitUntilNotState(struct mCoreThreadInternal* threadContext, enum m
|
||||||
threadContext->sync.videoFrameWait = false;
|
threadContext->sync.videoFrameWait = false;
|
||||||
MutexUnlock(&threadContext->sync.videoFrameMutex);
|
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) {
|
while (threadContext->state == oldState) {
|
||||||
MutexUnlock(&threadContext->stateMutex);
|
MutexUnlock(&threadContext->stateMutex);
|
||||||
|
|
||||||
|
@ -77,6 +82,10 @@ static void _waitUntilNotState(struct mCoreThreadInternal* threadContext, enum m
|
||||||
ConditionWake(&threadContext->stateCond);
|
ConditionWake(&threadContext->stateCond);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MutexLock(&threadContext->sync.audioBufferMutex);
|
||||||
|
threadContext->sync.audioWait = audioWait;
|
||||||
|
MutexUnlock(&threadContext->sync.audioBufferMutex);
|
||||||
|
|
||||||
MutexLock(&threadContext->sync.videoFrameMutex);
|
MutexLock(&threadContext->sync.videoFrameMutex);
|
||||||
threadContext->sync.videoFrameWait = videoFrameWait;
|
threadContext->sync.videoFrameWait = videoFrameWait;
|
||||||
MutexUnlock(&threadContext->sync.videoFrameMutex);
|
MutexUnlock(&threadContext->sync.videoFrameMutex);
|
||||||
|
@ -228,8 +237,10 @@ static THREAD_ENTRY _mCoreThreadRun(void* context) {
|
||||||
ConditionWait(&impl->stateCond, &impl->stateMutex);
|
ConditionWait(&impl->stateCond, &impl->stateMutex);
|
||||||
|
|
||||||
if (impl->sync.audioWait) {
|
if (impl->sync.audioWait) {
|
||||||
|
MutexUnlock(&impl->stateMutex);
|
||||||
mCoreSyncLockAudio(&impl->sync);
|
mCoreSyncLockAudio(&impl->sync);
|
||||||
mCoreSyncProduceAudio(&impl->sync, core->getAudioChannel(core, 0), core->getAudioBufferSize(core));
|
mCoreSyncProduceAudio(&impl->sync, core->getAudioChannel(core, 0), core->getAudioBufferSize(core));
|
||||||
|
MutexLock(&impl->stateMutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue