summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
diff options
context:
space:
mode:
authorTillmann Karras <tilkax@gmail.com>2016-12-05 00:37:36 +0000
committerTillmann Karras <tilkax@gmail.com>2016-12-05 00:47:26 +0000
commitf575902cf31ead3238d43ac475a5d3a33f83ce1f (patch)
treefafb361ae932de68c26df5d8e97e82042124c130 /Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
parent3c090a37d4f552008bbc287fcd635064e294f553 (diff)
evdev: set flag in a thread-safe way
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
index 788ea963bc..58f92f29a4 100644
--- a/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
@@ -116,26 +116,28 @@ static void HotplugThreadFunc()
static void StartHotplugThread()
{
- if (s_hotplug_thread_running.IsSet())
+ // Mark the thread as running.
+ if (!s_hotplug_thread_running.TestAndSet())
+ // It was already running.
return;
s_wakeup_eventfd = eventfd(0, 0);
_assert_msg_(PAD, s_wakeup_eventfd != -1, "Couldn't create eventfd.");
- s_hotplug_thread_running.Set(true);
s_hotplug_thread = std::thread(HotplugThreadFunc);
}
static void StopHotplugThread()
{
- if (s_hotplug_thread_running.TestAndClear())
+ // Tell the hotplug thread to stop.
+ if (!s_hotplug_thread_running.TestAndClear())
+ // It wasn't running, we're done.
+ return;
+ // Write something to efd so that select() stops blocking.
+ uint64_t value = 1;
+ if (write(s_wakeup_eventfd, &value, sizeof(uint64_t)) < 0)
{
- // Write something to efd so that select() stops blocking.
- uint64_t value = 1;
- if (write(s_wakeup_eventfd, &value, sizeof(uint64_t)) < 0)
- {
- }
- s_hotplug_thread.join();
}
+ s_hotplug_thread.join();
}
void Init()