diff --git a/rpcs3/Emu/games_config.cpp b/rpcs3/Emu/games_config.cpp index 9cbe775cbb..346b537d81 100644 --- a/rpcs3/Emu/games_config.cpp +++ b/rpcs3/Emu/games_config.cpp @@ -19,6 +19,12 @@ games_config::~games_config() } } +const std::map games_config::get_games() const +{ + std::lock_guard lock(m_mutex); + return m_games; +} + std::string games_config::get_path(const std::string& title_id) const { if (title_id.empty()) @@ -26,6 +32,8 @@ std::string games_config::get_path(const std::string& title_id) const return {}; } + std::lock_guard lock(m_mutex); + if (const auto it = m_games.find(title_id); it != m_games.cend()) { return it->second; @@ -36,6 +44,8 @@ std::string games_config::get_path(const std::string& title_id) const bool games_config::add_game(const std::string& key, const std::string& path) { + std::lock_guard lock(m_mutex); + // Access or create node if does not exist if (auto it = m_games.find(key); it != m_games.end()) { @@ -64,6 +74,8 @@ bool games_config::add_game(const std::string& key, const std::string& path) bool games_config::save() { + std::lock_guard lock(m_mutex); + YAML::Emitter out; out << m_games; @@ -81,6 +93,8 @@ bool games_config::save() void games_config::load() { + std::lock_guard lock(m_mutex); + m_games.clear(); if (fs::file f{fs::get_config_dir() + "/games.yml", fs::read + fs::create}) diff --git a/rpcs3/Emu/games_config.h b/rpcs3/Emu/games_config.h index 0415a6d58b..12ca97ca80 100644 --- a/rpcs3/Emu/games_config.h +++ b/rpcs3/Emu/games_config.h @@ -1,5 +1,6 @@ #pragma once +#include "Utilities/mutex.h" #include class games_config @@ -10,7 +11,7 @@ public: void set_save_on_dirty(bool enabled) { m_save_on_dirty = enabled; } - const std::map& get_games() const { return m_games; } + const std::map get_games() const; bool is_dirty() const { return m_dirty; } std::string get_path(const std::string& title_id) const; @@ -22,6 +23,7 @@ private: void load(); std::map m_games; + mutable shared_mutex m_mutex; bool m_dirty = false; bool m_save_on_dirty = true;