From 8678133e8746fdc20f7d012005ebf2db370ddccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 25 Jun 2016 21:46:39 +0200 Subject: ControllerInterface: Switch to std::shared_ptr Small cleanup by using std::shared_ptr and getting rid of ciface.Devices() which just returned the m_devices (which defeats the point of making m_devices protected). Incidentally, this should make the code safer when we have different threads accessing devices in the future (for hotplug?). A lot of code use Device references directly so there is no easy way to remove FindDevice() and make those unique_ptrs. --- .../ControllerInterface/ControllerInterface.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 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 b36387162d..cbf2c4dfbb 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -2,8 +2,10 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include "InputCommon/ControllerInterface/ControllerInterface.h" +#include + #include "Common/Thread.h" +#include "InputCommon/ControllerInterface/ControllerInterface.h" #ifdef CIFACE_USE_XINPUT #include "InputCommon/ControllerInterface/XInput/XInput.h" @@ -106,14 +108,11 @@ void ControllerInterface::Shutdown() std::lock_guard lk(m_devices_mutex); - for (ciface::Core::Device* d : m_devices) + for (const auto& d : m_devices) { // Set outputs to ZERO before destroying device for (ciface::Core::Device::Output* o : d->Outputs()) o->SetState(0); - - // Delete device - delete d; } m_devices.clear(); @@ -141,10 +140,10 @@ void ControllerInterface::Shutdown() m_is_init = false; } -void ControllerInterface::AddDevice(ciface::Core::Device* device) +void ControllerInterface::AddDevice(std::shared_ptr device) { std::lock_guard lk(m_devices_mutex); - m_devices.push_back(device); + m_devices.emplace_back(std::move(device)); } // @@ -155,7 +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) + for (const auto& d : m_devices) d->UpdateInput(); } -- cgit v1.2.3