Qt: Replace pause-after-frame mutex with an atomic
Jeffrey Pfau jeffrey@endrift.com
Mon, 01 Jun 2015 23:55:44 -0700
3 files changed,
8 insertions(+),
11 deletions(-)
M
CHANGES
→
CHANGES
@@ -55,6 +55,7 @@ - Qt: Unified file opening and saving with last location
- 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:
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -40,6 +40,7 @@ , m_logLevels(0)
, 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 @@ };
m_threadContext.frameCallback = [] (GBAThread* context) { GameController* controller = static_cast<GameController*>(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) {
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -6,10 +6,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef QGBA_GAME_CONTROLLER #define QGBA_GAME_CONTROLLER +#include <QAtomicInt> #include <QFile> #include <QImage> #include <QObject> -#include <QMutex> #include <QString> #include <QTimer>@@ -177,8 +177,7 @@
QThread* m_audioThread; AudioProcessor* m_audioProcessor; - QMutex m_pauseMutex; - bool m_pauseAfterFrame; + QAtomicInt m_pauseAfterFrame; bool m_videoSync; bool m_audioSync;