diff --git a/pcsx2/System/SysThreadBase.cpp b/pcsx2/System/SysThreadBase.cpp index a92f9836e4..3845b2c889 100644 --- a/pcsx2/System/SysThreadBase.cpp +++ b/pcsx2/System/SysThreadBase.cpp @@ -91,7 +91,7 @@ void SysThreadBase::Suspend( bool isBlocking ) { ScopedLock locker( m_ExecModeMutex ); - switch( m_ExecMode ) + switch( m_ExecMode.load() ) { // Invalid thread state, nothing to suspend case ExecMode_NoThreadYet: @@ -196,7 +196,7 @@ void SysThreadBase::Resume() // sanity checks against m_ExecMode/m_Running status, and if something doesn't feel // right, we should abort; the user may have canceled the action before it even finished. - switch( m_ExecMode ) + switch( m_ExecMode.load() ) { case ExecMode_Opened: return; @@ -267,7 +267,7 @@ void SysThreadBase::OnResumeInThread( bool isSuspended ) {} // continued execution unimpeded. bool SysThreadBase::StateCheckInThread() { - switch( m_ExecMode ) + switch( m_ExecMode.load() ) { #ifdef PCSX2_DEVBUILD // optimize out handlers for these cases in release builds. diff --git a/pcsx2/System/SysThreads.h b/pcsx2/System/SysThreads.h index 853ad4d735..caead7ba25 100644 --- a/pcsx2/System/SysThreads.h +++ b/pcsx2/System/SysThreads.h @@ -63,7 +63,7 @@ public: }; protected: - volatile ExecutionMode m_ExecMode; + std::atomic m_ExecMode; // This lock is used to avoid simultaneous requests to Suspend/Resume/Pause from // contending threads. @@ -71,7 +71,7 @@ protected: // Used to wake up the thread from sleeping when it's in a suspended state. Semaphore m_sem_Resume; - + // Used to synchronize inline changes from paused to suspended status. Semaphore m_sem_ChangingExecMode; @@ -79,7 +79,7 @@ protected: // Issue a Wait against this mutex for performing actions that require the thread // to be suspended. Mutex m_RunningLock; - + public: explicit SysThreadBase(); virtual ~SysThreadBase() throw(); @@ -99,7 +99,7 @@ public: bool IsClosing() const { - return !IsRunning() || (m_ExecMode <= ExecMode_Closed) || (m_ExecMode == ExecMode_Closing); + return !IsRunning() || (m_ExecMode <= ExecMode_Closed) || (m_ExecMode == ExecMode_Closing); } bool HasPendingStateChangeRequest() const @@ -107,7 +107,7 @@ public: return m_ExecMode >= ExecMode_Closing; } - ExecutionMode GetExecutionMode() const { return m_ExecMode; } + ExecutionMode GetExecutionMode() const { return m_ExecMode.load(); } Mutex& ExecutionModeMutex() { return m_ExecModeMutex; } virtual void Suspend( bool isBlocking = true ); @@ -172,10 +172,10 @@ protected: // true anytime between plugins being initialized and plugins being shutdown. Gets // set false when plugins are shutdown, the corethread is canceled, or when an error // occurs while trying to upload a new state into the VM. - volatile bool m_hasActiveMachine; + std::atomic m_hasActiveMachine; wxString m_elf_override; - + SSE_MXCSR m_mxcsr_saved; public: @@ -198,10 +198,10 @@ public: virtual void UploadStateCopy( const VmStateBuffer& copy ); virtual bool HasActiveMachine() const { return m_hasActiveMachine; } - + virtual const wxString& GetElfOverride() const { return m_elf_override; } virtual void SetElfOverride( const wxString& elf ); - + protected: void _reset_stuff_as_needed();