fix poke race

poke()d from both UDP (tickSearch()) and TCP workers (*Builder::exec())
This commit is contained in:
Michael Davidsaver
2020-12-30 10:20:10 -08:00
parent b9b1a60954
commit d15430fb17
2 changed files with 18 additions and 10 deletions
+16 -10
View File
@@ -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();