diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h index a0c1fe662a..63ada504f4 100644 --- a/Source/Core/Common/ChunkFile.h +++ b/Source/Core/Common/ChunkFile.h @@ -181,6 +181,15 @@ public: flag.Set(s); } + template + void Do(std::atomic& atomic) + { + T temp = atomic.load(); + Do(temp); + if (mode == MODE_READ) + atomic.store(temp); + } + template void Do(T& x) { diff --git a/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp b/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp index 6d0d336bc9..24402c21cd 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp +++ b/Source/Core/Core/HW/DSPLLE/DSPLLE.cpp @@ -34,12 +34,13 @@ #include "Core/HW/DSPLLE/DSPSymbols.h" DSPLLE::DSPLLE() + : m_hDSPThread() + , m_csDSPThreadActive() + , m_bWii(false) + , m_bDSPThread(false) + , m_bIsRunning(false) + , m_cycle_count(0) { - m_bIsRunning.Clear(); - { - std::lock_guard lk(m_csDSPCycleCountActive); - m_cycle_count = 0; - } } static Common::Event dspEvent; @@ -93,12 +94,7 @@ void DSPLLE::DSPThread(DSPLLE* dsp_lle) while (dsp_lle->m_bIsRunning.IsSet()) { - int cycles = 0; - { - std::lock_guard lk(dsp_lle->m_csDSPCycleCountActive); - cycles = (int)dsp_lle->m_cycle_count; - } - + const int cycles = static_cast(dsp_lle->m_cycle_count.load()); if (cycles > 0) { std::lock_guard dsp_thread_lock(dsp_lle->m_csDSPThreadActive); @@ -110,10 +106,7 @@ void DSPLLE::DSPThread(DSPLLE* dsp_lle) { DSPInterpreter::RunCyclesThread(cycles); } - { - std::lock_guard cycle_count_lock(dsp_lle->m_csDSPCycleCountActive); - dsp_lle->m_cycle_count = 0; - } + dsp_lle->m_cycle_count.store(0); } else { @@ -344,10 +337,7 @@ void DSPLLE::DSP_Update(int cycles) { // Wait for DSP thread to complete its cycle. Note: this logic should be thought through. ppcEvent.Wait(); - { - std::lock_guard lk(m_csDSPCycleCountActive); - m_cycle_count += dsp_cycles; - } + m_cycle_count.fetch_add(dsp_cycles); dspEvent.Set(); } } diff --git a/Source/Core/Core/HW/DSPLLE/DSPLLE.h b/Source/Core/Core/HW/DSPLLE/DSPLLE.h index a25d0850cf..39b9e26adc 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPLLE.h +++ b/Source/Core/Core/HW/DSPLLE/DSPLLE.h @@ -4,6 +4,8 @@ #pragma once +#include + #include "Common/Thread.h" #include "Core/DSPEmulator.h" @@ -36,9 +38,8 @@ private: std::thread m_hDSPThread; std::mutex m_csDSPThreadActive; - std::mutex m_csDSPCycleCountActive; bool m_bWii; bool m_bDSPThread; Common::Flag m_bIsRunning; - u32 m_cycle_count; + std::atomic m_cycle_count; };