diff --git a/services/distributedhardwarefwkservice/include/localhardwaremanager/local_hardware_manager.h b/services/distributedhardwarefwkservice/include/localhardwaremanager/local_hardware_manager.h index d8acd185e56ccd877e1b9aa3dfaa530afbaa69d5..0de9a6c93f1f059147b2b5a37e614bd7c9a8ff62 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 18091cb58fa8b8522f935ecfc0ab73d222fad126..ff9acef069a00b65fb4541e18ab7ef6e4e1cee74 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 4d8cee077cb7a45ba124df303e240da6eec32593..057d5e545c0507fa5cee5dca271b4f2e5b08fe1b 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 ac233b06a8ca71ed96aace549be5d1576551c997..9c373c070ac6330300d76a474114527e42afa2cf 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 464cd1e4449f776196bdb9dd209b81a55ac45ce9..4c6b9bfbec2ec76510626164918d87769046a9b4 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(); }