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; }