Skip to content
Permalink
Browse files

Merge pull request #8178 from leoetlino/less-sleep

DiscordHandler: Don't delay shutdown by up to 2s
  • Loading branch information...
Helios747 committed Jun 14, 2019
2 parents 9cf6ba1 + a6f4cb1 commit dd3b67845142a6a28620bafb565f3f46648d8bfe
Showing with 10 additions and 6 deletions.
  1. +8 −6 Source/Core/DolphinQt/DiscordHandler.cpp
  2. +2 −0 Source/Core/DolphinQt/DiscordHandler.h
@@ -6,6 +6,7 @@

#include "DolphinQt/DiscordHandler.h"

#include <chrono>
#include <iterator>

#include <QApplication>
@@ -35,10 +36,12 @@ void DiscordHandler::Start()

void DiscordHandler::Stop()
{
m_stop_requested.Set(true);
if (!m_thread.joinable())
return;

if (m_thread.joinable())
m_thread.join();
m_stop_requested.Set(true);
m_wakeup_event.Set();
m_thread.join();
}

void DiscordHandler::DiscordJoinRequest(const char* id, const std::string& discord_tag,
@@ -68,8 +71,7 @@ void DiscordHandler::Run()
{
while (!m_stop_requested.IsSet())
{
if (m_thread.joinable())
Discord::CallPendingCallbacks();
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});
}
}

@@ -10,6 +10,7 @@

#include <QObject>

#include "Common/Event.h"
#include "Common/Flag.h"

#include "UICommon/DiscordPresence.h"
@@ -42,6 +43,7 @@ class DiscordHandler : public QObject, public Discord::Handler
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;

0 comments on commit dd3b678

Please sign in to comment.
You can’t perform that action at this time.