Ensure lock is held when accessing open devices
parent
f254ee2515
commit
8d21b98ac6
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue