Merge pull request #8178 from leoetlino/less-sleep

DiscordHandler: Don't delay shutdown by up to 2s
This commit is contained in:
Anthony 2019-06-14 12:28:13 -07:00 committed by GitHub
commit dd3b678451
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -6,6 +6,7 @@
#include "DolphinQt/DiscordHandler.h"
#include <chrono>
#include <iterator>
#include <QApplication>
@ -35,9 +36,11 @@ void DiscordHandler::Start()
void DiscordHandler::Stop()
{
m_stop_requested.Set(true);
if (!m_thread.joinable())
return;
if (m_thread.joinable())
m_stop_requested.Set(true);
m_wakeup_event.Set();
m_thread.join();
}
@ -68,7 +71,6 @@ void DiscordHandler::Run()
{
while (!m_stop_requested.IsSet())
{
if (m_thread.joinable())
Discord::CallPendingCallbacks();
// close and remove dead requests
@ -91,7 +93,7 @@ void DiscordHandler::Run()
}
}
Common::SleepCurrentThread(1000 * 2);
m_wakeup_event.WaitFor(std::chrono::seconds{2});
}
}

View File

@ -10,6 +10,7 @@
#include <QObject>
#include "Common/Event.h"
#include "Common/Flag.h"
#include "UICommon/DiscordPresence.h"
@ -42,6 +43,7 @@ private:
void Run();
QWidget* m_parent;
Common::Flag m_stop_requested;
Common::Event m_wakeup_event;
std::thread m_thread;
std::list<DiscordJoinRequestDialog> m_request_dialogs;
std::mutex m_request_dialogs_mutex;