Lifecycle: drain asynchronous boot before shutdown

Join the loader before dismantling guest memory, filesystems or graphics state. A failed loader has already shut down the CPU, so skip duplicate cleanup and still complete lifecycle teardown. Clear libretro pending boot and deferred state buffers on unload/reset. This drains an in-progress load; it does not interrupt a blocking backend read.
This commit is contained in:
Codex authored and libretroadmin committed 2026-10-09 14:56:01 +02:00
1 parent ac0585439d
commit 2ac075c3dd
2 files changed
+22 -4

No files matched your search

+13 -4
View File
@@ -855,17 +855,25 @@ BootState PollBootState() {
}
void PSP_Shutdown(bool success) {
// Only the lifecycle owner calls this; the loader uses CPU_Shutdown on
// failure. Finish its accesses before destroying memory or filesystem state.
if (g_loadingThread.joinable()) {
g_loadingThread.join();
Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE);
}
// Do nothing if we never inited.
if (GetBootState() == BootState::Off) {
ERROR_LOG(Log::Loader, "Unexpected PSP_Shutdown");
return;
}
_assert_(GetBootState() != BootState::Failed);
// A failed loader already shut its CPU state down. Do not do that twice.
const bool cpuInitialized = GetBootState() != BootState::Failed;
Core_Stop();
if (g_Config.bFuncHashMap) {
if (cpuInitialized && g_Config.bFuncHashMap) {
MIPSAnalyst::StoreHashMap();
}
@@ -876,7 +884,8 @@ void PSP_Shutdown(bool success) {
Core_NotifyLifecycle(CoreLifecycle::STOPPING);
CPU_Shutdown(success);
if (cpuInitialized)
CPU_Shutdown(success);
GPU_Shutdown();
g_paramSFO.Clear();
g_paramSFORaw.Clear();
@@ -890,7 +899,7 @@ void PSP_Shutdown(bool success) {
Core_NotifyLifecycle(CoreLifecycle::STOPPED);
if (success) {
if (success || !cpuInitialized) {
SetBootState(BootState::Off);
}
+9
View File
@@ -1532,6 +1532,11 @@ void retro_unload_game(void) {
}
PSP_Shutdown(true);
g_pendingBoot = false;
g_bootErrorString.clear();
free(unserialize_data);
unserialize_data = nullptr;
unserialize_size = 0;
g_VFS.Clear();
delete ctx;
@@ -1546,6 +1551,10 @@ void retro_reset(void) {
Libretro::EmuThreadStop();
PSP_Shutdown(true);
g_pendingBoot = false;
free(unserialize_data);
unserialize_data = nullptr;
unserialize_size = 0;
if (BootState::Complete != PSP_Init(PSP_CoreParameter(), &g_bootErrorString)) {
ERROR_LOG(Log::Boot, "%s", g_bootErrorString.c_str());