From 2945efcc5b7be15f44a9d71b4c6904af4fb25ccb Mon Sep 17 00:00:00 2001 From: wangkun Date: Thu, 22 Jul 2021 23:09:13 +0800 Subject: [PATCH] fixed the distributeddata deadlock bugs Signed-off-by: wangkun --- .../communicator/src/softbus_adapter_standard.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp b/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp index 78c365e65..449b490d1 100755 --- a/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp +++ b/services/distributeddataservice/adapter/communicator/src/softbus_adapter_standard.cpp @@ -201,12 +201,18 @@ Status SoftBusAdapter::StopWatchDeviceChange(const AppDeviceStatusChangeListener void SoftBusAdapter::NotifyAll(const DeviceInfo &deviceInfo, const DeviceChangeType &type) { std::thread th = std::thread([this, deviceInfo, type]() { - std::lock_guard lock(deviceChangeMutex_); + std::vector listeners; + { + std::lock_guard lock(deviceChangeMutex_); + for (const auto &listener : listeners_) { + listeners.push_back(listener); + } + } ZLOGD("high"); std::string uuid = GetUuidByNodeId(deviceInfo.deviceId); ZLOGD("[Notify] to DB from: %{public}s, type:%{public}d", ToBeAnonymous(uuid).c_str(), type); UpdateRelationship(deviceInfo.deviceId, type); - for (const auto &device : listeners_) { + for (const auto &device : listeners) { if (device == nullptr) { continue; } @@ -217,7 +223,7 @@ void SoftBusAdapter::NotifyAll(const DeviceInfo &deviceInfo, const DeviceChangeT } } ZLOGD("low"); - for (const auto &device : listeners_) { + for (const auto &device : listeners) { if (device == nullptr) { continue; } @@ -228,7 +234,7 @@ void SoftBusAdapter::NotifyAll(const DeviceInfo &deviceInfo, const DeviceChangeT } } ZLOGD("min"); - for (const auto &device : listeners_) { + for (const auto &device : listeners) { if (device == nullptr) { continue; } -- Gitee