From cd9e93133b90da3dd02a6a0d955b9aa3527056de Mon Sep 17 00:00:00 2001 From: liweifeng Date: Wed, 22 Feb 2023 19:55:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8D=A1=E7=89=87=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E5=88=B7=E6=96=B0=E6=97=B6=E9=97=B4=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liweifeng Change-Id: Ifa0ebefe8619696653810b675226f972d8cae974 --- services/include/form_timer.h | 4 ++-- services/src/form_timer_mgr.cpp | 8 +++++--- services/src/form_util.cpp | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/services/include/form_timer.h b/services/include/form_timer.h index 974d79d6da..33d6238f2b 100644 --- a/services/include/form_timer.h +++ b/services/include/form_timer.h @@ -71,7 +71,7 @@ public: type = UpdateType::TYPE_INTERVAL_CHANGE; } - FormTimer(int64_t id, long repeatTime, int32_t uId = 0) + FormTimer(int64_t id, long repeatTime, int64_t currentTime, int32_t uId = 0) { formId = id; userId = uId; @@ -80,7 +80,7 @@ public: min = -1; isUpdateAt = false; isCountTimer = true; - refreshTime = INT64_MAX; + refreshTime = currentTime; type = UpdateType::TYPE_INTERVAL_CHANGE; } diff --git a/services/src/form_timer_mgr.cpp b/services/src/form_timer_mgr.cpp index e64833eda0..c504a9c938 100644 --- a/services/src/form_timer_mgr.cpp +++ b/services/src/form_timer_mgr.cpp @@ -88,7 +88,7 @@ bool FormTimerMgr::AddFormTimer(int64_t formId, long updateDuration, int32_t use auto duration = updateDuration / timeSpeed_; HILOG_INFO("%{public}s formId:%{public}s duration:%{public}s", __func__, std::to_string(formId).c_str(), std::to_string(duration).c_str()); - FormTimer timerTask(formId, duration, userId); + FormTimer timerTask(formId, duration, FormUtil::GetCurrentNanosecond() / Constants::TIME_1000000, userId); return AddFormTimer(timerTask); } /** @@ -300,7 +300,7 @@ bool FormTimerMgr::AtTimerToIntervalTimer(int64_t formId, const FormTimerCfg &ti } targetItem.refreshTask.isUpdateAt = false; targetItem.refreshTask.period = timerCfg.updateDuration; - targetItem.refreshTask.refreshTime = INT64_MAX; + targetItem.refreshTask.refreshTime = FormUtil::GetCurrentNanosecond() / Constants::TIME_1000000; if (!AddIntervalTimer(targetItem.refreshTask)) { HILOG_ERROR("%{public}s, failed to add interval timer", __func__); return false; @@ -811,7 +811,9 @@ void FormTimerMgr::OnIntervalTimeOut() int64_t currentTime = FormUtil::GetCurrentNanosecond() / Constants::TIME_1000000; for (auto &intervalPair : intervalTimerTasks_) { FormTimer &intervalTask = intervalPair.second; - if ((intervalTask.refreshTime == INT64_MAX || (currentTime - intervalTask.refreshTime) >= intervalTask.period || + HILOG_INFO("intervalTask form id is %{public}" PRId64 ", period is %{public}" PRId64 "", + intervalTask.formId, intervalTask.period); + if (((currentTime - intervalTask.refreshTime) >= intervalTask.period || std::abs((currentTime - intervalTask.refreshTime) - intervalTask.period) < Constants::ABS_TIME) && intervalTask.isEnable && refreshLimiter_.IsEnableRefresh(intervalTask.formId)) { intervalTask.refreshTime = currentTime; diff --git a/services/src/form_util.cpp b/services/src/form_util.cpp index 486203214b..f2b547e17c 100644 --- a/services/src/form_util.cpp +++ b/services/src/form_util.cpp @@ -140,7 +140,7 @@ int64_t FormUtil::GetCurrentNanosecond() struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0; - clock_gettime(CLOCK_REALTIME, &ts); + clock_gettime(CLOCK_MONOTONIC, &ts); return (ts.tv_sec * SEC_TO_NANOSEC + ts.tv_nsec); } /** -- Gitee