From fd7cbd633edbac9e38592b9253a507410d7d6553 Mon Sep 17 00:00:00 2001 From: Michael M Date: Fri, 10 Nov 2017 12:29:25 -0800 Subject: [PATCH] ControllerInterface: add mutex around callbacks vector --- .../ControllerInterface/ControllerInterface.cpp | 4 +++- .../InputCommon/ControllerInterface/ControllerInterface.h | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 1552cd7dc2..9e3c7ba7af 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -4,7 +4,7 @@ #include "InputCommon/ControllerInterface/ControllerInterface.h" -#include +#include #include "Common/Logging/Log.h" @@ -232,6 +232,7 @@ void ControllerInterface::UpdateInput() // void ControllerInterface::RegisterDevicesChangedCallback(std::function callback) { + std::lock_guard lk(m_callbacks_mutex); m_devices_changed_callbacks.emplace_back(std::move(callback)); } @@ -242,6 +243,7 @@ void ControllerInterface::RegisterDevicesChangedCallback(std::function c // void ControllerInterface::InvokeDevicesChangedCallbacks() const { + std::lock_guard lk(m_callbacks_mutex); for (const auto& callback : m_devices_changed_callbacks) callback(); } diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h index e70c135b3e..b485cda31a 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h @@ -4,14 +4,11 @@ #pragma once -#include #include -#include -#include -#include +#include +#include #include -#include "Common/CommonTypes.h" #include "InputCommon/ControllerInterface/Device.h" // enable disable sources @@ -58,6 +55,7 @@ public: private: std::vector> m_devices_changed_callbacks; + mutable std::mutex m_callbacks_mutex; bool m_is_init; void* m_hwnd; };