From d4194e4cf95aef7b53799468ebfdac85155ce3eb Mon Sep 17 00:00:00 2001 From: li_junsong Date: Thu, 31 Oct 2024 16:51:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=8D=A1=E6=AD=BB?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=87=8F=E5=B0=8F=E6=8C=81=E9=94=81=E8=8C=83?= =?UTF-8?q?=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li_junsong --- .../inner_api/include/time_service_client.h | 1 + .../inner_api/src/time_service_client.cpp | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/interfaces/inner_api/include/time_service_client.h b/interfaces/inner_api/include/time_service_client.h index 738898a1..4073f3ce 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 347b865c..cdbf8b15 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; -- Gitee