Merge pull request #7714 from cristian64/avoid_leaking_gamelistmodel

DolphinQt: Avoid leaking the GameListModel instance to gracefully shutdown the GameTracker and prevent a crash on exit
This commit is contained in:
Léo Lam
2020-11-18 02:14:51 +01:00
committed by GitHub
21 changed files with 191 additions and 117 deletions

View File

@ -27,6 +27,7 @@ public:
{
Shutdown();
m_shutdown.Clear();
m_cancelled.Clear();
m_function = std::move(function);
m_thread = std::thread(&WorkQueueThread::ThreadLoop, this);
}
@ -34,6 +35,7 @@ public:
template <typename... Args>
void EmplaceItem(Args&&... args)
{
if (!m_cancelled.IsSet())
{
std::lock_guard lg(m_lock);
m_items.emplace(std::forward<Args>(args)...);
@ -41,6 +43,24 @@ public:
m_wakeup.Set();
}
void Clear()
{
{
std::lock_guard lg(m_lock);
m_items = std::queue<T>();
}
m_wakeup.Set();
}
void Cancel()
{
m_cancelled.Set();
Clear();
Shutdown();
}
bool IsCancelled() const { return m_cancelled.IsSet(); }
private:
void Shutdown()
{
@ -81,6 +101,7 @@ private:
std::thread m_thread;
Common::Event m_wakeup;
Common::Flag m_shutdown;
Common::Flag m_cancelled;
std::mutex m_lock;
std::queue<T> m_items;
};