summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2016-06-12 17:31:41 +0200
committerLéo Lam <leo@innovatetechnologi.es>2016-06-25 13:46:53 +0200
commitd3e2ae35ff853d115aca077eaa10b88114ef7c7c (patch)
treeef48e2c922c685a99fbfe602b408623475092763 /Source/Core/InputCommon/ControllerInterface
parentfd29e5c4cc26cd853a03ac7b0e08b367b7070c84 (diff)
ControllerInterface: Add synchronisation
Since we may have to add/access devices from different threads, this adds synchronisation to anything that touches m_devices.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp4
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ControllerInterface.h1
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Device.h2
3 files changed, 7 insertions, 0 deletions
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<std::mutex> 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<std::mutex> 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<std::mutex> 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 <algorithm>
#include <map>
+#include <mutex>
#include <sstream>
#include <string>
#include <vector>
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 <mutex>
#include <string>
#include <vector>
@@ -167,6 +168,7 @@ public:
Device* FindDevice(const DeviceQualifier& devq) const;
protected:
+ std::mutex m_devices_mutex;
std::vector<Device*> m_devices;
};
}