Skip to content

Commit cc3ce6a

Browse files
author
NoahAndrews
committed
Erase removed devices from heartbeatsRunning
1 parent 17ba762 commit cc3ce6a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/canWrapper.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,17 @@ void heartbeatsWatchdog() {
646646
while (true) {
647647
std::this_thread::sleep_for (std::chrono::seconds(1));
648648

649+
{
650+
// Erase removed CAN buses from heartbeatsRunning
651+
std::scoped_lock lock{watchdogMtx, canDevicesMtx};
652+
for(int i = 0; i < heartbeatsRunning.size(); i++) {
653+
auto deviceIterator = canDeviceMap.find(heartbeatsRunning[i]);
654+
if (deviceIterator == canDeviceMap.end()) {
655+
heartbeatsRunning.erase(heartbeatsRunning.begin() + i);
656+
}
657+
}
658+
}
659+
649660
std::scoped_lock lock{watchdogMtx};
650661

651662
if (heartbeatsRunning.size() < 1) { break; }

0 commit comments

Comments
 (0)