From fd29e5c4cc26cd853a03ac7b0e08b367b7070c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 12 Jun 2016 17:08:04 +0200 Subject: ControllerInterface: Don't pass m_devices to the backends Previously, the devices vector would be passed to all backends. They would then manually push_back to it to add new devices. This was fine but caused issues when trying to add synchronisation. Instead, backends now call AddDevice() to fill m_devices so that it is not accessible from the outside. --- .../ControllerInterface/ControllerInterface.cpp | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 55643ece5f..c139d3b787 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -55,31 +55,31 @@ void ControllerInterface::Initialize(void* const hwnd) m_hwnd = hwnd; #ifdef CIFACE_USE_DINPUT - ciface::DInput::Init(m_devices, (HWND)hwnd); + ciface::DInput::Init((HWND)hwnd); #endif #ifdef CIFACE_USE_XINPUT - ciface::XInput::Init(m_devices); + ciface::XInput::Init(); #endif #ifdef CIFACE_USE_XLIB - ciface::Xlib::Init(m_devices, hwnd); + ciface::Xlib::Init(hwnd); #ifdef CIFACE_USE_X11_XINPUT2 - ciface::XInput2::Init(m_devices, hwnd); + ciface::XInput2::Init(hwnd); #endif #endif #ifdef CIFACE_USE_OSX - ciface::OSX::Init(m_devices, hwnd); + ciface::OSX::Init(hwnd); #endif #ifdef CIFACE_USE_SDL - ciface::SDL::Init(m_devices); + ciface::SDL::Init(); #endif #ifdef CIFACE_USE_ANDROID - ciface::Android::Init(m_devices); + ciface::Android::Init(); #endif #ifdef CIFACE_USE_EVDEV - ciface::evdev::Init(m_devices); + ciface::evdev::Init(); #endif #ifdef CIFACE_USE_PIPES - ciface::Pipes::Init(m_devices); + ciface::Pipes::Init(); #endif m_is_init = true; @@ -139,6 +139,11 @@ void ControllerInterface::Shutdown() m_is_init = false; } +void ControllerInterface::AddDevice(ciface::Core::Device* device) +{ + m_devices.push_back(device); +} + // // UpdateInput // -- cgit v1.2.3 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: ControllerInterface: Add synchronisation Since we may have to add/access devices from different threads, this adds synchronisation to anything that touches m_devices. --- Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp') 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(); } -- cgit v1.2.3