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: 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:

View File

@ -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<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) {

View File

@ -6,10 +6,10 @@
#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 @@ private:
QThread* m_audioThread;
AudioProcessor* m_audioProcessor;
QMutex m_pauseMutex;
bool m_pauseAfterFrame;
QAtomicInt m_pauseAfterFrame;
bool m_videoSync;
bool m_audioSync;