UI: Correct a race condition when loading bgs.

This commit is contained in:
Unknown W. Brackets committed 2016-03-06 14:49:17 -08:00
1 parent 8a9e30f833
commit f38869141a
2 files changed
+16 -1

No files matched your search

+13
View File
@@ -303,6 +303,11 @@ bool GameInfo::IsPending() {
return pending;
}
bool GameInfo::IsWorking() {
lock_guard guard(lock);
return working;
}
void GameInfo::SetTitle(const std::string &newTitle) {
lock_guard guard(lock);
title = newTitle;
@@ -360,6 +365,7 @@ public:
std::string filename = gamePath_;
{
lock_guard lock(info_->lock);
info_->working = true;
info_->fileType = Identify_File(info_->GetFileLoader());
}
@@ -591,6 +597,7 @@ handleELF:
lock_guard lock(info_->lock);
info_->pending = false;
info_->working = false;
// ILOG("Completed writing info for %s", info_->GetTitle().c_str());
}
@@ -755,8 +762,14 @@ again:
if (!info) {
info = new GameInfo();
}
{
lock_guard lock(info->lock);
if (info->IsWorking()) {
// Uh oh, it's currently in process. It could mark pending = false with the wrong wantFlags.
// Let's wait it out, then queue.
WaitUntilDone(info);
}
info->wantFlags |= wantFlags;
info->pending = true;
}
+3 -1
View File
@@ -98,7 +98,7 @@ public:
: disc_total(0), disc_number(0), region(-1), fileType(FILETYPE_UNKNOWN), paramSFOLoaded(false),
hasConfig(false), iconTexture(nullptr), pic0Texture(nullptr), pic1Texture(nullptr), wantFlags(0),
lastAccessedTime(0.0), timeIconWasLoaded(0.0), timePic0WasLoaded(0.0), timePic1WasLoaded(0.0),
gameSize(0), saveDataSize(0), installDataSize(0), pending(true), fileLoader(nullptr) {}
gameSize(0), saveDataSize(0), installDataSize(0), pending(true), working(false), fileLoader(nullptr) {}
~GameInfo();
bool Delete(); // Better be sure what you're doing when calling this.
@@ -120,6 +120,7 @@ public:
void SetTitle(const std::string &newTitle);
bool IsPending();
bool IsWorking();
// Hold this when reading or writing from the GameInfo.
// Don't need to hold it when just passing around the pointer,
@@ -166,6 +167,7 @@ public:
u64 saveDataSize;
u64 installDataSize;
bool pending;
bool working;
protected:
// Note: this can change while loading, use GetTitle().