Refactor placeholder cacheing
This commit is contained in:
@@ -24,53 +24,56 @@
|
||||
namespace sts::ncm::impl {
|
||||
|
||||
class PlaceHolderAccessor {
|
||||
public:
|
||||
private:
|
||||
class CacheEntry {
|
||||
public:
|
||||
PlaceHolderId id;
|
||||
FILE* handle;
|
||||
u64 counter;
|
||||
};
|
||||
|
||||
public:
|
||||
private:
|
||||
static constexpr size_t MaxCaches = 0x2;
|
||||
|
||||
CacheEntry caches[MaxCaches];
|
||||
std::array<CacheEntry, MaxCaches> caches;
|
||||
char* root_path;
|
||||
u64 cur_counter;
|
||||
HosMutex cache_mutex;
|
||||
MakePlaceHolderPathFunc make_placeholder_path_func;
|
||||
bool delay_flush;
|
||||
|
||||
private:
|
||||
Result Open(FILE** out_handle, PlaceHolderId placeholder_id);
|
||||
CacheEntry *FindInCache(PlaceHolderId placeholder_id);
|
||||
bool LoadFromCache(FILE** out_handle, PlaceHolderId placeholder_id);
|
||||
CacheEntry *GetFreeEntry();
|
||||
void StoreToCache(FILE* handle, PlaceHolderId placeholder_id);
|
||||
void Invalidate(CacheEntry *entry);
|
||||
public:
|
||||
PlaceHolderAccessor() : cur_counter(0), delay_flush(false) {
|
||||
for (size_t i = 0; i < MaxCaches; i++) {
|
||||
caches[i].id = InvalidUuid;
|
||||
}
|
||||
}
|
||||
|
||||
inline void GetPlaceHolderRootPath(char* out_placeholder_root) {
|
||||
inline void MakeRootPath(char* out_placeholder_root) {
|
||||
path::GetPlaceHolderRootPath(out_placeholder_root, this->root_path);
|
||||
}
|
||||
|
||||
inline void GetPlaceHolderPath(char* out_placeholder_path, PlaceHolderId placeholder_id) {
|
||||
inline void MakePath(char* out_placeholder_path, PlaceHolderId placeholder_id) {
|
||||
char placeholder_root_path[FS_MAX_PATH] = {0};
|
||||
this->GetPlaceHolderRootPath(placeholder_root_path);
|
||||
this->MakeRootPath(placeholder_root_path);
|
||||
this->make_placeholder_path_func(out_placeholder_path, placeholder_id, placeholder_root_path);
|
||||
}
|
||||
|
||||
void Initialize(char* root, MakePlaceHolderPathFunc path_func, bool delay_flush);
|
||||
unsigned int GetDirectoryDepth();
|
||||
void GetPlaceHolderPathUncached(char* out_placeholder_path, PlaceHolderId placeholder_id);
|
||||
void GetPath(char* out_placeholder_path, PlaceHolderId placeholder_id);
|
||||
Result Create(PlaceHolderId placeholder_id, size_t size);
|
||||
Result Delete(PlaceHolderId placeholder_id);
|
||||
Result Open(FILE** out_handle, PlaceHolderId placeholder_id);
|
||||
Result Write(PlaceHolderId placeholder_id, size_t offset, const void* buffer, size_t size);
|
||||
Result SetSize(PlaceHolderId placeholder_id, size_t size);
|
||||
Result GetSize(bool* found_in_cache, size_t* out_size, PlaceHolderId placeholder_id);
|
||||
Result EnsureRecursively(PlaceHolderId placeholder_id);
|
||||
|
||||
CacheEntry *FindInCache(PlaceHolderId placeholder_id);
|
||||
bool LoadFromCache(FILE** out_handle, PlaceHolderId placeholder_id);
|
||||
void StoreToCache(FILE* handle, PlaceHolderId placeholder_id);
|
||||
void ClearAllCaches();
|
||||
void InvalidateAll();
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user