diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2016-06-25 21:46:39 +0200 |
|---|---|---|
| committer | Léo Lam <leo@innovatetechnologi.es> | 2016-06-25 21:46:39 +0200 |
| commit | 8678133e8746fdc20f7d012005ebf2db370ddccc (patch) | |
| tree | ccca4a186be0e8ee93c733c8d2315e5dd0c20db2 /Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | |
| parent | afa202738e54652e98e8388a5c6a1541d750e3e6 (diff) | |
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.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
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 <mutex> + #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<std::mutex> 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<ciface::Core::Device> device) { std::lock_guard<std::mutex> 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<std::mutex> lk(m_devices_mutex); - for (ciface::Core::Device* d : m_devices) + for (const auto& d : m_devices) d->UpdateInput(); } |
