summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2020-01-21 18:52:58 -0600
committerJordan Woyak <jordan.woyak@gmail.com>2020-02-17 15:58:06 -0600
commit4176cc77e1c3627ceee7b849195f026efc1bf9ca (patch)
tree7b22972a98827e12357eab76c896fad5c7817b04 /Source/Core/InputCommon/ControllerInterface
parent5af2081c756b6584236044acb198374b2e8b1422 (diff)
InputCommon/ControllerInterface: Make devices mutex recursive so RemoveDevice can be used within UpdateInput.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp11
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Device.cpp8
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Device.h2
3 files changed, 11 insertions, 10 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
index 130f0f357a..faa6de185e 100644
--- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp
@@ -93,7 +93,7 @@ void ControllerInterface::RefreshDevices()
return;
{
- std::lock_guard<std::mutex> lk(m_devices_mutex);
+ std::lock_guard lk(m_devices_mutex);
m_devices.clear();
}
@@ -131,6 +131,7 @@ void ControllerInterface::RefreshDevices()
#ifdef CIFACE_USE_DUALSHOCKUDPCLIENT
ciface::DualShockUDPClient::PopulateDevices();
#endif
+ ciface::Wiimote::PopulateDevices();
m_is_populating_devices = false;
InvokeDevicesChangedCallbacks();
@@ -146,7 +147,7 @@ void ControllerInterface::Shutdown()
m_is_init = false;
{
- std::lock_guard<std::mutex> lk(m_devices_mutex);
+ std::lock_guard lk(m_devices_mutex);
for (const auto& d : m_devices)
{
@@ -193,7 +194,7 @@ void ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device
return;
{
- std::lock_guard<std::mutex> lk(m_devices_mutex);
+ std::lock_guard lk(m_devices_mutex);
const auto is_id_in_use = [&device, this](int id) {
return std::any_of(m_devices.begin(), m_devices.end(), [&device, &id](const auto& d) {
@@ -229,7 +230,7 @@ void ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device
void ControllerInterface::RemoveDevice(std::function<bool(const ciface::Core::Device*)> callback)
{
{
- std::lock_guard<std::mutex> lk(m_devices_mutex);
+ std::lock_guard lk(m_devices_mutex);
auto it = std::remove_if(m_devices.begin(), m_devices.end(), [&callback](const auto& dev) {
if (callback(dev.get()))
{
@@ -251,7 +252,7 @@ void ControllerInterface::UpdateInput()
// Don't block the UI or CPU thread (to avoid a short but noticeable frame drop)
if (m_devices_mutex.try_lock())
{
- std::lock_guard<std::mutex> lk(m_devices_mutex, std::adopt_lock);
+ std::lock_guard lk(m_devices_mutex, std::adopt_lock);
for (const auto& d : m_devices)
d->UpdateInput();
}
diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp
index d91a9e119e..15c403ca24 100644
--- a/Source/Core/InputCommon/ControllerInterface/Device.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp
@@ -180,7 +180,7 @@ bool DeviceQualifier::operator!=(const DeviceQualifier& devq) const
std::shared_ptr<Device> DeviceContainer::FindDevice(const DeviceQualifier& devq) const
{
- std::lock_guard<std::mutex> lk(m_devices_mutex);
+ std::lock_guard lk(m_devices_mutex);
for (const auto& d : m_devices)
{
if (devq == d.get())
@@ -192,7 +192,7 @@ std::shared_ptr<Device> DeviceContainer::FindDevice(const DeviceQualifier& devq)
std::vector<std::string> DeviceContainer::GetAllDeviceStrings() const
{
- std::lock_guard<std::mutex> lk(m_devices_mutex);
+ std::lock_guard lk(m_devices_mutex);
std::vector<std::string> device_strings;
DeviceQualifier device_qualifier;
@@ -208,7 +208,7 @@ std::vector<std::string> DeviceContainer::GetAllDeviceStrings() const
std::string DeviceContainer::GetDefaultDeviceString() const
{
- std::lock_guard<std::mutex> lk(m_devices_mutex);
+ std::lock_guard lk(m_devices_mutex);
if (m_devices.empty())
return "";
@@ -226,7 +226,7 @@ Device::Input* DeviceContainer::FindInput(std::string_view name, const Device* d
return inp;
}
- std::lock_guard<std::mutex> lk(m_devices_mutex);
+ std::lock_guard lk(m_devices_mutex);
for (const auto& d : m_devices)
{
Device::Input* const i = d->FindInput(name);
diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h
index e07f4fb16a..39ff6e9bb5 100644
--- a/Source/Core/InputCommon/ControllerInterface/Device.h
+++ b/Source/Core/InputCommon/ControllerInterface/Device.h
@@ -198,7 +198,7 @@ public:
DetectInput(u32 wait_ms, const std::vector<std::string>& device_strings) const;
protected:
- mutable std::mutex m_devices_mutex;
+ mutable std::recursive_mutex m_devices_mutex;
std::vector<std::shared_ptr<Device>> m_devices;
};
} // namespace Core