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;
}