summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2016-07-14 17:45:59 +0200
committerLéo Lam <leo@innovatetechnologi.es>2016-07-29 17:18:37 +0200
commit93f5df419521171c11e16d6a8ff84b9d0d8fd6c0 (patch)
treef0d915225a6221acc88716b6f7f8c62a1963fc7a /Source/Core/InputCommon/ControllerEmu.cpp
parent0d783f0869eaef163a318ab4d79744f592ed1cc5 (diff)
ControllerInterface: Add RemoveDevice()
This adds RemoveDevice() to ControllerInterface, fixes ExpressionParser and some other code to support device removals without crashing, and adds an IsValid() method to Device, to prepare for hotplugging.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerEmu.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu.cpp b/Source/Core/InputCommon/ControllerEmu.cpp
index 117184c8db..b3b13b796a 100644
--- a/Source/Core/InputCommon/ControllerEmu.cpp
+++ b/Source/Core/InputCommon/ControllerEmu.cpp
@@ -6,8 +6,19 @@
#include <memory>
#include "Common/Common.h"
+// This should be called before calling GetState() or State() on a control reference
+// to prevent a race condition.
+// This is a recursive mutex because UpdateReferences is recursive.
+static std::recursive_mutex s_get_state_mutex;
+std::unique_lock<std::recursive_mutex> ControllerEmu::GetStateLock()
+{
+ std::unique_lock<std::recursive_mutex> lock(s_get_state_mutex);
+ return lock;
+}
+
void ControllerEmu::UpdateReferences(ControllerInterface& devi)
{
+ auto lock = ControllerEmu::GetStateLock();
for (auto& ctrlGroup : groups)
{
for (auto& control : ctrlGroup->controls)