Permalink
Browse files

UI: Add threadsafety to cache item file loaders.

  • Loading branch information...
unknownbrackets committed Dec 10, 2017
1 parent 8b665ae commit 472ee12391a78f95e34752cbab62ff5cf52d7ffd
Showing with 15 additions and 18 deletions.
  1. +12 −16 UI/GameInfoCache.cpp
  2. +3 −2 UI/GameInfoCache.h
@@ -54,7 +54,7 @@ GameInfo::~GameInfo() {
icon.Clear();
pic0.Clear();
pic1.Clear();
delete fileLoader;
fileLoader.reset();
}
bool GameInfo::Delete() {
@@ -218,8 +218,7 @@ bool GameInfo::LoadFromPath(const std::string &gamePath) {
std::lock_guard<std::mutex> guard(lock);
// No need to rebuild if we already have it loaded.
if (filePath_ != gamePath) {
delete fileLoader;
fileLoader = ConstructFileLoader(gamePath);
fileLoader.reset(ConstructFileLoader(gamePath));
if (!fileLoader)
return false;
filePath_ = gamePath;
@@ -231,16 +230,15 @@ bool GameInfo::LoadFromPath(const std::string &gamePath) {
return fileLoader ? fileLoader->Exists() : true;
}
FileLoader *GameInfo::GetFileLoader() {
std::shared_ptr<FileLoader> GameInfo::GetFileLoader() {
if (!fileLoader) {
fileLoader = ConstructFileLoader(filePath_);
fileLoader.reset(ConstructFileLoader(filePath_));
}
return fileLoader;
}
void GameInfo::DisposeFileLoader() {
delete fileLoader;
fileLoader = nullptr;
fileLoader.reset();
}
bool GameInfo::DeleteAllSaveData() {
@@ -373,24 +371,22 @@ class GameInfoWorkItem : public PrioritizedWorkQueueItem {
{
std::lock_guard<std::mutex> lock(info_->lock);
info_->working = true;
info_->fileType = Identify_File(info_->GetFileLoader());
info_->fileType = Identify_File(info_->GetFileLoader().get());
}
switch (info_->fileType) {
case IdentifiedFileType::PSP_PBP:
case IdentifiedFileType::PSP_PBP_DIRECTORY:
{
FileLoader *pbpLoader = info_->GetFileLoader();
std::unique_ptr<FileLoader> altLoader;
auto pbpLoader = info_->GetFileLoader();
if (info_->fileType == IdentifiedFileType::PSP_PBP_DIRECTORY) {
std::string ebootPath = ResolvePBPFile(gamePath_);
if (ebootPath != gamePath_) {
pbpLoader = ConstructFileLoader(ebootPath);
altLoader.reset(pbpLoader);
pbpLoader.reset(ConstructFileLoader(ebootPath));
}
}
PBPReader pbp(pbpLoader);
PBPReader pbp(pbpLoader.get());
if (!pbp.IsValid()) {
if (pbp.IsELF()) {
goto handleELF;
@@ -559,10 +555,10 @@ class GameInfoWorkItem : public PrioritizedWorkQueueItem {
// Let's assume it's an ISO.
// TODO: This will currently read in the whole directory tree. Not really necessary for just a
// few files.
FileLoader *fl = info_->GetFileLoader();
auto fl = info_->GetFileLoader();
if (!fl)
return; // Happens with UWP currently, TODO...
BlockDevice *bd = constructBlockDevice(info_->GetFileLoader());
BlockDevice *bd = constructBlockDevice(info_->GetFileLoader().get());
if (!bd)
return; // nothing to do here..
ISOFileSystem umd(&handles, bd);
@@ -700,7 +696,7 @@ void GameInfoCache::Clear() {
void GameInfoCache::CancelAll() {
for (auto info : info_) {
FileLoader *fl = info.second->GetFileLoader();
auto fl = info.second->GetFileLoader();
if (fl) {
fl->Cancel();
}
@@ -19,6 +19,7 @@
#include <string>
#include <map>
#include <memory>
#include <mutex>
#include <atomic>
@@ -93,7 +94,7 @@ class GameInfo {
bool DeleteAllSaveData();
bool LoadFromPath(const std::string &gamePath);
FileLoader *GetFileLoader();
std::shared_ptr<FileLoader> GetFileLoader();
void DisposeFileLoader();
u64 GetGameSizeInBytes();
@@ -148,7 +149,7 @@ class GameInfo {
// Note: this can change while loading, use GetTitle().
std::string title;
FileLoader *fileLoader = nullptr;
std::shared_ptr<FileLoader> fileLoader;
std::string filePath_;
private:

0 comments on commit 472ee12

Please sign in to comment.