mirror of
https://github.com/espressif/openthread.git
synced 2026-08-25 19:59:51 +00:00
[timer] add helper methods for common timer use patterns and simplify code (#4243)
This commit adds helper methods in `Timer` class which cover commonly repeated use patterns by other modules. Method `FireAt()` allows a timer to be started with a given fire time. `FireAtIfEarlier()` (re-)schedules the timer with a given a fire time only if the timer is not running or if the new given fire time is earlier than the current fire time. Modules mle, coap, ip6-mpl, joiner-router, dns-clinet, and sntp-client are updated to use the new methods.
This commit is contained in:
committed by
Jonathan Hui
parent
ecf7a7050f
commit
aab693f9c3
@@ -633,6 +633,16 @@ int TestTimerTime(void)
|
||||
VerifyOrQuit((t1 >= t2), "Time >= failed.\n");
|
||||
VerifyOrQuit(t1 - t2 == duration, "Time difference failed\n");
|
||||
|
||||
t2 = t1.GetDistantFuture();
|
||||
VerifyOrQuit((t1 < t2), "GetDistanceFuture() failed\n");
|
||||
t2 += 1;
|
||||
VerifyOrQuit(!(t1 < t2), "GetDistanceFuture() failed\n");
|
||||
|
||||
t2 = t1.GetDistantPast();
|
||||
VerifyOrQuit((t1 > t2), "GetDistantPast() failed\n");
|
||||
t2 -= 1;
|
||||
VerifyOrQuit(!(t1 > t2), "GetDistantPast() failed\n");
|
||||
|
||||
printf("--> PASSED\n");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user