DolphinQt2: Fix a race condition in GameTracker
We need to make sure that LoadCache finishes before Start begins accessing m_cache. The old solution with mutexes didn't do this.
This commit is contained in:
parent
7b07424885
commit
c0553afff1
|
@ -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