Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9708 from JosJuice/dsp-volatile
DSP: Change external_interrupt_waiting from volatile to atomic
  • Loading branch information
lioncash committed May 14, 2021
2 parents 964fed7 + d173415 commit 41befc2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Core/DSP/DSPCore.cpp
Expand Up @@ -195,7 +195,7 @@ void SDSP::SetException(ExceptionType exception)

void SDSP::SetExternalInterrupt(bool val)
{
external_interrupt_waiting = val;
external_interrupt_waiting.store(val, std::memory_order_release);
}

void SDSP::CheckExternalInterrupt()
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/DSP/DSPCore.h
Expand Up @@ -420,7 +420,7 @@ struct SDSP

u8 reg_stack_ptrs[4]{};
u8 exceptions = 0; // pending exceptions
volatile bool external_interrupt_waiting = false;
std::atomic<bool> external_interrupt_waiting = false;
bool reset_dspjit_codespace = false;

// DSP hardware stacks. They're mapped to a bunch of registers, such that writes
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp
Expand Up @@ -69,10 +69,9 @@ int Interpreter::RunCyclesThread(int cycles)
if ((state.cr & CR_HALT) != 0)
return 0;

if (state.external_interrupt_waiting)
if (state.external_interrupt_waiting.exchange(false, std::memory_order_acquire))
{
m_dsp_core.CheckExternalInterrupt();
m_dsp_core.SetExternalInterrupt(false);
}

Step();
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp
Expand Up @@ -51,11 +51,10 @@ DSPEmitter::~DSPEmitter()

u16 DSPEmitter::RunCycles(u16 cycles)
{
if (m_dsp_core.DSPState().external_interrupt_waiting)
if (m_dsp_core.DSPState().external_interrupt_waiting.exchange(false, std::memory_order_acquire))
{
m_dsp_core.CheckExternalInterrupt();
m_dsp_core.CheckExceptions();
m_dsp_core.SetExternalInterrupt(false);
}

m_cycles_left = cycles;
Expand Down Expand Up @@ -489,6 +488,9 @@ Gen::OpArg DSPEmitter::M_SDSP_cr()

Gen::OpArg DSPEmitter::M_SDSP_external_interrupt_waiting()
{
static_assert(decltype(SDSP::external_interrupt_waiting)::is_always_lock_free &&
sizeof(SDSP::external_interrupt_waiting) == sizeof(u8));

return MDisp(R15, static_cast<int>(offsetof(SDSP, external_interrupt_waiting)));
}

Expand Down

0 comments on commit 41befc2

Please sign in to comment.