mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Merge pull request #6982 from JosJuice/gametracker-race
DolphinQt2: Fix a race condition in GameTracker
This commit is contained in:
commit
2bc9a4a902
@ -56,8 +56,8 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
|
||||
|
||||
void GameTracker::LoadCache()
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> lk(m_mutex);
|
||||
|
||||
m_load_thread.EmplaceItem(Command{CommandType::Start, {}});
|
||||
|
||||
m_cache_loaded_event.Wait();
|
||||
|
||||
m_cache.ForEach(
|
||||
[this](const std::shared_ptr<const UICommon::GameFile>& 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<std::mutex> 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);
|
||||
|
@ -5,7 +5,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include <QFileSystemWatcher>
|
||||
@ -13,6 +12,7 @@
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
|
||||
#include "Common/Event.h"
|
||||
#include "Common/WorkQueueThread.h"
|
||||
#include "Core/TitleDatabase.h"
|
||||
#include "UICommon/GameFile.h"
|
||||
@ -75,9 +75,10 @@ private:
|
||||
Common::WorkQueueThread<Command> 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<const UICommon::GameFile>)
|
||||
|
Loading…
Reference in New Issue
Block a user