Permalink
Browse files

Merge pull request #6982 from JosJuice/gametracker-race

DolphinQt2: Fix a race condition in GameTracker
  • Loading branch information...
leoetlino committed May 27, 2018
2 parents 7b07424 + c0553af commit 2bc9a4a90214a7813622f1405174e60ccda523e5
Showing with 10 additions and 7 deletions.
  1. +6 −4 Source/Core/DolphinQt2/GameList/GameTracker.cpp
  2. +4 −3 Source/Core/DolphinQt2/GameList/GameTracker.h
@@ -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,14 +5,14 @@
#pragma once
#include <memory>
#include <mutex>
#include <string>
#include <QFileSystemWatcher>
#include <QMap>
#include <QSet>
#include <QString>
#include "Common/Event.h"
#include "Common/WorkQueueThread.h"
#include "Core/TitleDatabase.h"
#include "UICommon/GameFile.h"
@@ -75,9 +75,10 @@ class GameTracker final : public QFileSystemWatcher
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>)

0 comments on commit 2bc9a4a

Please sign in to comment.