Merge pull request #4137 from aldelaro5/memCheck-crash-fix

Fix a crash when adding the first memory check while the game is running
This commit is contained in:
Scott Mansell 2016-09-07 14:19:19 +12:00 committed by GitHub
commit 7311cd8b6e
3 changed files with 18 additions and 3 deletions

View File

@ -171,7 +171,7 @@ void MemChecks::Add(const TMemCheck& _rMemoryCheck)
// If this is the first one, clear the JIT cache so it can switch to // If this is the first one, clear the JIT cache so it can switch to
// watchpoint-compatible code. // watchpoint-compatible code.
if (!had_any && jit) if (!had_any && jit)
jit->ClearCache(); jit->GetBlockCache()->SchedulateClearCacheThreadSafe();
} }
void MemChecks::Remove(u32 _Address) void MemChecks::Remove(u32 _Address)
@ -181,11 +181,11 @@ void MemChecks::Remove(u32 _Address)
if (i->StartAddress == _Address) if (i->StartAddress == _Address)
{ {
m_MemChecks.erase(i); m_MemChecks.erase(i);
if (!HasAny() && jit)
jit->GetBlockCache()->SchedulateClearCacheThreadSafe();
return; return;
} }
} }
if (!HasAny() && jit)
jit->ClearCache();
} }
TMemCheck* MemChecks::GetMemCheck(u32 address) TMemCheck* MemChecks::GetMemCheck(u32 address)

View File

@ -17,6 +17,7 @@
#include "Common/JitRegister.h" #include "Common/JitRegister.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/CoreTiming.h"
#include "Core/PowerPC/JitCommon/JitBase.h" #include "Core/PowerPC/JitCommon/JitBase.h"
#include "Core/PowerPC/JitInterface.h" #include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
@ -27,6 +28,13 @@
using namespace Gen; using namespace Gen;
static int s_clear_jit_cache_thread_safe;
static void ClearCacheThreadSafe(u64 userdata, s64 cyclesdata)
{
JitInterface::ClearCache();
}
bool JitBaseBlockCache::IsFull() const bool JitBaseBlockCache::IsFull() const
{ {
return GetNumBlocks() >= MAX_NUM_BLOCKS - 1; return GetNumBlocks() >= MAX_NUM_BLOCKS - 1;
@ -34,6 +42,7 @@ bool JitBaseBlockCache::IsFull() const
void JitBaseBlockCache::Init() void JitBaseBlockCache::Init()
{ {
s_clear_jit_cache_thread_safe = CoreTiming::RegisterEvent("clearJitCache", ClearCacheThreadSafe);
JitRegister::Init(SConfig::GetInstance().m_perfDir); JitRegister::Init(SConfig::GetInstance().m_perfDir);
iCache.fill(0); iCache.fill(0);
@ -73,6 +82,11 @@ void JitBaseBlockCache::Clear()
blocks[0].invalid = true; blocks[0].invalid = true;
} }
void JitBaseBlockCache::SchedulateClearCacheThreadSafe()
{
CoreTiming::ScheduleEvent(0, s_clear_jit_cache_thread_safe);
}
void JitBaseBlockCache::Reset() void JitBaseBlockCache::Reset()
{ {
Shutdown(); Shutdown();

View File

@ -159,6 +159,7 @@ public:
void FinalizeBlock(int block_num, bool block_link, const u8* code_ptr); void FinalizeBlock(int block_num, bool block_link, const u8* code_ptr);
void Clear(); void Clear();
void SchedulateClearCacheThreadSafe();
void Init(); void Init();
void Shutdown(); void Shutdown();
void Reset(); void Reset();