mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Made cycle count atomic to avoid using a mutex
This commit is contained in:
parent
6b6b5ed37f
commit
4051da75e4
@ -181,6 +181,15 @@ public:
|
||||
flag.Set(s);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Do(std::atomic<T>& atomic)
|
||||
{
|
||||
T temp = atomic.load();
|
||||
Do(temp);
|
||||
if (mode == MODE_READ)
|
||||
atomic.store(temp);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Do(T& x)
|
||||
{
|
||||
|
@ -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<std::mutex> 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<std::mutex> lk(dsp_lle->m_csDSPCycleCountActive);
|
||||
cycles = (int)dsp_lle->m_cycle_count;
|
||||
}
|
||||
|
||||
const int cycles = static_cast<int>(dsp_lle->m_cycle_count.load());
|
||||
if (cycles > 0)
|
||||
{
|
||||
std::lock_guard<std::mutex> dsp_thread_lock(dsp_lle->m_csDSPThreadActive);
|
||||
@ -110,10 +106,7 @@ void DSPLLE::DSPThread(DSPLLE* dsp_lle)
|
||||
{
|
||||
DSPInterpreter::RunCyclesThread(cycles);
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> cycle_count_lock(dsp_lle->m_csDSPCycleCountActive);
|
||||
dsp_lle->m_cycle_count = 0;
|
||||
}
|
||||
dsp_lle->m_cycle_count.store(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -345,10 +338,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<std::mutex> lk(m_csDSPCycleCountActive);
|
||||
m_cycle_count += dsp_cycles;
|
||||
}
|
||||
m_cycle_count.fetch_add(dsp_cycles);
|
||||
dspEvent.Set();
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#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<u32> m_cycle_count;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user