Bypass the PSP file system when calculating the savedata size to avoid a lock

This commit is contained in:
Henrik Rydgård 2024-11-29 14:43:13 +01:00
parent 6d2826dcb0
commit 7cbb60fd22
4 changed files with 22 additions and 9 deletions

View File

@ -130,10 +130,10 @@ bool ThreadManager::TeardownTask(Task *task, bool enqueue) {
static void WorkerThreadFunc(GlobalThreadContext *global, TaskThreadContext *thread) {
if (thread->type == TaskType::CPU_COMPUTE) {
snprintf(thread->name, sizeof(thread->name), "PoolWorker %d", thread->index);
snprintf(thread->name, sizeof(thread->name), "PoolW %d", thread->index);
} else {
_assert_(thread->type == TaskType::IO_BLOCKING);
snprintf(thread->name, sizeof(thread->name), "PoolWorkerIO %d", thread->index);
snprintf(thread->name, sizeof(thread->name), "PoolW IO %d", thread->index);
}
SetCurrentThreadName(thread->name);

View File

@ -675,8 +675,8 @@ void __IoInit() {
pspFileSystem.Mount("flash0:", flash0System);
const std::string gameId = g_paramSFO.GetDiscID();
if (g_RemasterMode) {
const std::string gameId = g_paramSFO.GetDiscID();
const Path exdataPath = GetSysDirectory(DIRECTORY_EXDATA) / gameId;
if (File::Exists(exdataPath)) {
auto exdataSystem = std::make_shared<DirectoryFileSystem>(&pspFileSystem, exdataPath, FileSystemFlags::SIMULATE_FAT32 | FileSystemFlags::CARD);
@ -698,7 +698,7 @@ void __IoInit() {
__KernelRegisterWaitTypeFuncs(WAITTYPE_ASYNCIO, __IoAsyncBeginCallback, __IoAsyncEndCallback);
MemoryStick_Init();
MemoryStick_Init(gameId);
lastMemStickState = MemoryStick_State();
lastMemStickFatState = MemoryStick_FatState();
__DisplayListenVblank(__IoVblank);

View File

@ -23,6 +23,8 @@
#include "Common/Serialize/Serializer.h"
#include "Common/Serialize/SerializeFuncs.h"
#include "Common/Thread/ThreadUtil.h"
#include "Common/File/DiskFree.h"
#include "Common/File/FileUtil.h"
#include "Core/Config.h"
#include "Core/CoreTiming.h"
#include "Core/Compatibility.h"
@ -158,7 +160,7 @@ void MemoryStick_SetState(MemStickState state) {
}
}
void MemoryStick_Init() {
void MemoryStick_Init(std::string gameID) {
if (g_Config.bMemStickInserted) {
memStickState = PSP_MEMORYSTICK_STATE_INSERTED;
memStickFatState = PSP_FAT_MEMORYSTICK_STATE_ASSIGNED;
@ -170,10 +172,19 @@ void MemoryStick_Init() {
memStickNeedsAssign = false;
const CompatFlags &flags = PSP_CoreParameter().compat.flags();
//if (flags.MemstickFixedFree) {
// See issue #12761
g_initialMemstickSizePromise = Promise<uint64_t>::Spawn(&g_threadManager, []() -> uint64_t {
INFO_LOG(Log::System, "Calculating initial savedata size...");
return pspFileSystem.FreeDiskSpace("ms0:/") + pspFileSystem.ComputeRecursiveDirectorySize("ms0:/PSP/SAVEDATA/");
g_initialMemstickSizePromise = Promise<uint64_t>::Spawn(&g_threadManager, [gameID]() -> uint64_t {
INFO_LOG(Log::System, "Calculating initial savedata size for %s...", gameID.c_str());
// NOTE: We only really need to sum up the diskspace for subfolders related to this game, and add it to the actual free space,
// to obtain the free space with the save data removed.
// We previously went through the meta file system here, but the memstick is always a directory so no need.
Path saveFolder = GetSysDirectory(DIRECTORY_SAVEDATA);
int64_t freeSpace = 0;
free_disk_space(saveFolder, freeSpace);
freeSpace += File::ComputeRecursiveDirectorySize(saveFolder);
return freeSpace;
}, TaskType::IO_BLOCKING);
}

View File

@ -17,6 +17,8 @@
#pragma once
#include <string>
#include "Common/CommonTypes.h"
class PointerWrap;
@ -40,7 +42,7 @@ enum MemStickDriverState {
PSP_MEMORYSTICK_STATE_DEVICE_REMOVED = 8,
};
void MemoryStick_Init();
void MemoryStick_Init(std::string gameID);
void MemoryStick_Shutdown();
void MemoryStick_DoState(PointerWrap &p);
MemStickState MemoryStick_State();