diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index 78e7b53f28..76d25aa088 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -142,7 +142,8 @@ bool BootCore(std::unique_ptr boot, const WindowSystemInfo& wsi) if (!boot->riivolution_patches.empty()) Config::SetCurrent(Config::MAIN_FAST_DISC_SPEED, true); - Core::System::GetInstance().Initialize(); + auto& system = Core::System::GetInstance(); + system.Initialize(); Core::UpdateWantDeterminism(/*initial*/ true); @@ -173,13 +174,14 @@ bool BootCore(std::unique_ptr boot, const WindowSystemInfo& wsi) if (load_ipl) { return Core::Init( + system, std::make_unique( BootParameters::IPL{StartUp.m_region, std::move(std::get(boot->parameters))}, std::move(boot->boot_session_data)), wsi); } - return Core::Init(std::move(boot), wsi); + return Core::Init(system, std::move(boot), wsi); } // SYSCONF can be modified during emulation by the user and internally, which makes it diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index f6cbb10d4a..85b6e98e19 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -134,7 +135,8 @@ static thread_local bool tls_is_cpu_thread = false; static thread_local bool tls_is_gpu_thread = false; static thread_local bool tls_is_host_thread = false; -static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi); +static void EmuThread(Core::System& system, std::unique_ptr boot, + WindowSystemInfo wsi); static Common::EventHook s_frame_presented = AfterPresentEvent::Register( [](auto& present_info) { @@ -239,7 +241,7 @@ bool WantsDeterminism() // This is called from the GUI thread. See the booting call schedule in // BootManager.cpp -bool Init(std::unique_ptr boot, const WindowSystemInfo& wsi) +bool Init(Core::System& system, std::unique_ptr boot, const WindowSystemInfo& wsi) { if (s_emu_thread.joinable()) { @@ -257,8 +259,7 @@ bool Init(std::unique_ptr boot, const WindowSystemInfo& wsi) HostDispatchJobs(); INFO_LOG_FMT(BOOT, "Starting core = {} mode", SConfig::GetInstance().bWii ? "Wii" : "GameCube"); - INFO_LOG_FMT(BOOT, "CPU Thread separate = {}", - Core::System::GetInstance().IsDualCoreMode() ? "Yes" : "No"); + INFO_LOG_FMT(BOOT, "CPU Thread separate = {}", system.IsDualCoreMode() ? "Yes" : "No"); Host_UpdateMainFrame(); // Disable any menus or buttons at boot @@ -271,7 +272,7 @@ bool Init(std::unique_ptr boot, const WindowSystemInfo& wsi) // Start the emu thread s_is_booting.Set(); - s_emu_thread = std::thread(EmuThread, std::move(boot), prepared_wsi); + s_emu_thread = std::thread(EmuThread, std::ref(system), std::move(boot), prepared_wsi); return true; } @@ -371,11 +372,12 @@ static void CPUSetInitialExecutionState(bool force_paused = false) } // Create the CPU thread, which is a CPU + Video thread in Single Core mode. -static void CpuThread(const std::optional& savestate_path, bool delete_savestate) +static void CpuThread(Core::System& system, const std::optional& savestate_path, + bool delete_savestate) { DeclareAsCPUThread(); - if (Core::System::GetInstance().IsDualCoreMode()) + if (system.IsDualCoreMode()) Common::SetCurrentThreadName("CPU thread"); else Common::SetCurrentThreadName("CPU-GPU thread"); @@ -434,7 +436,6 @@ static void CpuThread(const std::optional& savestate_path, bool del } // Enter CPU run loop. When we leave it - we are done. - auto& system = Core::System::GetInstance(); system.GetCPU().Run(); #ifdef USE_MEMORYWATCHER @@ -454,12 +455,11 @@ static void CpuThread(const std::optional& savestate_path, bool del } } -static void FifoPlayerThread(const std::optional& savestate_path, +static void FifoPlayerThread(Core::System& system, const std::optional& savestate_path, bool delete_savestate) { DeclareAsCPUThread(); - auto& system = Core::System::GetInstance(); if (system.IsDualCoreMode()) Common::SetCurrentThreadName("FIFO player thread"); else @@ -490,9 +490,9 @@ static void FifoPlayerThread(const std::optional& savestate_path, // Initialize and create emulation thread // Call browser: Init():s_emu_thread(). // See the BootManager.cpp file description for a complete call schedule. -static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi) +static void EmuThread(Core::System& system, std::unique_ptr boot, + WindowSystemInfo wsi) { - Core::System& system = Core::System::GetInstance(); const SConfig& core_parameter = SConfig::GetInstance(); CallOnStateChangedCallbacks(State::Starting); Common::ScopeGuard flag_guard{[] { @@ -630,7 +630,8 @@ static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi system.GetPowerPC().SetMode(PowerPC::CoreMode::Interpreter); // Determine the CPU thread function - void (*cpuThreadFunc)(const std::optional& savestate_path, bool delete_savestate); + void (*cpuThreadFunc)(Core::System & system, const std::optional& savestate_path, + bool delete_savestate); if (std::holds_alternative(boot->parameters)) cpuThreadFunc = FifoPlayerThread; else @@ -684,7 +685,8 @@ static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi Common::FPU::LoadDefaultSIMDState(); // Spawn the CPU thread. The CPU thread will signal the event that boot is complete. - s_cpu_thread = std::thread(cpuThreadFunc, savestate_path, delete_savestate); + s_cpu_thread = + std::thread(cpuThreadFunc, std::ref(system), std::ref(savestate_path), delete_savestate); // become the GPU thread system.GetFifo().RunGpuLoop(); @@ -703,7 +705,7 @@ static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi else // SingleCore mode { // Become the CPU thread - cpuThreadFunc(savestate_path, delete_savestate); + cpuThreadFunc(system, savestate_path, delete_savestate); } INFO_LOG_FMT(CONSOLE, "{}", StopMessage(true, "Stopping GDB ...")); diff --git a/Source/Core/Core/Core.h b/Source/Core/Core/Core.h index d8c5c9a0da..90346d2cac 100644 --- a/Source/Core/Core/Core.h +++ b/Source/Core/Core/Core.h @@ -124,7 +124,7 @@ private: bool m_was_unpaused = false; }; -bool Init(std::unique_ptr boot, const WindowSystemInfo& wsi); +bool Init(Core::System& system, std::unique_ptr boot, const WindowSystemInfo& wsi); void Stop(); void Shutdown();