From c2e4ca3a50d096d063860492f737f16eb3d4c55a Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Thu, 6 Mar 2025 15:37:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81review=EF=BC=9A=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E5=8A=A0=E9=94=81=E6=8E=92=E6=9F=A5=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- .../include/localhardwaremanager/local_hardware_manager.h | 4 +++- .../src/localhardwaremanager/local_hardware_manager.cpp | 4 +++- .../src/resourcemanager/capability_info_manager.cpp | 3 ++- .../src/resourcemanager/meta_info_manager.cpp | 2 +- .../src/versionmanager/version_manager.cpp | 3 ++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/localhardwaremanager/local_hardware_manager.h b/services/distributedhardwarefwkservice/include/localhardwaremanager/local_hardware_manager.h index d8acd185..0de9a6c9 100644 --- a/services/distributedhardwarefwkservice/include/localhardwaremanager/local_hardware_manager.h +++ b/services/distributedhardwarefwkservice/include/localhardwaremanager/local_hardware_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,6 +18,7 @@ #include #include +#include #include #include "capability_info.h" @@ -50,6 +51,7 @@ private: std::map compToolFuncsMap_; std::map> pluginListenerMap_; std::unordered_map> localDHItemsMap_; + std::mutex localHardwareMgrMutex_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp index 18091cb5..ff9acef0 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp @@ -48,8 +48,8 @@ LocalHardwareManager::~LocalHardwareManager() {} void LocalHardwareManager::Init() { DHLOGI("start"); + std::lock_guard lock(localHardwareMgrMutex_); std::vector allCompTypes = ComponentLoader::GetInstance().GetAllCompTypes(); - localDHItemsMap_.clear(); int64_t allQueryStartTime = GetCurrentTime(); for (auto dhType : allCompTypes) { int64_t singleQueryStartTime = GetCurrentTime(); @@ -96,8 +96,10 @@ void LocalHardwareManager::Init() void LocalHardwareManager::UnInit() { DHLOGI("start"); + std::lock_guard lock(localHardwareMgrMutex_); compToolFuncsMap_.clear(); pluginListenerMap_.clear(); + localDHItemsMap_.clear(); } void LocalHardwareManager::QueryLocalHardware(const DHType dhType, IHardwareHandler *hardwareHandler) diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp index 4d8cee07..057d5e54 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -644,6 +644,7 @@ int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, void CapabilityInfoManager::DumpCapabilityInfos(std::vector &capInfos) { + std::lock_guard lock(capInfoMgrMutex_); for (auto info : globalCapInfoMap_) { CapabilityInfo capInfo = *(info.second); capInfos.emplace_back(capInfo); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp index ac233b06..9c373c07 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp @@ -340,7 +340,6 @@ int32_t MetaInfoManager::SyncDataByNetworkId(const std::string &networkId) int32_t MetaInfoManager::RemoveMetaInfoInMemByUdid(const std::string &peerudid) { DHLOGI("remove device metainfo in memory, peerudid: %{public}s", GetAnonyString(peerudid).c_str()); - std::lock_guard lock(metaInfoMgrMutex_); std::string udIdHash = Sha256(peerudid); for (auto iter = globalMetaInfoMap_.begin(); iter != globalMetaInfoMap_.end();) { if (!IsCapKeyMatchDeviceId(iter->first, udIdHash)) { @@ -355,6 +354,7 @@ int32_t MetaInfoManager::RemoveMetaInfoInMemByUdid(const std::string &peerudid) int32_t MetaInfoManager::ClearRemoteDeviceMetaInfoData(const std::string &peerudid, const std::string &peeruuid) { + std::lock_guard lock(metaInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL; diff --git a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp index 464cd1e4..4c6b9bfb 100644 --- a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp +++ b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -46,6 +46,7 @@ int32_t VersionManager::Init() void VersionManager::UnInit() { DHLOGI("start"); + std::lock_guard lock(versionMutex_); dhVersions_.clear(); } -- Gitee