diff --git a/services/distributeddataservice/service/data_share/common/proxy_data_manager.cpp b/services/distributeddataservice/service/data_share/common/proxy_data_manager.cpp index 8a9988e0c401e94e7e8333b63500074246cc894a..25125bdbe31c6fd0c5de4f19f1aecafd684a61bf 100644 --- a/services/distributeddataservice/service/data_share/common/proxy_data_manager.cpp +++ b/services/distributeddataservice/service/data_share/common/proxy_data_manager.cpp @@ -24,6 +24,7 @@ #include "utils/anonymous.h" namespace OHOS::DataShare { +std::mutex PublishedProxyData::mutex_; ProxyDataManager &ProxyDataManager::GetInstance() { @@ -270,6 +271,7 @@ int32_t PublishedProxyData::Query(const std::string &uri, const BundleInfo &call int32_t PublishedProxyData::Upsert(const DataShareProxyData &proxyData, const BundleInfo &callerBundleInfo, DataShareObserver::ChangeType &type) { + std::lock_guard lock(mutex_); type = DataShareObserver::ChangeType::INVAILD; auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { @@ -317,6 +319,7 @@ int32_t PublishedProxyData::Upsert(const DataShareProxyData &proxyData, const Bu int32_t PublishedProxyData::Delete(const std::string &uri, const BundleInfo &callerBundleInfo, DataShareProxyData &oldProxyData, DataShareObserver::ChangeType &type) { + std::lock_guard lock(mutex_); type = DataShareObserver::ChangeType::INVAILD; auto delegate = KvDBDelegate::GetInstance(); if (delegate == nullptr) { @@ -349,8 +352,7 @@ int32_t PublishedProxyData::Delete(const std::string &uri, const BundleInfo &cal return INNER_ERROR; } std::vector uris; - auto count = ProxyDataList::Query(callerBundleInfo.tokenId, callerBundleInfo.userId, uris); - if (count <= 0) { + if (ProxyDataList::Query(callerBundleInfo.tokenId, callerBundleInfo.userId, uris) <= 0) { ZLOGI("get bundle %{public}s's proxyData failed", callerBundleInfo.bundleName.c_str()); return INNER_ERROR; } diff --git a/services/distributeddataservice/service/data_share/common/proxy_data_manager.h b/services/distributeddataservice/service/data_share/common/proxy_data_manager.h index 75da70ed1bc913251c817b7bd0286603d9e78b6a..e8a4a62f3346c1174318b5bcf8feaf0b3bb54ecd 100644 --- a/services/distributeddataservice/service/data_share/common/proxy_data_manager.h +++ b/services/distributeddataservice/service/data_share/common/proxy_data_manager.h @@ -84,6 +84,7 @@ private: uint32_t tokenId, const std::vector &proxyDataList, const DataShareProxyData &proxyData); static bool CheckAndCorrectProxyData(DataShareProxyData &proxyData); ProxyDataNode value; + static std::mutex mutex_; }; class ProxyDataManager {