From d3e2ae35ff853d115aca077eaa10b88114ef7c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 12 Jun 2016 17:31:41 +0200 Subject: [PATCH] ControllerInterface: Add synchronisation Since we may have to add/access devices from different threads, this adds synchronisation to anything that touches m_devices. --- .../InputCommon/ControllerInterface/ControllerInterface.cpp | 4 ++++ .../InputCommon/ControllerInterface/ControllerInterface.h | 1 + Source/Core/InputCommon/ControllerInterface/Device.h | 2 ++ 3 files changed, 7 insertions(+) diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index c139d3b787..b36387162d 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -104,6 +104,8 @@ void ControllerInterface::Shutdown() if (!m_is_init) return; + std::lock_guard lk(m_devices_mutex); + for (ciface::Core::Device* d : m_devices) { // Set outputs to ZERO before destroying device @@ -141,6 +143,7 @@ void ControllerInterface::Shutdown() void ControllerInterface::AddDevice(ciface::Core::Device* device) { + std::lock_guard lk(m_devices_mutex); m_devices.push_back(device); } @@ -151,6 +154,7 @@ void ControllerInterface::AddDevice(ciface::Core::Device* device) // void ControllerInterface::UpdateInput() { + std::lock_guard lk(m_devices_mutex); for (ciface::Core::Device* d : m_devices) d->UpdateInput(); } diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h index 3d1354dcc7..2571e5f3ab 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index dc60691b56..c3cddb3a79 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include @@ -167,6 +168,7 @@ public: Device* FindDevice(const DeviceQualifier& devq) const; protected: + std::mutex m_devices_mutex; std::vector m_devices; }; }