From 304f67f0d2907f66f40f5c3cb497b05e185d5bb7 Mon Sep 17 00:00:00 2001 From: zhutianyi Date: Wed, 13 Jul 2022 14:20:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhutianyi --- services/timer/include/timer_manager.h | 1 + services/timer/src/timer_manager.cpp | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/services/timer/include/timer_manager.h b/services/timer/include/timer_manager.h index 09fbc64..397bbcc 100644 --- a/services/timer/include/timer_manager.h +++ b/services/timer/include/timer_manager.h @@ -93,6 +93,7 @@ private: std::chrono::steady_clock::time_point ConvertToElapsed(std::chrono::milliseconds when, int type); std::chrono::steady_clock::time_point GetBootTimeNs(); void CallbackAlarmIfNeed(std::shared_ptr alarm); + bool StopTimerInner(uint64_t timerNumber, bool needDestroy); void RemoveProxy(uint64_t timerNumber, int32_t uid); std::map> timerEntryMap_; diff --git a/services/timer/src/timer_manager.cpp b/services/timer/src/timer_manager.cpp index e54cf04..ab6bb1a 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -126,23 +126,15 @@ bool TimerManager::StartTimer(uint64_t timerNumber, uint64_t triggerTime) bool TimerManager::StopTimer(uint64_t timerNumber) { - TIME_HILOGD(TIME_MODULE_SERVICE, "start."); - std::lock_guard lock(entryMapMutex_); - auto it = timerEntryMap_.find(timerNumber); - if (it == timerEntryMap_.end()) { - TIME_HILOGD(TIME_MODULE_SERVICE, "end."); - return false; - } - RemoveHandler(timerNumber); - if (it->second) { - int32_t uid = it->second->uid; - RemoveProxy(timerNumber, uid); - } - TIME_HILOGD(TIME_MODULE_SERVICE, "end."); - return true; + return StopTimerInner(timerNumber, false); } bool TimerManager::DestroyTimer(uint64_t timerNumber) +{ + return StopTimerInner(timerNumber, true); +} + +bool TimerManager::StopTimerInner(uint64_t timerNumber, bool needDestroy) { TIME_HILOGD(TIME_MODULE_SERVICE, "start id: %{public}" PRId64 "", timerNumber); std::lock_guard lock(entryMapMutex_); @@ -156,7 +148,9 @@ bool TimerManager::DestroyTimer(uint64_t timerNumber) int32_t uid = it->second->uid; RemoveProxy(timerNumber, uid); } - timerEntryMap_.erase(it); + if (needDestroy) { + timerEntryMap_.erase(it); + } TIME_HILOGD(TIME_MODULE_SERVICE, "end."); return true; }