From 93f5df419521171c11e16d6a8ff84b9d0d8fd6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 14 Jul 2016 17:45:59 +0200 Subject: 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. --- Source/Core/InputCommon/ControllerEmu.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Source/Core/InputCommon/ControllerEmu.cpp') 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 #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 ControllerEmu::GetStateLock() +{ + std::unique_lock 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) -- cgit v1.2.3