mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Io: Calculate memory stick size on a thread.
If you have a bunch of saves/states/etc. this might be a bit slow.
This commit is contained in:
parent
4c1ed81d45
commit
a3680ca3cb
@ -774,6 +774,7 @@ void __IoShutdown() {
|
||||
delete flash0System;
|
||||
flash0System = nullptr;
|
||||
|
||||
MemoryStick_Shutdown();
|
||||
memStickCallbacks.clear();
|
||||
memStickFatCallbacks.clear();
|
||||
}
|
||||
|
@ -16,6 +16,9 @@
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include <algorithm>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include "Common/Serialize/Serializer.h"
|
||||
#include "Common/Serialize/SerializeFuncs.h"
|
||||
#include "Core/CoreTiming.h"
|
||||
@ -31,8 +34,20 @@ static bool memStickNeedsAssign = false;
|
||||
static u64 memStickInsertedAt = 0;
|
||||
static uint64_t memstickInitialFree = 0;
|
||||
|
||||
const u64 normalMemstickSize = 9ULL * 1024 * 1024 * 1024;
|
||||
const u64 smallMemstickSize = 1ULL * 1024 * 1024 * 1024;
|
||||
enum FreeCalcStatus {
|
||||
NONE,
|
||||
RUNNING,
|
||||
DONE,
|
||||
CLEANED_UP,
|
||||
};
|
||||
|
||||
static std::thread freeCalcThread;
|
||||
static std::condition_variable freeCalcCond;
|
||||
static std::mutex freeCalcMutex;
|
||||
static FreeCalcStatus freeCalcStatus = FreeCalcStatus::NONE;
|
||||
|
||||
static const u64 normalMemstickSize = 9ULL * 1024 * 1024 * 1024;
|
||||
static const u64 smallMemstickSize = 1ULL * 1024 * 1024 * 1024;
|
||||
|
||||
void MemoryStick_DoState(PointerWrap &p) {
|
||||
auto s = p.Section("MemoryStick", 1, 5);
|
||||
@ -75,7 +90,31 @@ u64 MemoryStick_SectorSize() {
|
||||
return 32 * 1024; // 32KB
|
||||
}
|
||||
|
||||
static void MemoryStick_CalcInitialFree() {
|
||||
std::unique_lock<std::mutex> guard(freeCalcMutex);
|
||||
freeCalcStatus = FreeCalcStatus::RUNNING;
|
||||
freeCalcThread = std::thread([] {
|
||||
memstickInitialFree = pspFileSystem.FreeSpace("ms0:/") + pspFileSystem.getDirSize("ms0:/PSP/SAVEDATA/");
|
||||
|
||||
std::unique_lock<std::mutex> guard(freeCalcMutex);
|
||||
freeCalcStatus = FreeCalcStatus::DONE;
|
||||
freeCalcCond.notify_all();
|
||||
});
|
||||
}
|
||||
|
||||
static void MemoryStick_WaitInitialFree() {
|
||||
std::unique_lock<std::mutex> guard(freeCalcMutex);
|
||||
while (freeCalcStatus == FreeCalcStatus::RUNNING) {
|
||||
freeCalcCond.wait(guard);
|
||||
}
|
||||
if (freeCalcStatus == FreeCalcStatus::DONE)
|
||||
freeCalcThread.join();
|
||||
freeCalcStatus = FreeCalcStatus::CLEANED_UP;
|
||||
}
|
||||
|
||||
u64 MemoryStick_FreeSpace() {
|
||||
MemoryStick_WaitInitialFree();
|
||||
|
||||
const CompatFlags &flags = PSP_CoreParameter().compat.flags();
|
||||
u64 realFreeSpace = pspFileSystem.FreeSpace("ms0:/");
|
||||
|
||||
@ -135,5 +174,9 @@ void MemoryStick_Init() {
|
||||
}
|
||||
|
||||
memStickNeedsAssign = false;
|
||||
memstickInitialFree = pspFileSystem.FreeSpace("ms0:/") + pspFileSystem.getDirSize("ms0:/PSP/SAVEDATA/");
|
||||
MemoryStick_CalcInitialFree();
|
||||
}
|
||||
|
||||
void MemoryStick_Shutdown() {
|
||||
MemoryStick_WaitInitialFree();
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ enum MemStickDriverState {
|
||||
};
|
||||
|
||||
void MemoryStick_Init();
|
||||
void MemoryStick_Shutdown();
|
||||
void MemoryStick_DoState(PointerWrap &p);
|
||||
MemStickState MemoryStick_State();
|
||||
MemStickFatState MemoryStick_FatState();
|
||||
|
Loading…
Reference in New Issue
Block a user