From 94f0065a4d4d46a43aca6481db727adb85fd264e Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sat, 5 Jun 2021 12:14:58 -0500 Subject: [PATCH] fix beaconSenders locking --- src/client.cpp | 17 +++++++++++------ src/clientimpl.h | 14 +++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index d4d83e4..4423034 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -447,13 +447,16 @@ void Context::Pvt::onBeacon(const UDPManager::Beacon& msg) epicsTimeStamp now; epicsTimeGetCurrent(&now); - auto it = beaconSenders.find(msg.src); - if(it!=beaconSenders.end() && msg.guid==it->second.guid) { - it->second.lastRx = now; - return; - } + { + Guard G(pokeLock); + auto it = beaconSenders.find(msg.src); + if(it!=beaconSenders.end() && msg.guid==it->second.guid) { + it->second.lastRx = now; + return; + } - beaconSenders.emplace(msg.src, BTrack{msg.guid, now}); + beaconSenders.emplace(msg.src, BTrack{msg.guid, now}); + } log_debug_printf(io, "%s New server %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s\n", msg.src.tostring().c_str(), @@ -774,6 +777,8 @@ void Context::Pvt::tickBeaconClean() epicsTimeStamp now; epicsTimeGetCurrent(&now); + Guard G(pokeLock); + auto it = beaconSenders.begin(); while(it!=beaconSenders.end()) { auto cur = it++; diff --git a/src/clientimpl.h b/src/clientimpl.h index 0b71a7b..17a9c88 100644 --- a/src/clientimpl.h +++ b/src/clientimpl.h @@ -186,11 +186,17 @@ struct Context::Pvt evsocket searchTx; uint16_t searchRxPort; - // poked from both TCP and UDP workers + // poked and beaconSenders from both TCP and UDP workers epicsMutex pokeLock; epicsTimeStamp lastPoke{}; bool poked = false; + struct BTrack { + std::array guid; + epicsTimeStamp lastRx; + }; + std::map beaconSenders; + std::vector searchMsg; // search destination address and whether to set the unicast flag @@ -212,12 +218,6 @@ struct Context::Pvt const evevent searchRx; const evevent searchTimer; - struct BTrack { - std::array guid; - epicsTimeStamp lastRx; - }; - std::map beaconSenders; - // beacon handling done on UDP worker. // we keep a ref here as long as beaconCleaner is in use UDPManager manager;