Qt: Fix race condition with proxied video events
Vicki Pfau vi@endrift.com
Wed, 22 Jan 2020 18:22:25 -0800
3 files changed,
16 insertions(+),
1 deletions(-)
M
src/feature/thread-proxy.c
→
src/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.cpp
→
src/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() {