Ensure lock is held when accessing open devices

pull/7/head
Paul Hollinsky 2020-08-06 17:01:24 -04:00
parent f254ee2515
commit 8d21b98ac6
1 changed files with 2 additions and 0 deletions

View File

@ -275,6 +275,7 @@ void searchForDevices() {
return; return;
auto canMessage = std::static_pointer_cast<icsneo::CANMessage>(message); auto canMessage = std::static_pointer_cast<icsneo::CANMessage>(message);
const OpenDevice* openDevice = nullptr; const OpenDevice* openDevice = nullptr;
std::lock_guard<std::mutex> lg(openDevicesMutex);
for(const auto& dev : openDevices) { for(const auto& dev : openDevices) {
if(dev.device->getSerial() == serial) { if(dev.device->getSerial() == serial) {
openDevice = &dev; openDevice = &dev;
@ -482,6 +483,7 @@ int main(int argc, char** argv) {
msg->data = currentPosition; msg->data = currentPosition;
currentPosition += msg->length; currentPosition += msg->length;
bool sent = false; bool sent = false;
std::lock_guard<std::mutex> lg(openDevicesMutex);
for(auto& dev : openDevices) { for(auto& dev : openDevices) {
for(auto& netifPair : dev.interfaces) { for(auto& netifPair : dev.interfaces) {
if(netifPair.second->getKernelHandle() != msg->netid) if(netifPair.second->getKernelHandle() != msg->netid)