mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-24 04:57:45 +00:00
common: Add mutex guards to the FileCache
This commit is contained in:
parent
71007249b6
commit
1cd3f989df
2 changed files with 6 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QMutex>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <physis.hpp>
|
#include <physis.hpp>
|
||||||
|
|
||||||
|
@ -21,4 +22,5 @@ private:
|
||||||
QMap<QLatin1String, physis_Buffer> cachedBuffers;
|
QMap<QLatin1String, physis_Buffer> cachedBuffers;
|
||||||
QHash<QLatin1String, bool> cachedExist;
|
QHash<QLatin1String, bool> cachedExist;
|
||||||
GameData& data;
|
GameData& data;
|
||||||
|
QMutex bufferMutex, existMutex;
|
||||||
};
|
};
|
|
@ -9,6 +9,8 @@ FileCache::FileCache(GameData& data) : data(data) {}
|
||||||
|
|
||||||
physis_Buffer &FileCache::lookupFile(const QLatin1String &path)
|
physis_Buffer &FileCache::lookupFile(const QLatin1String &path)
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&bufferMutex);
|
||||||
|
|
||||||
if (!cachedBuffers.contains(path)) {
|
if (!cachedBuffers.contains(path)) {
|
||||||
cachedBuffers[path] = physis_gamedata_extract_file(&data, path.data());
|
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)
|
bool FileCache::fileExists(const QLatin1String &path)
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&existMutex);
|
||||||
|
|
||||||
if (!cachedExist.contains(path)) {
|
if (!cachedExist.contains(path)) {
|
||||||
cachedExist[path] = physis_gamedata_exists(&data, path.data());
|
cachedExist[path] = physis_gamedata_exists(&data, path.data());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue