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