From d15430fb17b4258e513abf064fdfe506f8aab3a6 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 30 Dec 2020 10:20:10 -0800 Subject: [PATCH] fix poke race poke()d from both UDP (tickSearch()) and TCP workers (*Builder::exec()) --- src/client.cpp | 26 ++++++++++++++++---------- src/clientimpl.h | 2 ++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 6e4c511..4836689 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -415,24 +415,27 @@ void Context::Pvt::close() void Context::Pvt::poke(bool force) { - if(poked) - return; + { + Guard G(pokeLock); + if(poked) + return; - epicsTimeStamp now{}; + epicsTimeStamp now{}; - double age = -1.0; - if(!force && (epicsTimeGetCurrent(&now) || (age=epicsTimeDiffInSeconds(&now, &lastPoke))<30.0)) { - log_debug_printf(setup, "Ignoring hurryUp() age=%.1f sec\n", age); - return; + double age = -1.0; + if(!force && (epicsTimeGetCurrent(&now) || (age=epicsTimeDiffInSeconds(&now, &lastPoke))<30.0)) { + log_debug_printf(setup, "Ignoring hurryUp() age=%.1f sec\n", age); + return; + } + lastPoke = now; + poked = true; } - lastPoke = now; log_debug_printf(setup, "hurryUp()%s\n", ""); timeval immediate{0,0}; if(event_add(searchTimer.get(), &immediate)) throw std::runtime_error("Unable to schedule searchTimer"); - poked = true; } void Context::Pvt::onBeacon(const UDPManager::Beacon& msg) @@ -611,7 +614,10 @@ void Context::Pvt::onSearchS(evutil_socket_t fd, short evt, void *raw) void Context::Pvt::tickSearch() { - poked = false; + { + Guard G(pokeLock); + poked = false; + } auto idx = currentBucket; currentBucket = (currentBucket+1u)%searchBuckets.size(); diff --git a/src/clientimpl.h b/src/clientimpl.h index d5ae66b..fb2d0e2 100644 --- a/src/clientimpl.h +++ b/src/clientimpl.h @@ -185,6 +185,8 @@ struct Context::Pvt evsocket searchTx; uint16_t searchRxPort; + // poked from both TCP and UDP workers + epicsMutex pokeLock; epicsTimeStamp lastPoke{}; bool poked = false;