[netdata] update StartContextReuseTimer() to start time if not running (#8859)

This commit contains two changes to `StartContextReuseTimer()`:
- We now start the context reuse timer only if the timer is not already
  scheduled (`mContextLastUsed` will be non-zero when reuse timer
  is already scheduled).
- The `mTimer` (which is used as a periodic timer) is only started
  if it is not already running.
This commit is contained in:
Abtin Keshavarzian
2023-03-13 13:20:06 -07:00
committed by GitHub
parent b2e813429b
commit c81e8d3fd0
+12 -1
View File
@@ -1003,6 +1003,11 @@ void Leader::FreeContextId(uint8_t aContextId)
void Leader::StartContextReuseTimer(uint8_t aContextId)
{
// Start the reuse timer for `aContextId` if it is not already
// scheduled.
VerifyOrExit(mContextLastUsed[aContextId - kMinContextId].GetValue() == 0);
mContextLastUsed[aContextId - kMinContextId] = TimerMilli::GetNow();
if (mContextLastUsed[aContextId - kMinContextId].GetValue() == 0)
@@ -1010,7 +1015,13 @@ void Leader::StartContextReuseTimer(uint8_t aContextId)
mContextLastUsed[aContextId - kMinContextId].SetValue(1);
}
mTimer.Start(kStateUpdatePeriod);
if (!mTimer.IsRunning())
{
mTimer.Start(kStateUpdatePeriod);
}
exit:
return;
}
void Leader::StopContextReuseTimer(uint8_t aContextId) { mContextLastUsed[aContextId - kMinContextId].SetValue(0); }