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);
|
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>
|
template <typename T>
|
||||||
void Do(T& x)
|
void Do(T& x)
|
||||||
{
|
{
|
||||||
|
@ -34,12 +34,13 @@
|
|||||||
#include "Core/HW/DSPLLE/DSPSymbols.h"
|
#include "Core/HW/DSPLLE/DSPSymbols.h"
|
||||||
|
|
||||||
DSPLLE::DSPLLE()
|
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;
|
static Common::Event dspEvent;
|
||||||
@ -93,12 +94,7 @@ void DSPLLE::DSPThread(DSPLLE* dsp_lle)
|
|||||||
|
|
||||||
while (dsp_lle->m_bIsRunning.IsSet())
|
while (dsp_lle->m_bIsRunning.IsSet())
|
||||||
{
|
{
|
||||||
int cycles = 0;
|
const int cycles = static_cast<int>(dsp_lle->m_cycle_count.load());
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lk(dsp_lle->m_csDSPCycleCountActive);
|
|
||||||
cycles = (int)dsp_lle->m_cycle_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cycles > 0)
|
if (cycles > 0)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> dsp_thread_lock(dsp_lle->m_csDSPThreadActive);
|
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);
|
DSPInterpreter::RunCyclesThread(cycles);
|
||||||
}
|
}
|
||||||
{
|
dsp_lle->m_cycle_count.store(0);
|
||||||
std::lock_guard<std::mutex> cycle_count_lock(dsp_lle->m_csDSPCycleCountActive);
|
|
||||||
dsp_lle->m_cycle_count = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
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.
|
// Wait for DSP thread to complete its cycle. Note: this logic should be thought through.
|
||||||
ppcEvent.Wait();
|
ppcEvent.Wait();
|
||||||
{
|
m_cycle_count.fetch_add(dsp_cycles);
|
||||||
std::lock_guard<std::mutex> lk(m_csDSPCycleCountActive);
|
|
||||||
m_cycle_count += dsp_cycles;
|
|
||||||
}
|
|
||||||
dspEvent.Set();
|
dspEvent.Set();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
#include "Common/Thread.h"
|
#include "Common/Thread.h"
|
||||||
|
|
||||||
#include "Core/DSPEmulator.h"
|
#include "Core/DSPEmulator.h"
|
||||||
@ -36,9 +38,8 @@ private:
|
|||||||
|
|
||||||
std::thread m_hDSPThread;
|
std::thread m_hDSPThread;
|
||||||
std::mutex m_csDSPThreadActive;
|
std::mutex m_csDSPThreadActive;
|
||||||
std::mutex m_csDSPCycleCountActive;
|
|
||||||
bool m_bWii;
|
bool m_bWii;
|
||||||
bool m_bDSPThread;
|
bool m_bDSPThread;
|
||||||
Common::Flag m_bIsRunning;
|
Common::Flag m_bIsRunning;
|
||||||
u32 m_cycle_count;
|
std::atomic<u32> m_cycle_count;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user