diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.cpp b/Source/Core/DolphinQt2/GameList/GameTracker.cpp index 958236d227..4fbde454c1 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.cpp +++ b/Source/Core/DolphinQt2/GameList/GameTracker.cpp @@ -56,8 +56,8 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent) void GameTracker::LoadCache() { - std::lock_guard lk(m_mutex); m_cache.Load(); + m_cache_loaded_event.Set(); } void GameTracker::Start() @@ -67,12 +67,14 @@ void GameTracker::Start() m_initial_games_emitted = true; - std::lock_guard lk(m_mutex); - m_load_thread.EmplaceItem(Command{CommandType::Start, {}}); + m_cache_loaded_event.Wait(); + m_cache.ForEach( [this](const std::shared_ptr& game) { emit GameLoaded(game); }); + + m_initial_games_emitted_event.Set(); } void GameTracker::StartInternal() @@ -92,7 +94,7 @@ void GameTracker::StartInternal() }; auto emit_game_removed = [this](const std::string& path) { emit GameRemoved(path); }; - std::lock_guard lk(m_mutex); + m_initial_games_emitted_event.Wait(); bool cache_updated = m_cache.Update(paths, emit_game_loaded, emit_game_removed); cache_updated |= m_cache.UpdateAdditionalMetadata(m_title_database, emit_game_loaded); diff --git a/Source/Core/DolphinQt2/GameList/GameTracker.h b/Source/Core/DolphinQt2/GameList/GameTracker.h index cbe6c63cba..3f27475ebc 100644 --- a/Source/Core/DolphinQt2/GameList/GameTracker.h +++ b/Source/Core/DolphinQt2/GameList/GameTracker.h @@ -5,7 +5,6 @@ #pragma once #include -#include #include #include @@ -13,6 +12,7 @@ #include #include +#include "Common/Event.h" #include "Common/WorkQueueThread.h" #include "Core/TitleDatabase.h" #include "UICommon/GameFile.h" @@ -75,9 +75,10 @@ private: Common::WorkQueueThread m_load_thread; UICommon::GameFileCache m_cache; Core::TitleDatabase m_title_database; - std::mutex m_mutex; - bool m_started = false; + Common::Event m_cache_loaded_event; + Common::Event m_initial_games_emitted_event; bool m_initial_games_emitted = false; + bool m_started = false; }; Q_DECLARE_METATYPE(std::shared_ptr)