Skip to content

Commit

Permalink
Quick attempt to add some thread safety to GameInfo::fileLoader.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed May 4, 2023
1 parent 7ddcf62 commit 6a51b6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 12 additions & 4 deletions UI/GameInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ bool GameInfo::LoadFromPath(const Path &gamePath) {
std::lock_guard<std::mutex> guard(lock);
// No need to rebuild if we already have it loaded.
if (filePath_ != gamePath) {
fileLoader.reset(ConstructFileLoader(gamePath));
if (!fileLoader)
return false;
{
std::lock_guard<std::mutex> guard(loaderLock);
fileLoader.reset(ConstructFileLoader(gamePath));
if (!fileLoader)
return false;
}
filePath_ = gamePath;

// This is a fallback title, while we're loading / if unable to load.
Expand All @@ -215,13 +218,18 @@ std::shared_ptr<FileLoader> GameInfo::GetFileLoader() {
// because Priority() calls GetFileLoader()... gnarly.
return fileLoader;
}

std::lock_guard<std::mutex> guard(loaderLock);
if (!fileLoader) {
fileLoader.reset(ConstructFileLoader(filePath_));
FileLoader *loader = ConstructFileLoader(filePath_);
fileLoader.reset(loader);
return fileLoader;
}
return fileLoader;
}

void GameInfo::DisposeFileLoader() {
std::lock_guard<std::mutex> guard(loaderLock);
fileLoader.reset();
}

Expand Down
3 changes: 3 additions & 0 deletions UI/GameInfoCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class GameInfo {
// to it.
std::mutex lock;

// Controls access to the fileLoader pointer.
std::mutex loaderLock;

std::string id;
std::string id_version;
int disc_total = 0;
Expand Down

0 comments on commit 6a51b6f

Please sign in to comment.