diff --git a/services/include/form_timer.h b/services/include/form_timer.h index 974d79d6da3458db7e4149323e2d78c86cf5064e..33d6238f2bad70f7aaafc06dfd944d546ea4f86d 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 e64833eda0d6f12f4e8e3102266b3577bd631744..c504a9c938c1f291e5b4d35273fe3a1c1777837d 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 486203214ba0caac2753a5666ed0d9a99d4f3bcc..f2b547e17c8ff05fc07c5b93ddc42533a5234eec 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); } /**