Stop a second copy of the game before the shader prewarm, not after it.

The one-game-per-profile lock was taken at the first storage use, after the boot prewarm. A second copy started
while the game ran (a second Play, a shortcut) spent 14 to 30 s translating and building on every core and committed
about 10.9 GB before it ended with "another copy of the game is running", enough to bring a 48 GB machine to its
commit limit and stall the copy being played. rt_boot now takes the lock first; storage_init takes it again, which
plat_lock_file answers from the handle it already holds. A restart from the settings menu is unaffected: main waits
for the previous process to exit before rt_boot.
This commit is contained in:
Sebastian Choperena
2026-11-09 12:33:10 -05:00
committed by chrg6
parent 9bba578e58
commit 59069502f3
3 changed files with 16 additions and 5 deletions

View File

@@ -619,19 +619,27 @@ static uint32_t save_commit(void) {
}
// ---- storage roots
static void storage_init(void *param) {
(void)param;
// One game per profile: a second one's start would take the first one's commit in progress for an interrupted one
// and delete it, and both would write into one working copy (save-tx/work), losing or mixing their saves. rt_boot
// takes the lock before the shader prewarm, so a second copy ends at once instead of after the prewarm's seconds of
// work on every core and the gigabytes of memory it commits; storage_init takes it again (plat_lock_file keeps one
// handle per path, so the second call holds it already).
void fs_host_lock_profile(void) {
if (!*profile)
need(snprintf(profile, sizeof profile, "%s", rt_config()->profile) < (int)sizeof profile, "profile path");
uint64_t uid[2];
char p[PATH_CAP];
make_dirs(profile);
// One game per profile: a second one's start would take the first one's commit in progress for an interrupted
// one and delete it, and both would write into one working copy (save-tx/work), losing or mixing their saves.
snprintf(p, sizeof p, "%s/instance.lock", profile);
int held = plat_lock_file(p);
if (!held) rt_fatal("fs: another copy of the game is running with the profile %s; close it first", profile);
if (held < 0) rt_log("fs: cannot make %s; a second copy of the game would not be stopped", p);
}
static void storage_init(void *param) {
(void)param;
uint64_t uid[2];
char p[PATH_CAP];
fs_host_lock_profile();
account_uid(uid);
snprintf(p, sizeof p, "%s/save", profile);
make_dirs(p);