summaryrefslogtreecommitdiff
path: root/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp
diff options
context:
space:
mode:
authorYu Shan <shanyu@google.com>2022-08-10 21:20:08 +0000
committerYu Shan <shanyu@google.com>2022-08-12 17:39:35 +0000
commit8e532e6d8213378115896037659a2b5793b64d27 (patch)
tree9d404d4cf44b91946ee3309e0ca692b0a7717f13 /automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp
parent604a89d8ff12dd4de795f8aa1b9d2c07724e3ef4 (diff)
Use a different timesource in recurrent timer.
Previously we used elapsedRealtimeNanos in recurrent timer which will still go even if the system is in deep sleep. This causes all the events "happened" during suspension to be replayed immediately after the wake up, which causes a spam of messages. uptimeNanos meanwhile, does not go if the system is in sleep, so we use that instead. Test: atest VehicleHalVehicleUtilsTest Bug: 235262127 Change-Id: Ib67c2e2251af3231cefd875416d5bcb15953ba5e Merged-In: Ib67c2e2251af3231cefd875416d5bcb15953ba5e (cherry picked from commit 5e508737934feb595c841430f41b5edb1d1925d5)
Diffstat (limited to 'automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp')
-rw-r--r--automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp b/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp
index 8521c4db7c..2eca6b7a17 100644
--- a/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp
+++ b/automotive/vehicle/aidl/impl/utils/common/src/RecurrentTimer.cpp
@@ -48,7 +48,7 @@ void RecurrentTimer::registerTimerCallback(int64_t intervalInNano,
std::scoped_lock<std::mutex> lockGuard(mLock);
// Aligns the nextTime to multiply of interval.
- int64_t nextTime = ceil(elapsedRealtimeNano() / intervalInNano) * intervalInNano;
+ int64_t nextTime = ceil(uptimeNanos() / intervalInNano) * intervalInNano;
std::unique_ptr<CallbackInfo> info = std::make_unique<CallbackInfo>();
info->callback = callback;
@@ -128,7 +128,7 @@ void RecurrentTimer::loop() {
}
// The first element is the nearest next event.
int64_t nextTime = mCallbackQueue[0]->nextTime;
- int64_t now = elapsedRealtimeNano();
+ int64_t now = uptimeNanos();
if (nextTime > now) {
interval = nextTime - now;
} else {
@@ -146,7 +146,7 @@ void RecurrentTimer::loop() {
{
ScopedLockAssertion lockAssertion(mLock);
- int64_t now = elapsedRealtimeNano();
+ int64_t now = uptimeNanos();
while (mCallbackQueue.size() > 0) {
int64_t nextTime = mCallbackQueue[0]->nextTime;
if (nextTime > now) {