Skip to content

Commit

Permalink
[mdns] use NextFireTime for scheduling timers (openthread#10371)
Browse files Browse the repository at this point in the history
  • Loading branch information
abtink authored Jun 13, 2024
1 parent fa71a8a commit 6bc3b4d
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/core/net/mdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4111,11 +4111,10 @@ void Core::MultiPacketRxMessages::AddNew(OwnedPtr<RxMessage> &aRxMessagePtr)

void Core::MultiPacketRxMessages::HandleTimer(void)
{
TimeMilli now = TimerMilli::GetNow();
TimeMilli nextTime = now.GetDistantFuture();
NextFireTime nextTime;
OwningList<RxMsgEntry> expiredEntries;

mRxMsgEntries.RemoveAllMatching(ExpireChecker(now), expiredEntries);
mRxMsgEntries.RemoveAllMatching(ExpireChecker(nextTime.GetNow()), expiredEntries);

for (RxMsgEntry &expiredEntry : expiredEntries)
{
Expand All @@ -4124,13 +4123,10 @@ void Core::MultiPacketRxMessages::HandleTimer(void)

for (const RxMsgEntry &msgEntry : mRxMsgEntries)
{
nextTime = Min(nextTime, msgEntry.mProcessTime);
nextTime.UpdateIfEarlier(msgEntry.mProcessTime);
}

if (nextTime != now.GetDistantFuture())
{
mTimer.FireAtIfEarlier(nextTime);
}
mTimer.FireAtIfEarlier(nextTime);
}

void Core::MultiPacketRxMessages::Clear(void)
Expand Down Expand Up @@ -4254,20 +4250,16 @@ void Core::TxMessageHistory::CalculateHash(const Message &aMessage, Hash &aHash)

void Core::TxMessageHistory::HandleTimer(void)
{
TimeMilli now = TimerMilli::GetNow();
TimeMilli nextTime = now.GetDistantFuture();
NextFireTime nextTime;

mHashEntries.RemoveAndFreeAllMatching(ExpireChecker(now));
mHashEntries.RemoveAndFreeAllMatching(ExpireChecker(nextTime.GetNow()));

for (const HashEntry &entry : mHashEntries)
{
nextTime = Min(nextTime, entry.mExpireTime);
nextTime.UpdateIfEarlier(entry.mExpireTime);
}

if (nextTime != now.GetDistantFuture())
{
mTimer.FireAtIfEarlier(nextTime);
}
mTimer.FireAtIfEarlier(nextTime);
}

template <typename CacheType, typename BrowserResolverType>
Expand Down

0 comments on commit 6bc3b4d

Please sign in to comment.