GameSubscriber: read core state on the CPU thread

game.status, game.reset and version all read PSP_GetBootState(), g_paramSFO,
GetUIState() and PSP_CoreParameter() straight from the WebSocket thread, where
they race with a game being torn down or booted. Route them through
Core_RunOnCPUThread() like the other subscribers already do.

Part of removing the WebSocket debugger's lifecycleLock, which is currently what
stops these racing with teardown.

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 12:26:05 +02:00
1 parent 1019976f45
commit a59b5c6dd5
1 file changed
+37 -23
+37 -23
View File
@@ -31,6 +31,7 @@
#include "Common/System/System.h"
#include "Core/Config.h"
#include "Core/Core.h"
#include "Core/CoreParameter.h"
#include "Core/Debugger/WebSocket/GameSubscriber.h"
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
@@ -64,15 +65,21 @@ DebuggerSubscriber *WebSocketGameInit(DebuggerEventHandlerMap &map) {
//
// Response (same event name) with no extra data or error.
void WebSocketGameReset(DebuggerRequest &req) {
if (PSP_GetBootState() != BootState::Complete)
return req.Fail("Game not running");
bool needBreak = false;
if (!req.ParamBool("break", &needBreak, DebuggerParamType::OPTIONAL))
return;
if (needBreak)
PSP_CoreParameter().startBreak = true;
// Route the boot-state check and the startBreak write to the CPU thread instead of poking at
// them directly from this WebSocket handler thread - see Core_RunOnCPUThread() in Core.h.
bool running = false;
Core_RunOnCPUThread([&] {
running = PSP_GetBootState() == BootState::Complete;
if (running && needBreak)
PSP_CoreParameter().startBreak = true;
});
if (!running)
return req.Fail("Game not running");
// We can only support async resets here. A lot of the stuff in init must happen on the EmuThread,
// and we are not on it here.
@@ -92,17 +99,21 @@ void WebSocketGameReset(DebuggerRequest &req) {
// - title: string game title.
// - paused: boolean, true when gameplay is paused (not the same as stepping.)
void WebSocketGameStatus(DebuggerRequest &req) {
JsonWriter &json = req.Respond();
if (PSP_GetBootState() == BootState::Complete) {
json.pushDict("game");
json.writeString("id", g_paramSFO.GetDiscID());
json.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
json.writeString("title", g_paramSFO.GetValueString("TITLE"));
json.pop();
} else {
json.writeNull("game");
}
json.writeBool("paused", GetUIState() == UISTATE_PAUSEMENU);
// Route the boot state and param SFO reads to the CPU thread instead of poking at them directly
// from this WebSocket handler thread - see Core_RunOnCPUThread() in Core.h.
Core_RunOnCPUThread([&] {
JsonWriter &json = req.Respond();
if (PSP_GetBootState() == BootState::Complete) {
json.pushDict("game");
json.writeString("id", g_paramSFO.GetDiscID());
json.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
json.writeString("title", g_paramSFO.GetValueString("TITLE"));
json.pop();
} else {
json.writeNull("game");
}
json.writeBool("paused", GetUIState() == UISTATE_PAUSEMENU);
});
}
// Notify debugger version info (version)
@@ -121,8 +132,6 @@ void WebSocketGameStatus(DebuggerRequest &req) {
// meant to attach to. Ports aren't enough on their own: a leftover process may still be holding
// the one you asked for, and you'd never know you were driving the wrong emulator.
void WebSocketVersion(DebuggerRequest &req) {
JsonWriter &json = req.Respond();
std::string version = req.client->version;
if (!req.ParamString("version", &version, DebuggerParamType::OPTIONAL_LOOSE))
return;
@@ -133,14 +142,19 @@ void WebSocketVersion(DebuggerRequest &req) {
req.client->version = version;
req.client->name = name;
// fileToStart is CPU-thread-owned (PSP_Shutdown clears it), so read it over there - see
// Core_RunOnCPUThread() in Core.h. The rest is constant and safe to read here.
std::string path;
Core_RunOnCPUThread([&] {
path = PSP_CoreParameter().fileToStart.ToString();
});
JsonWriter &json = req.Respond();
json.writeString("name", "PPSSPP");
json.writeString("version", PPSSPP_GIT_VERSION);
json.writeUint("pid", GetOwnProcessID());
const Path &fileToStart = PSP_CoreParameter().fileToStart;
if (fileToStart.empty())
if (path.empty())
json.writeNull("path");
else
json.writeString("path", fileToStart.ToString());
json.writeString("path", path);
}