From 01f79a68c281b5e24702ab72fbed49c6620658be Mon Sep 17 00:00:00 2001 From: wangkun Date: Thu, 22 Jul 2021 23:09:13 +0800 Subject: [PATCH] fixed 2945efc from https://gitee.com/wangkun_hw/distributeddatamgr_datamgr/pulls/29 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 020a55a63..e79d42649 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