From 1cd3f989df88d1ad2133a64576d993820213ed1b Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 26 Sep 2023 20:20:36 -0400 Subject: [PATCH] common: Add mutex guards to the FileCache --- common/include/filecache.h | 2 ++ common/src/filecache.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/common/include/filecache.h b/common/include/filecache.h index 7c85dab..4c2c0e4 100644 --- a/common/include/filecache.h +++ b/common/include/filecache.h @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -21,4 +22,5 @@ private: QMap cachedBuffers; QHash cachedExist; GameData& data; + QMutex bufferMutex, existMutex; }; \ No newline at end of file diff --git a/common/src/filecache.cpp b/common/src/filecache.cpp index 6d5b780..2326130 100644 --- a/common/src/filecache.cpp +++ b/common/src/filecache.cpp @@ -9,6 +9,8 @@ FileCache::FileCache(GameData& data) : data(data) {} physis_Buffer &FileCache::lookupFile(const QLatin1String &path) { + QMutexLocker locker(&bufferMutex); + if (!cachedBuffers.contains(path)) { cachedBuffers[path] = physis_gamedata_extract_file(&data, path.data()); } @@ -18,6 +20,8 @@ physis_Buffer &FileCache::lookupFile(const QLatin1String &path) bool FileCache::fileExists(const QLatin1String &path) { + QMutexLocker locker(&existMutex); + if (!cachedExist.contains(path)) { cachedExist[path] = physis_gamedata_exists(&data, path.data()); }