summaryrefslogtreecommitdiff
path: root/Source/Core/UICommon/NetPlayIndex.cpp
diff options
context:
space:
mode:
authorTechjar <tecknojar@gmail.com>2019-04-06 08:09:20 -0400
committerTechjar <tecknojar@gmail.com>2019-04-06 17:23:37 -0400
commitdc552f2cbb204b4ad53bdcdc324bf1ab7baf410a (patch)
treea3e00a73c76e92391fd99fccbd653d82166d0f18 /Source/Core/UICommon/NetPlayIndex.cpp
parent23986d48f731fd92e8989b32988f636118c9d2ba (diff)
UICommon/NetPlayIndex: Fix random segfaults after quitting NetPlay
We can't join a detached thread, so NetPlayIndex gets deleted before the notification thread exits, creating a race condition. We switch to using Common::Event because just sleeping leaves the UI hung on the thread join for a few seconds.
Diffstat (limited to 'Source/Core/UICommon/NetPlayIndex.cpp')
-rw-r--r--Source/Core/UICommon/NetPlayIndex.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/Source/Core/UICommon/NetPlayIndex.cpp b/Source/Core/UICommon/NetPlayIndex.cpp
index b41920c647..4de053338d 100644
--- a/Source/Core/UICommon/NetPlayIndex.cpp
+++ b/Source/Core/UICommon/NetPlayIndex.cpp
@@ -4,6 +4,7 @@
#include "UICommon/NetPlayIndex.h"
+#include <chrono>
#include <numeric>
#include <string>
@@ -121,7 +122,7 @@ NetPlayIndex::List(const std::map<std::string, std::string>& filters)
void NetPlayIndex::NotificationLoop()
{
- while (m_running.IsSet())
+ while (!m_session_thread_exit_event.WaitFor(std::chrono::seconds(5)))
{
Common::HttpRequest request;
auto response = request.Get(
@@ -138,7 +139,6 @@ void NetPlayIndex::NotificationLoop()
if (!json)
{
m_last_error = "BAD_JSON";
- m_running.Set(false);
return;
}
@@ -147,18 +147,13 @@ void NetPlayIndex::NotificationLoop()
if (status != "OK")
{
m_last_error = std::move(status);
- m_running.Set(false);
return;
}
-
- Common::SleepCurrentThread(1000 * 5);
}
}
bool NetPlayIndex::Add(NetPlaySession session)
{
- m_running.Set(true);
-
Common::HttpRequest request;
auto response = request.Get(Config::Get(Config::NETPLAY_INDEX_URL) +
"/v0/session/add?name=" + request.EscapeComponent(session.name) +
@@ -201,8 +196,6 @@ bool NetPlayIndex::Add(NetPlaySession session)
m_session_thread = std::thread([this] { NotificationLoop(); });
- m_session_thread.detach();
-
return true;
}
@@ -226,7 +219,7 @@ void NetPlayIndex::Remove()
if (m_secret.empty())
return;
- m_running.Set(false);
+ m_session_thread_exit_event.Set();
if (m_session_thread.joinable())
m_session_thread.join();