Skip to content

Commit

Permalink
GameInfoCache: Move some I/O out of the mutex. There's more to do.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 18, 2024
1 parent 71354d0 commit e29f59a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions UI/GameInfoCache.cpp
Expand Up @@ -340,16 +340,19 @@ static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string
if (handle < 0) {
return false;
}

if (mtx) {
std::string data;
data.resize(info.size);
fs->ReadFile(handle, (u8 *)data.data(), info.size);
fs->CloseFile(handle);

std::lock_guard<std::mutex> lock(*mtx);
contents->resize(info.size);
fs->ReadFile(handle, (u8 *)contents->data(), info.size);
*contents = std::move(data);
} else {
contents->resize(info.size);
fs->ReadFile(handle, (u8 *)contents->data(), info.size);
fs->CloseFile(handle);
}
fs->CloseFile(handle);
return true;
}

Expand All @@ -363,12 +366,13 @@ static bool ReadVFSToString(const char *filename, std::string *contents, std::mu
} else {
*contents = std::string((const char *)data, sz);
}
} else {
return false;
}
delete [] data;
return data != nullptr;
return true;
}


class GameInfoWorkItem : public Task {
public:
GameInfoWorkItem(const Path &gamePath, std::shared_ptr<GameInfo> &info)
Expand Down

0 comments on commit e29f59a

Please sign in to comment.