Qt: Replace pause-after-frame mutex with an atomic

This commit is contained in:
Jeffrey Pfau 2015-06-01 23:55:44 -07:00
parent 3af3fab3cf
commit a51066820a
3 changed files with 8 additions and 11 deletions

View File

@ -55,6 +55,7 @@ Misc:
- Qt: Fix windows being resizable when they shouldn't have been - Qt: Fix windows being resizable when they shouldn't have been
- Qt: Only hide cursor in full screen - Qt: Only hide cursor in full screen
- Perf: Ability to load savestates immediately on launch - Perf: Ability to load savestates immediately on launch
- Qt: Replace pause-after-frame mutex with an atomic
0.2.1: (2015-05-13) 0.2.1: (2015-05-13)
Bugfixes: Bugfixes:

View File

@ -40,6 +40,7 @@ GameController::GameController(QObject* parent)
, m_gameOpen(false) , m_gameOpen(false)
, m_audioThread(new QThread(this)) , m_audioThread(new QThread(this))
, m_audioProcessor(AudioProcessor::create()) , m_audioProcessor(AudioProcessor::create())
, m_pauseAfterFrame(false)
, m_videoSync(VIDEO_SYNC) , m_videoSync(VIDEO_SYNC)
, m_audioSync(AUDIO_SYNC) , m_audioSync(AUDIO_SYNC)
, m_fpsTarget(-1) , m_fpsTarget(-1)
@ -114,13 +115,10 @@ GameController::GameController(QObject* parent)
m_threadContext.frameCallback = [] (GBAThread* context) { m_threadContext.frameCallback = [] (GBAThread* context) {
GameController* controller = static_cast<GameController*>(context->userData); GameController* controller = static_cast<GameController*>(context->userData);
controller->m_pauseMutex.lock(); if (controller->m_pauseAfterFrame.testAndSetAcquire(true, false)) {
if (controller->m_pauseAfterFrame) {
GBAThreadPauseFromThread(context); GBAThreadPauseFromThread(context);
controller->m_pauseAfterFrame = false;
controller->gamePaused(&controller->m_threadContext); controller->gamePaused(&controller->m_threadContext);
} }
controller->m_pauseMutex.unlock();
if (GBASyncDrawingFrame(&controller->m_threadContext.sync)) { if (GBASyncDrawingFrame(&controller->m_threadContext.sync)) {
controller->frameAvailable(controller->m_drawContext); controller->frameAvailable(controller->m_drawContext);
} else { } else {
@ -422,10 +420,9 @@ void GameController::frameAdvance() {
if (m_rewindTimer.isActive()) { if (m_rewindTimer.isActive()) {
return; return;
} }
m_pauseMutex.lock(); if (m_pauseAfterFrame.testAndSetRelaxed(false, true)) {
m_pauseAfterFrame = true; setPaused(false);
setPaused(false); }
m_pauseMutex.unlock();
} }
void GameController::setRewind(bool enable, int capacity, int interval) { void GameController::setRewind(bool enable, int capacity, int interval) {

View File

@ -6,10 +6,10 @@
#ifndef QGBA_GAME_CONTROLLER #ifndef QGBA_GAME_CONTROLLER
#define QGBA_GAME_CONTROLLER #define QGBA_GAME_CONTROLLER
#include <QAtomicInt>
#include <QFile> #include <QFile>
#include <QImage> #include <QImage>
#include <QObject> #include <QObject>
#include <QMutex>
#include <QString> #include <QString>
#include <QTimer> #include <QTimer>
@ -177,8 +177,7 @@ private:
QThread* m_audioThread; QThread* m_audioThread;
AudioProcessor* m_audioProcessor; AudioProcessor* m_audioProcessor;
QMutex m_pauseMutex; QAtomicInt m_pauseAfterFrame;
bool m_pauseAfterFrame;
bool m_videoSync; bool m_videoSync;
bool m_audioSync; bool m_audioSync;