Add a thread safe variant of invalidating the icache

This is used by the next commit.
This commit is contained in:
aldelaro5 2016-08-23 00:27:49 -04:00
parent f1964f90d6
commit 47d1b07abb
2 changed files with 20 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/CoreTiming.h"
#include "Core/HW/CPU.h" #include "Core/HW/CPU.h"
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/HW/SystemTimers.h" #include "Core/HW/SystemTimers.h"
@ -35,6 +36,12 @@ BreakPoints breakpoints;
MemChecks memchecks; MemChecks memchecks;
PPCDebugInterface debug_interface; PPCDebugInterface debug_interface;
static int s_invalidate_cache_thread_safe;
static void InvalidateCacheThreadSafe(u64 userdata, s64 cyclesLate)
{
ppcState.iCache.Invalidate(static_cast<u32>(userdata));
}
u32 CompactCR() u32 CompactCR()
{ {
u32 new_cr = 0; u32 new_cr = 0;
@ -117,6 +124,9 @@ void Init(int cpu_core)
// Changing the rounding mode has a limited effect. // Changing the rounding mode has a limited effect.
FPURoundMode::SetPrecisionMode(FPURoundMode::PREC_53); FPURoundMode::SetPrecisionMode(FPURoundMode::PREC_53);
s_invalidate_cache_thread_safe =
CoreTiming::RegisterEvent("invalidateEmulatedCache", InvalidateCacheThreadSafe);
memset(ppcState.sr, 0, sizeof(ppcState.sr)); memset(ppcState.sr, 0, sizeof(ppcState.sr));
ppcState.pagetable_base = 0; ppcState.pagetable_base = 0;
ppcState.pagetable_hashmask = 0; ppcState.pagetable_hashmask = 0;
@ -173,6 +183,15 @@ void Init(int cpu_core)
breakpoints.ClearAllTemporary(); breakpoints.ClearAllTemporary();
} }
void ScheduleInvalidateCacheThreadSafe(u32 address)
{
if (CPU::GetState() == CPU::State::CPU_RUNNING)
CoreTiming::ScheduleEvent(0, s_invalidate_cache_thread_safe, address,
CoreTiming::FromThread::NON_CPU);
else
PowerPC::ppcState.iCache.Invalidate(static_cast<u32>(address));
}
void Shutdown() void Shutdown()
{ {
InjectExternalCPUCore(nullptr); InjectExternalCPUCore(nullptr);

View File

@ -138,6 +138,7 @@ extern PPCDebugInterface debug_interface;
void Init(int cpu_core); void Init(int cpu_core);
void Shutdown(); void Shutdown();
void DoState(PointerWrap& p); void DoState(PointerWrap& p);
void ScheduleInvalidateCacheThreadSafe(u32 address);
CoreMode GetMode(); CoreMode GetMode();
// [NOT THREADSAFE] CPU Thread or CPU::PauseAndLock or CORE_UNINITIALIZED // [NOT THREADSAFE] CPU Thread or CPU::PauseAndLock or CORE_UNINITIALIZED