diff --git a/CHANGES b/CHANGES index ae0e96536..4a2de53ac 100644 --- a/CHANGES +++ b/CHANGES @@ -55,6 +55,7 @@ Misc: - Qt: Fix windows being resizable when they shouldn't have been - Qt: Only hide cursor in full screen - Perf: Ability to load savestates immediately on launch + - Qt: Replace pause-after-frame mutex with an atomic 0.2.1: (2015-05-13) Bugfixes: diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 042007183..0adf18c01 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -40,6 +40,7 @@ GameController::GameController(QObject* parent) , m_gameOpen(false) , m_audioThread(new QThread(this)) , m_audioProcessor(AudioProcessor::create()) + , m_pauseAfterFrame(false) , m_videoSync(VIDEO_SYNC) , m_audioSync(AUDIO_SYNC) , m_fpsTarget(-1) @@ -114,13 +115,10 @@ GameController::GameController(QObject* parent) m_threadContext.frameCallback = [] (GBAThread* context) { GameController* controller = static_cast(context->userData); - controller->m_pauseMutex.lock(); - if (controller->m_pauseAfterFrame) { + if (controller->m_pauseAfterFrame.testAndSetAcquire(true, false)) { GBAThreadPauseFromThread(context); - controller->m_pauseAfterFrame = false; controller->gamePaused(&controller->m_threadContext); } - controller->m_pauseMutex.unlock(); if (GBASyncDrawingFrame(&controller->m_threadContext.sync)) { controller->frameAvailable(controller->m_drawContext); } else { @@ -422,10 +420,9 @@ void GameController::frameAdvance() { if (m_rewindTimer.isActive()) { return; } - m_pauseMutex.lock(); - m_pauseAfterFrame = true; - setPaused(false); - m_pauseMutex.unlock(); + if (m_pauseAfterFrame.testAndSetRelaxed(false, true)) { + setPaused(false); + } } void GameController::setRewind(bool enable, int capacity, int interval) { diff --git a/src/platform/qt/GameController.h b/src/platform/qt/GameController.h index 176898d15..6848c6fd2 100644 --- a/src/platform/qt/GameController.h +++ b/src/platform/qt/GameController.h @@ -6,10 +6,10 @@ #ifndef QGBA_GAME_CONTROLLER #define QGBA_GAME_CONTROLLER +#include #include #include #include -#include #include #include @@ -177,8 +177,7 @@ private: QThread* m_audioThread; AudioProcessor* m_audioProcessor; - QMutex m_pauseMutex; - bool m_pauseAfterFrame; + QAtomicInt m_pauseAfterFrame; bool m_videoSync; bool m_audioSync;