Fix threading issues with the video thread and the main thread deadlocking

This commit is contained in:
Jeffrey Pfau 2014-10-18 02:26:32 -07:00
parent f1de3d603a
commit 8e4a3439c0
3 changed files with 10 additions and 1 deletions

View File

@ -42,6 +42,7 @@ void Display::startDrawing(const uint32_t* buffer, GBAThread* thread) {
m_painter->setContext(thread);
m_painter->setBacking(buffer);
m_painter->moveToThread(m_drawThread);
m_context = thread;
doneCurrent();
context()->moveToThread(m_drawThread);
connect(m_drawThread, SIGNAL(started()), m_painter, SLOT(start()));
@ -50,9 +51,13 @@ void Display::startDrawing(const uint32_t* buffer, GBAThread* thread) {
void Display::stopDrawing() {
if (m_drawThread) {
GBAThreadInterrupt(m_context);
GBASyncSuspendDrawing(&m_context->sync);
QMetaObject::invokeMethod(m_painter, "stop", Qt::BlockingQueuedConnection);
m_drawThread->exit();
m_drawThread = nullptr;
GBASyncResumeDrawing(&m_context->sync);
GBAThreadContinue(m_context);
}
}
@ -70,7 +75,11 @@ void Display::initializeGL() {
void Display::resizeEvent(QResizeEvent* event) {
if (m_drawThread) {
GBAThreadInterrupt(m_context);
GBASyncSuspendDrawing(&m_context->sync);
QMetaObject::invokeMethod(m_painter, "resize", Qt::BlockingQueuedConnection, Q_ARG(QSize, event->size()));
GBASyncResumeDrawing(&m_context->sync);
GBAThreadContinue(m_context);
}
}

View File

@ -29,6 +29,7 @@ protected:
private:
Painter* m_painter;
QThread* m_drawThread;
GBAThread* m_context;
};
class Painter : public QObject {

View File

@ -215,7 +215,6 @@ void GameController::setFPSTarget(float fps) {
void GameController::loadState(int slot) {
GBAThreadInterrupt(&m_threadContext);
GBALoadState(m_threadContext.gba, m_threadContext.stateDir, slot);
ConditionWake(&m_threadContext.sync.videoFrameAvailableCond); // Hack: wake up the drawing thread
GBAThreadContinue(&m_threadContext);
emit stateLoaded(&m_threadContext);
emit frameAvailable(m_drawContext);