Rename Memory::Lock() to Core_LockAgainstShutdown(), move it to Core

It stopped being about memory when CPU_Shutdown started holding it across the
whole teardown - it's what keeps kernel objects, the symbol map and the memory
map from being freed while another thread reads them. The old name invited the
reading that it locks memory *access*, which it has never done.

Memory::Reinit() now holds it across both halves rather than relying on
Memory::Shutdown()'s own acquire: between Shutdown() and Init() there is no
memory map at all, and a reader could slip into that gap.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
This commit is contained in:
Henrik RydgårdandClaude Opus 5 committed 2026-08-17 13:11:16 +02:00
1 parent f57a102027
commit 75ff0d406c
16 files changed
+76 -66

No files matched your search

+6 -6
View File
@@ -261,7 +261,7 @@ void CtrlThreadList::reloadThreads()
// while it's actually touching that state. See g_frameMutex in Core.h.
{
std::lock_guard<std::mutex> frameGuard(g_frameMutex);
Memory::MemoryInitedLock memLock = Memory::Lock();
CoreShutdownLock coreLock = Core_LockAgainstShutdown();
threads = GetThreadsInfo();
}
Update();
@@ -337,7 +337,7 @@ void CtrlBreakpointList::reloadBreakpoints()
// with the CPU thread - see g_frameMutex in Core.h.
{
std::lock_guard<std::mutex> frameGuard(g_frameMutex);
Memory::MemoryInitedLock memLock = Memory::Lock();
CoreShutdownLock coreLock = Core_LockAgainstShutdown();
displayedBreakPoints_ = g_breakpoints.GetBreakpoints();
displayedMemChecks_= g_breakpoints.GetMemChecks();
}
@@ -750,9 +750,9 @@ void CtrlStackTraceView::loadStackTrace() {
// the CPU thread - hold g_frameMutex for the duration of the read, which NativeFrame() also
// holds while it's actually touching that state. See g_frameMutex in Core.h.
//
// g_frameMutex first, then Memory::Lock() - never the other way around. See CtrlMemView::onPaint.
// g_frameMutex first, then Core_LockAgainstShutdown() - never the other way around. See CtrlMemView::onPaint.
std::lock_guard<std::mutex> frameGuard(g_frameMutex);
Memory::MemoryInitedLock memLock = Memory::Lock();
CoreShutdownLock coreLock = Core_LockAgainstShutdown();
if (!PSP_IsInited())
return;
@@ -848,7 +848,7 @@ void CtrlModuleList::loadModules()
// actually touching that state. See g_frameMutex in Core.h.
{
std::lock_guard<std::mutex> frameGuard(g_frameMutex);
Memory::MemoryInitedLock memLock = Memory::Lock();
CoreShutdownLock coreLock = Core_LockAgainstShutdown();
if (g_symbolMap) {
modules = g_symbolMap->getAllModules();
} else {
@@ -874,7 +874,7 @@ void CtrlWatchList::RefreshValues() {
// otherwise race with the CPU thread - hold g_frameMutex for the duration, which NativeFrame()
// also holds while it's actually touching that state. See g_frameMutex in Core.h.
std::lock_guard<std::mutex> frameGuard(g_frameMutex);
Memory::MemoryInitedLock memLock = Memory::Lock();
CoreShutdownLock coreLock = Core_LockAgainstShutdown();
int steppingCounter = Core_GetSteppingCounter();
int changes = false;