From d270a42de8c19c73ef1eeaca165b458673139260 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 31 Jan 2020 18:06:18 -0800 Subject: [PATCH] Core: Fix race condition initializing thread proxy --- CHANGES | 1 + src/feature/thread-proxy.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 90442963d..4b9e1c695 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ Emulation fixes: - GBA Video: Fix backdrop blending on lines without sprites (fixes mgba.io/i/1647) - GBA Video: Fix OpenGL sprite flag priority Other fixes: + - Core: Fix race condition initializing thread proxy - Qt: Only dynamically reset video scale if a game is running - Qt: Fix race condition with proxied video events - Qt: Force OpenGL paint engine creation thread (fixes mgba.io/i/1642) diff --git a/src/feature/thread-proxy.c b/src/feature/thread-proxy.c index ba1785c46..d99e81066 100644 --- a/src/feature/thread-proxy.c +++ b/src/feature/thread-proxy.c @@ -137,8 +137,10 @@ static void _postEvent(struct mVideoLogger* logger, enum mVideoLoggerEvent event struct mVideoThreadProxy* proxyRenderer = (struct mVideoThreadProxy*) logger; MutexLock(&proxyRenderer->mutex); proxyRenderer->event = event; - ConditionWake(&proxyRenderer->toThreadCond); - ConditionWait(&proxyRenderer->fromThreadCond, &proxyRenderer->mutex); + while (proxyRenderer->event) { + ConditionWake(&proxyRenderer->toThreadCond); + ConditionWait(&proxyRenderer->fromThreadCond, &proxyRenderer->mutex); + } MutexUnlock(&proxyRenderer->mutex); } @@ -179,6 +181,7 @@ static THREAD_ENTRY _proxyThread(void* logger) { ThreadSetName("Proxy Renderer Thread"); MutexLock(&proxyRenderer->mutex); + ConditionWake(&proxyRenderer->fromThreadCond); while (proxyRenderer->threadState != PROXY_THREAD_STOPPED) { ConditionWait(&proxyRenderer->toThreadCond, &proxyRenderer->mutex); if (proxyRenderer->threadState == PROXY_THREAD_STOPPED) {