From 92865d3138309c2f367b83d1a758d65e4499b43d Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Fri, 11 Oct 2024 09:50:05 +0800 Subject: [PATCH] alarm recovery Signed-off-by: wangzhaohao --- .../src/dbstorage/device_profile_storage.cpp | 11 +++++++--- .../src/devicemanager/dp_device_manager.cpp | 1 + .../profile_event_handler.cpp | 1 + .../subscribemanager/subscribe_manager.cpp | 1 + .../kvadapter/kv_adapter.cpp | 22 ++++++++++++------- .../kvadapter/switch_adapter.cpp | 1 + services/core/src/utils/profile_cache.cpp | 5 ++++- 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/old/services/core/src/dbstorage/device_profile_storage.cpp b/old/services/core/src/dbstorage/device_profile_storage.cpp index 1b5623ea..44430385 100644 --- a/old/services/core/src/dbstorage/device_profile_storage.cpp +++ b/old/services/core/src/dbstorage/device_profile_storage.cpp @@ -54,10 +54,14 @@ void DeviceProfileStorage::SetOptions(const Options& options) bool DeviceProfileStorage::RegisterKvStoreInitCallback(const KvStoreInitCallback& callback) { - if (kvStoreInitCallback_ != nullptr) { - HILOGE("callback is not null"); - return false; + { + std::shared_lock readLock(storageLock_); + if (kvStoreInitCallback_ != nullptr) { + HILOGE("callback is not null"); + return false; + } } + std::unique_lock writeLock(storageLock_); kvStoreInitCallback_ = callback; return true; } @@ -126,6 +130,7 @@ int32_t DeviceProfileStorage::UnRegisterSyncCallback() StorageInitStatus DeviceProfileStorage::GetInitStatus() { + std::shared_lock readLock(storageLock_); HILOGI("GetInitStatus %{public}d", static_cast(initStatus_.load())); return initStatus_; } diff --git a/old/services/core/src/devicemanager/dp_device_manager.cpp b/old/services/core/src/devicemanager/dp_device_manager.cpp index 5ed5cbe9..a46b2215 100644 --- a/old/services/core/src/devicemanager/dp_device_manager.cpp +++ b/old/services/core/src/devicemanager/dp_device_manager.cpp @@ -53,6 +53,7 @@ IMPLEMENT_SINGLE_INSTANCE(DpDeviceManager); bool DpDeviceManager::Init() { + std::lock_guard autoLock(deviceLock_); initCallback_ = std::make_shared(); stateCallback_ = std::make_shared(); devTrustChangeCallback_ = std::make_shared(); diff --git a/old/services/core/src/subscribemanager/profile_event_handler.cpp b/old/services/core/src/subscribemanager/profile_event_handler.cpp index d7488973..92ceb1f6 100644 --- a/old/services/core/src/subscribemanager/profile_event_handler.cpp +++ b/old/services/core/src/subscribemanager/profile_event_handler.cpp @@ -28,6 +28,7 @@ const std::string TAG = "ProfileEventHandler"; bool ProfileEventHandler::Init() { auto runner = AppExecFwk::EventRunner::Create(handlerName_); + std::lock_guard autoLock(notifierLock_); eventHandler_ = std::make_shared(runner); if (eventHandler_ == nullptr) { return false; diff --git a/old/services/core/src/subscribemanager/subscribe_manager.cpp b/old/services/core/src/subscribemanager/subscribe_manager.cpp index a3bca60b..48513516 100644 --- a/old/services/core/src/subscribemanager/subscribe_manager.cpp +++ b/old/services/core/src/subscribemanager/subscribe_manager.cpp @@ -39,6 +39,7 @@ IMPLEMENT_SINGLE_INSTANCE(SubscribeManager); bool SubscribeManager::Init() { + std::lock_guard autoLock(handlerLock_); subscriberDeathRecipient_ = sptr( new (std::nothrow) SubscriberDeathRecipient); if (subscriberDeathRecipient_ == nullptr) { diff --git a/services/core/src/persistenceadapter/kvadapter/kv_adapter.cpp b/services/core/src/persistenceadapter/kvadapter/kv_adapter.cpp index c0a2e8bd..1e78e49c 100644 --- a/services/core/src/persistenceadapter/kvadapter/kv_adapter.cpp +++ b/services/core/src/persistenceadapter/kvadapter/kv_adapter.cpp @@ -59,18 +59,24 @@ KVAdapter::~KVAdapter() int32_t KVAdapter::Init() { - HILOGI("Init kvAdapter, storeId: %{public}s", storeId_.storeId.c_str()); + { + std::lock_guard lock(kvAdapterMutex_); + HILOGI("Init kvAdapter, storeId: %{public}s", storeId_.storeId.c_str()); + } int32_t tryTimes = MAX_INIT_RETRY_TIMES; int64_t beginTime = GetTickCount(); while (tryTimes > 0) { DistributedKv::Status status = GetKvStorePtr(dataType_); - if (kvStorePtr_ && status == DistributedKv::Status::SUCCESS) { - int64_t endTime = GetTickCount(); - HILOGI("Init KvStorePtr Success, spend %{public}" PRId64 " ms", endTime - beginTime); - RegisterSyncCompletedListener(); - RegisterDataChangeListener(); - RegisterDeathListener(); - return DP_SUCCESS; + { + std::lock_guard lock(kvAdapterMutex_); + if (kvStorePtr_ && status == DistributedKv::Status::SUCCESS) { + int64_t endTime = GetTickCount(); + HILOGI("Init KvStorePtr Success, spend %{public}" PRId64 " ms", endTime - beginTime); + RegisterSyncCompletedListener(); + RegisterDataChangeListener(); + RegisterDeathListener(); + return DP_SUCCESS; + } } HILOGI("CheckKvStore, left times: %{public}d, status: %{public}d", tryTimes, status); if (status == DistributedKv::Status::STORE_META_CHANGED) { diff --git a/services/core/src/persistenceadapter/kvadapter/switch_adapter.cpp b/services/core/src/persistenceadapter/kvadapter/switch_adapter.cpp index a3523b5f..9200cd6a 100644 --- a/services/core/src/persistenceadapter/kvadapter/switch_adapter.cpp +++ b/services/core/src/persistenceadapter/kvadapter/switch_adapter.cpp @@ -32,6 +32,7 @@ namespace { void SwitchAdapter::Init() { HILOGI("called"); + std::lock_guard lock(switchAdapterMutex_); observer_ = std::make_shared(EMPTY_STRING); } diff --git a/services/core/src/utils/profile_cache.cpp b/services/core/src/utils/profile_cache.cpp index 269479e7..f1ab1269 100644 --- a/services/core/src/utils/profile_cache.cpp +++ b/services/core/src/utils/profile_cache.cpp @@ -43,7 +43,10 @@ int32_t ProfileCache::Init() ContentSensorManagerUtils::GetInstance().ObtainDeviceDataSyncMode(); RefreshProfileCache(); SwitchProfileManager::GetInstance().RefreshLocalSwitchProfile(); - syncListenerDeathRecipient_ = sptr(new SyncSubscriberDeathRecipient); + { + std::lock_guard lock(syncListenerMutex_); + syncListenerDeathRecipient_ = sptr(new SyncSubscriberDeathRecipient); + } std::vector allOnlineDeviceInfo; int32_t res = DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(DP_PKG_NAME, "", allOnlineDeviceInfo); -- Gitee