summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h
diff options
context:
space:
mode:
authorAnthony <Helios747@users.noreply.github.com>2016-12-01 00:29:56 -0600
committerGitHub <noreply@github.com>2016-12-01 00:29:56 -0600
commitffe20705dd931128894a9a2839d22cad26bfc4c8 (patch)
tree5e9e75ae82018c28cd87cc56b8046faa6f8415b5 /Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h
parenta95e3c875e2749b4a489aa988f5b35608f5a8b59 (diff)
parent7ed8fb95c553d876a717089ca8808bd2c5adf575 (diff)
Merge pull request #4362 from ligfx/osxhotplug
ControllerInterface: enable hotplugging on macOS
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h b/Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h
new file mode 100644
index 0000000000..298dcd4a80
--- /dev/null
+++ b/Source/Core/InputCommon/ControllerInterface/OSX/RunLoopStopper.h
@@ -0,0 +1,45 @@
+// Copyright 2016 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <Foundation/Foundation.h>
+
+namespace ciface
+{
+namespace OSX
+{
+class RunLoopStopper
+{
+ CFRunLoopSourceRef m_source;
+ CFRunLoopRef m_runloop = nullptr;
+
+public:
+ RunLoopStopper()
+ {
+ CFRunLoopSourceContext ctx = {.version = 0,
+ .perform = [](void*) { CFRunLoopStop(CFRunLoopGetCurrent()); }};
+ m_source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &ctx);
+ }
+ ~RunLoopStopper() { CFRelease(m_source); }
+ void Signal()
+ {
+ CFRunLoopSourceSignal(m_source);
+ if (m_runloop != nullptr)
+ CFRunLoopWakeUp(m_runloop);
+ }
+ void AddToRunLoop(CFRunLoopRef runloop, CFStringRef mode)
+ {
+ m_runloop = runloop;
+ CFRunLoopAddSource(runloop, m_source, mode);
+ }
+ void RemoveFromRunLoop(CFRunLoopRef runloop, CFStringRef mode)
+ {
+ m_runloop = nullptr;
+ CFRunLoopRemoveSource(runloop, m_source, mode);
+ }
+};
+
+} // namespace ciface
+} // namespace OSX