mirror of https://github.com/mgba-emu/mgba.git
Fix threading issues with the video thread and the main thread deadlocking
This commit is contained in:
parent
f1de3d603a
commit
8e4a3439c0
|
@ -42,6 +42,7 @@ void Display::startDrawing(const uint32_t* buffer, GBAThread* thread) {
|
||||||
m_painter->setContext(thread);
|
m_painter->setContext(thread);
|
||||||
m_painter->setBacking(buffer);
|
m_painter->setBacking(buffer);
|
||||||
m_painter->moveToThread(m_drawThread);
|
m_painter->moveToThread(m_drawThread);
|
||||||
|
m_context = thread;
|
||||||
doneCurrent();
|
doneCurrent();
|
||||||
context()->moveToThread(m_drawThread);
|
context()->moveToThread(m_drawThread);
|
||||||
connect(m_drawThread, SIGNAL(started()), m_painter, SLOT(start()));
|
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() {
|
void Display::stopDrawing() {
|
||||||
if (m_drawThread) {
|
if (m_drawThread) {
|
||||||
|
GBAThreadInterrupt(m_context);
|
||||||
|
GBASyncSuspendDrawing(&m_context->sync);
|
||||||
QMetaObject::invokeMethod(m_painter, "stop", Qt::BlockingQueuedConnection);
|
QMetaObject::invokeMethod(m_painter, "stop", Qt::BlockingQueuedConnection);
|
||||||
m_drawThread->exit();
|
m_drawThread->exit();
|
||||||
m_drawThread = nullptr;
|
m_drawThread = nullptr;
|
||||||
|
GBASyncResumeDrawing(&m_context->sync);
|
||||||
|
GBAThreadContinue(m_context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +75,11 @@ void Display::initializeGL() {
|
||||||
|
|
||||||
void Display::resizeEvent(QResizeEvent* event) {
|
void Display::resizeEvent(QResizeEvent* event) {
|
||||||
if (m_drawThread) {
|
if (m_drawThread) {
|
||||||
|
GBAThreadInterrupt(m_context);
|
||||||
|
GBASyncSuspendDrawing(&m_context->sync);
|
||||||
QMetaObject::invokeMethod(m_painter, "resize", Qt::BlockingQueuedConnection, Q_ARG(QSize, event->size()));
|
QMetaObject::invokeMethod(m_painter, "resize", Qt::BlockingQueuedConnection, Q_ARG(QSize, event->size()));
|
||||||
|
GBASyncResumeDrawing(&m_context->sync);
|
||||||
|
GBAThreadContinue(m_context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
Painter* m_painter;
|
Painter* m_painter;
|
||||||
QThread* m_drawThread;
|
QThread* m_drawThread;
|
||||||
|
GBAThread* m_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Painter : public QObject {
|
class Painter : public QObject {
|
||||||
|
|
|
@ -215,7 +215,6 @@ void GameController::setFPSTarget(float fps) {
|
||||||
void GameController::loadState(int slot) {
|
void GameController::loadState(int slot) {
|
||||||
GBAThreadInterrupt(&m_threadContext);
|
GBAThreadInterrupt(&m_threadContext);
|
||||||
GBALoadState(m_threadContext.gba, m_threadContext.stateDir, slot);
|
GBALoadState(m_threadContext.gba, m_threadContext.stateDir, slot);
|
||||||
ConditionWake(&m_threadContext.sync.videoFrameAvailableCond); // Hack: wake up the drawing thread
|
|
||||||
GBAThreadContinue(&m_threadContext);
|
GBAThreadContinue(&m_threadContext);
|
||||||
emit stateLoaded(&m_threadContext);
|
emit stateLoaded(&m_threadContext);
|
||||||
emit frameAvailable(m_drawContext);
|
emit frameAvailable(m_drawContext);
|
||||||
|
|
Loading…
Reference in New Issue