From 1a056a1ecfecee82d1243fc6e56ad22caff3c782 Mon Sep 17 00:00:00 2001 From: pixl Date: Sun, 12 Jul 2020 03:04:07 -0400 Subject: [PATCH] Add mutex for events on Receiver --- src/logid/Receiver.cpp | 2 ++ src/logid/Receiver.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/logid/Receiver.cpp b/src/logid/Receiver.cpp index 1efa1ea..bdfa178 100644 --- a/src/logid/Receiver.cpp +++ b/src/logid/Receiver.cpp @@ -31,6 +31,7 @@ Receiver::Receiver(std::string path) : dj::ReceiverMonitor(path), _path (path) void Receiver::addDevice(hidpp::DeviceConnectionEvent event) { + std::unique_lock lock(_devices_change); try { auto dev = _devices.find(event.index); if(dev != _devices.end()) { @@ -71,5 +72,6 @@ void Receiver::addDevice(hidpp::DeviceConnectionEvent event) void Receiver::removeDevice(hidpp::DeviceIndex index) { + std::unique_lock lock(_devices_change); _devices.erase(index); } \ No newline at end of file diff --git a/src/logid/Receiver.h b/src/logid/Receiver.h index 029c80c..15c0f9b 100644 --- a/src/logid/Receiver.h +++ b/src/logid/Receiver.h @@ -34,6 +34,7 @@ namespace logid void addDevice(backend::hidpp::DeviceConnectionEvent event) override; void removeDevice(backend::hidpp::DeviceIndex index) override; private: + std::mutex _devices_change; std::map> _devices; std::string _path; };