From c81e8d3fd013168630fe8a446a5c448a6f1438f6 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 13 Mar 2023 13:20:06 -0700 Subject: [PATCH] [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. --- src/core/thread/network_data_leader_ftd.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/thread/network_data_leader_ftd.cpp b/src/core/thread/network_data_leader_ftd.cpp index e85946a90..a2dec390e 100644 --- a/src/core/thread/network_data_leader_ftd.cpp +++ b/src/core/thread/network_data_leader_ftd.cpp @@ -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); }