mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-19 19:00:09 +02:00
DiscordHandler: Don't delay shutdown by up to 2s
Currently, it is possible for the DiscordHandler thread to be in the middle of sleeping when Dolphin is closing. This results in a very noticeable delay of up to 2 seconds that is unacceptable, especially for people who don't use the Discord integration. This fixes the issue by making the thread wait on an Event instead and signalling it when shutting down.
This commit is contained in:
@ -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});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user