Qt: Fix race condition with proxied video events

This commit is contained in:
Vicki Pfau 2020-01-22 18:22:25 -08:00
parent d044c05f30
commit 541715008b
3 changed files with 16 additions and 1 deletions

View File

@ -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:

View File

@ -138,6 +138,7 @@ static void _postEvent(struct mVideoLogger* logger, enum mVideoLoggerEvent event
MutexLock(&proxyRenderer->mutex);
proxyRenderer->event = event;
ConditionWake(&proxyRenderer->toThreadCond);
ConditionWait(&proxyRenderer->fromThreadCond, &proxyRenderer->mutex);
MutexUnlock(&proxyRenderer->mutex);
}

View File

@ -7,6 +7,8 @@
#include "CoreController.h"
#include <QThread>
using namespace QGBA;
VideoProxy::VideoProxy() {
@ -81,11 +83,22 @@ bool VideoProxy::readData(void* data, size_t length, bool block) {
}
void VideoProxy::postEvent(enum mVideoLoggerEvent 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() {