From f91c6ec6ad97a1ae61cffd3690dd92490f8c9bd5 Mon Sep 17 00:00:00 2001 From: HuangXW Date: Tue, 28 Mar 2023 12:28:05 +0000 Subject: [PATCH] =?UTF-8?q?fixed=200f3baaa=20from=20https://gitee.com/raul?= =?UTF-8?q?naruto/ability=5Fform=5Ffwk/pulls/671=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=BC=91=E7=9C=A0=E4=B8=80=E6=AE=B5=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=90=8E=E5=AE=9A=E7=82=B9=E5=88=B7=E6=96=B0=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HuangXW Change-Id: I3425cb810d5f0fc4b3e69c1478b6724412a6679e --- services/include/form_timer_mgr.h | 2 ++ services/src/form_timer_mgr.cpp | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/services/include/form_timer_mgr.h b/services/include/form_timer_mgr.h index 5c61fc675a..6add4edcff 100644 --- a/services/include/form_timer_mgr.h +++ b/services/include/form_timer_mgr.h @@ -350,6 +350,8 @@ private: } } CompareDynamicRefreshItem; + std::chrono::steady_clock::time_point GetBootTimeNs(); + mutable std::recursive_mutex intervalMutex_; mutable std::recursive_mutex updateAtMutex_; mutable std::recursive_mutex dynamicMutex_; diff --git a/services/src/form_timer_mgr.cpp b/services/src/form_timer_mgr.cpp index 437f6092bc..d1aa75c97f 100644 --- a/services/src/form_timer_mgr.cpp +++ b/services/src/form_timer_mgr.cpp @@ -37,6 +37,7 @@ const int REQUEST_UPDATE_AT_CODE = 1; const int REQUEST_LIMITER_CODE = 2; const int REQUEST_DYNAMIC_CODE = 3; const int SHIFT_BIT_LENGTH = 32; +const int NANO_TO_SECOND = 1000000000; const std::string FMS_TIME_SPEED = "fms.time_speed"; } // namespace @@ -898,7 +899,7 @@ bool FormTimerMgr::UpdateAtTimerAlarm() if (currentUpdateAtWantAgent_ != nullptr) { ClearUpdateAtTimerResource(); } - auto timeSinceEpoch = std::chrono::steady_clock::now().time_since_epoch(); + auto timeSinceEpoch = GetBootTimeNs().time_since_epoch(); int64_t timeInSec = std::chrono::duration_cast(timeSinceEpoch).count(); HILOG_DEBUG("timeInSec: %{public}" PRId64 ".", timeInSec); int64_t nextTime = timeInSec + (selectTime - currentTime); @@ -917,6 +918,19 @@ bool FormTimerMgr::UpdateAtTimerAlarm() return true; } +std::chrono::steady_clock::time_point FormTimerMgr::GetBootTimeNs() +{ + int64_t timeNow = -1; + struct timespec tv {}; + if (clock_gettime(CLOCK_BOOTTIME, &tv) < 0) { + HILOG_WARN("Get bootTime by clock_gettime failed, use std::chrono::steady_clock"); + return std::chrono::steady_clock::now(); + } + timeNow = tv.tv_sec * NANO_TO_SECOND + tv.tv_nsec; + std::chrono::steady_clock::time_point tp_epoch ((std::chrono::nanoseconds(timeNow))); + return tp_epoch; +} + /** * @brief Get WantAgent. * @param updateAtTime The next update time. -- Gitee