diff --git a/interfaces/inner_api/include/time_service_client.h b/interfaces/inner_api/include/time_service_client.h index 738898a167db1c25a851f5b8140ddb4a7a9218c0..4073f3cebe8663e7b2afc99319d54f4cc61db25d 100644 --- a/interfaces/inner_api/include/time_service_client.h +++ b/interfaces/inner_api/include/time_service_client.h @@ -485,6 +485,7 @@ private: TIME_API std::mutex recoverTimerInfoLock_; std::mutex proxyLock_; std::mutex deathLock_; + sptr listener_; sptr timeServiceProxy_; sptr deathRecipient_ {}; }; diff --git a/interfaces/inner_api/src/time_service_client.cpp b/interfaces/inner_api/src/time_service_client.cpp index 347b865cef1459835e50a24162fe8b0c4ff549fe..cdbf8b15b4e3ce64ff180d472fb96e77f6ab74f8 100644 --- a/interfaces/inner_api/src/time_service_client.cpp +++ b/interfaces/inner_api/src/time_service_client.cpp @@ -53,9 +53,15 @@ void TimeServiceClient::TimeServiceListener::OnAddSystemAbility( TIME_HILOGE(TIME_MODULE_CLIENT, "New TimerCallback failed"); return; } - std::lock_guard lock(TimeServiceClient::GetInstance()->recoverTimerInfoLock_); - auto iter = TimeServiceClient::GetInstance()->recoverTimerInfoMap_.begin(); - for (; iter != TimeServiceClient::GetInstance()->recoverTimerInfoMap_.end(); iter++) { + std::map> recoverTimer; + { + auto timerServiceClient = TimeServiceClient::GetInstance(); + std::lock_guard lock(timerServiceClient->recoverTimerInfoLock_); + recoverTimer = timerServiceClient->recoverTimerInfoMap_; + } + TIME_HILOGI(TIME_MODULE_CLIENT, "recTimer cnt:%{public}zu", recoverTimer.size()); + auto iter = recoverTimer.begin(); + for (; iter != recoverTimer.end(); iter++) { auto timerId = iter->first; proxy->CreateTimer(iter->second->timerInfo, timerCallbackInfoObject, timerId); if (iter->second->state == 1) { @@ -64,7 +70,7 @@ void TimeServiceClient::TimeServiceListener::OnAddSystemAbility( } return; } else { - TIME_HILOGE(TIME_MODULE_SERVICE, "Id is not TIME_SERVICE_ID"); + TIME_HILOGE(TIME_MODULE_CLIENT, "Id is not TIME_SERVICE_ID"); return; } } @@ -93,6 +99,7 @@ sptr TimeServiceClient::GetInstance() std::lock_guard autoLock(instanceLock_); if (instance_ == nullptr) { instance_ = new TimeServiceClient; + listener_ = new (std::nothrow) TimeServiceListener(); } } return instance_; @@ -100,7 +107,7 @@ sptr TimeServiceClient::GetInstance() bool TimeServiceClient::SubscribeSA(sptr systemAbilityManager) { - auto timeServiceListener = new (std::nothrow) TimeServiceListener(); + auto timeServiceListener = listener_; if (timeServiceListener == nullptr) { TIME_HILOGE(TIME_MODULE_CLIENT, "Get timeServiceListener failed."); return false;