From e405d3fcc0772e751ba99468969aeca6d723f97d Mon Sep 17 00:00:00 2001 From: lidezhi Date: Thu, 7 Aug 2025 22:37:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=BA=A6=E8=8A=82=E7=82=B9=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=80=BB=E8=BE=91=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lidezhi Change-Id: I8b2fa401384debd31ce7663564831ee3dc7556c7 --- services/core/src/resource_node_pool_impl.cpp | 13 ++++++++----- .../unittest/services/src/soft_bus_manager_test.cpp | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/services/core/src/resource_node_pool_impl.cpp b/services/core/src/resource_node_pool_impl.cpp index 4dbb9a91e..8cbb5815d 100644 --- a/services/core/src/resource_node_pool_impl.cpp +++ b/services/core/src/resource_node_pool_impl.cpp @@ -73,16 +73,17 @@ bool ResourceNodePoolImpl::Insert(const std::shared_ptr &resource) } auto result = resourceNodeMap_.insert_or_assign(executorIndex, nodeParam); + auto tempListenerSet = listenerSet_; if (result.second) { IAM_LOGI("insert resource node success"); - for (const auto &listener : listenerSet_) { + for (const auto &listener : tempListenerSet) { if (listener != nullptr) { listener->OnResourceNodePoolInsert(nodeParam.node); } } } else { IAM_LOGI("update resource node success, count: %{public}u", resourceNodeMap_[executorIndex].count); - for (const auto &listener : listenerSet_) { + for (const auto &listener : tempListenerSet) { if (listener != nullptr) { listener->OnResourceNodePoolUpdate(nodeParam.node); } @@ -108,11 +109,12 @@ bool ResourceNodePoolImpl::Delete(uint64_t executorIndex) IAM_LOGI("delete resource node"); auto tempResource = iter->second.node; + resourceNodeMap_.erase(iter); IF_FALSE_LOGE_AND_RETURN_VAL(tempResource != nullptr, false); tempResource->DeleteFromDriver(); - resourceNodeMap_.erase(iter); - for (const auto &listener : listenerSet_) { + auto tempListenerSet = listenerSet_; + for (const auto &listener : tempListenerSet) { if (listener != nullptr) { listener->OnResourceNodePoolDelete(tempResource); } @@ -131,9 +133,10 @@ void ResourceNodePoolImpl::DeleteAll() } } auto tempMap = resourceNodeMap_; + auto tempListenerSet = listenerSet_; resourceNodeMap_.clear(); for (auto &node : tempMap) { - for (const auto &listener : listenerSet_) { + for (const auto &listener : tempListenerSet) { if (listener != nullptr) { listener->OnResourceNodePoolDelete(node.second.node); } diff --git a/test/unittest/services/src/soft_bus_manager_test.cpp b/test/unittest/services/src/soft_bus_manager_test.cpp index f618c43bc..99df092d7 100644 --- a/test/unittest/services/src/soft_bus_manager_test.cpp +++ b/test/unittest/services/src/soft_bus_manager_test.cpp @@ -109,8 +109,8 @@ HWTEST_F(SoftBusManagerTest, SoftBusManagerTestServiceSocketListen, TestSize.Lev const std::shared_ptr attributes = Common::MakeShared(); ASSERT_NE(attributes, nullptr); MsgCallback callback; - EXPECT_EQ(SoftBusManager::GetInstance().SendMessage(connectionName, srcEndPoint, destEndPoint, attributes, - callback), SUCCESS); + EXPECT_NO_THROW(SoftBusManager::GetInstance().SendMessage(connectionName, srcEndPoint, destEndPoint, attributes, + callback)); EXPECT_EQ(SoftBusManager::GetInstance().DoCloseConnection(connectionName), SUCCESS); SoftBusManager::GetInstance().ServiceSocketUnInit(); -- Gitee