all repos — mgba @ 541715008bea659104a1705caa69a7bfd3f36637

mGBA Game Boy Advance Emulator

Qt: Fix race condition with proxied video events
Vicki Pfau vi@endrift.com
Wed, 22 Jan 2020 18:22:25 -0800
commit

541715008bea659104a1705caa69a7bfd3f36637

parent

d044c05f30cd6c7591c5ec03b310253fdc06d7d1

3 files changed, 16 insertions(+), 1 deletions(-)

jump to
M CHANGESCHANGES

@@ -1,6 +1,7 @@

0.9.0: (Future) Other fixes: - Qt: Only dynamically reset video scale if a game is running + - Qt: Fix race condition with proxied video events 0.8.0: (2020-01-21) Features:
M src/feature/thread-proxy.csrc/feature/thread-proxy.c

@@ -138,6 +138,7 @@ struct mVideoThreadProxy* proxyRenderer = (struct mVideoThreadProxy*) logger;

MutexLock(&proxyRenderer->mutex); proxyRenderer->event = event; ConditionWake(&proxyRenderer->toThreadCond); + ConditionWait(&proxyRenderer->fromThreadCond, &proxyRenderer->mutex); MutexUnlock(&proxyRenderer->mutex); }
M src/platform/qt/VideoProxy.cppsrc/platform/qt/VideoProxy.cpp

@@ -7,6 +7,8 @@ #include "VideoProxy.h"

#include "CoreController.h" +#include <QThread> + using namespace QGBA; VideoProxy::VideoProxy() {

@@ -81,11 +83,22 @@ return read;

} void VideoProxy::postEvent(enum mVideoLoggerEvent event) { - emit eventPosted(event); + if (QThread::currentThread() == thread()) { + // We're on the main thread + emit eventPosted(event); + } else { + m_mutex.lock(); + emit eventPosted(event); + m_fromThreadCond.wait(&m_mutex, 1); + m_mutex.unlock(); + } } void VideoProxy::handleEvent(int event) { + m_mutex.lock(); m_logger.d.handleEvent(&m_logger.d, static_cast<enum mVideoLoggerEvent>(event)); + m_fromThreadCond.wakeAll(); + m_mutex.unlock(); } void VideoProxy::lock() {