Merge pull request #6284 from JosJuice/qt-gamefilecache-mutex

DolphinQt2: Don't use a mutex in GameFileCache
This commit is contained in:
Léo Lam 2018-01-04 22:44:53 +01:00 committed by GitHub
commit e31f8f8ecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 24 deletions

View File

@ -6,6 +6,7 @@
#include <QDataStream>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include "Common/FileUtil.h"
@ -20,24 +21,18 @@ GameFileCache::GameFileCache()
{
}
bool GameFileCache::IsCached(const QString& path)
bool GameFileCache::IsCached(const QString& path) const
{
std::lock_guard<std::mutex> guard(m_mutex);
return m_gamefiles.contains(path);
}
GameFile GameFileCache::GetFile(const QString& path)
GameFile GameFileCache::GetFile(const QString& path) const
{
std::lock_guard<std::mutex> guard(m_mutex);
return m_gamefiles[path];
}
void GameFileCache::Load()
{
std::lock_guard<std::mutex> guard(m_mutex);
QFile file(m_path);
if (!file.open(QIODevice::ReadOnly))
@ -56,10 +51,8 @@ void GameFileCache::Load()
stream >> m_gamefiles;
}
void GameFileCache::Save()
void GameFileCache::Save() const
{
std::lock_guard<std::mutex> guard(m_mutex);
QFile file(m_path);
if (!file.open(QIODevice::WriteOnly))
@ -74,14 +67,10 @@ void GameFileCache::Save()
void GameFileCache::Update(const GameFile& gamefile)
{
std::lock_guard<std::mutex> guard(m_mutex);
m_gamefiles[gamefile.GetFilePath()] = gamefile;
}
QList<QString> GameFileCache::GetCached()
QList<QString> GameFileCache::GetCached() const
{
std::lock_guard<std::mutex> guard(m_mutex);
return m_gamefiles.keys();
}

View File

@ -4,9 +4,9 @@
#pragma once
#include <QFile>
#include <mutex>
#include <QList>
#include <QMap>
#include <QString>
#include "DolphinQt2/GameList/GameFile.h"
@ -16,15 +16,14 @@ public:
explicit GameFileCache();
void Update(const GameFile& gamefile);
void Save();
void Save() const;
void Load();
bool IsCached(const QString& path);
GameFile GetFile(const QString& path);
QList<QString> GetCached();
bool IsCached(const QString& path) const;
GameFile GetFile(const QString& path) const;
QList<QString> GetCached() const;
private:
QString m_path;
QMap<QString, GameFile> m_gamefiles;
std::mutex m_mutex;
};