diff --git a/services/dbms/include/distributed_bms.h b/services/dbms/include/distributed_bms.h index 145c18cdf0b575b67272b004337d3ff4a07f5518..d4e4309dc9a768a26a7f5ac14fc45af39396417b 100644 --- a/services/dbms/include/distributed_bms.h +++ b/services/dbms/include/distributed_bms.h @@ -144,6 +144,7 @@ private: std::shared_ptr dbmsDeviceManager_; std::shared_ptr distributedSub_; std::mutex bundleMgrMutex_; + std::mutex dbmsDeviceManagerMutex_; void Init(); void InitDeviceManager(); diff --git a/services/dbms/src/distributed_bms.cpp b/services/dbms/src/distributed_bms.cpp index 1b110852d9f51b65a821a867461d1924c2fec3a2..1bde3d4b16fe656255aeb16153860723cc50186f 100644 --- a/services/dbms/src/distributed_bms.cpp +++ b/services/dbms/src/distributed_bms.cpp @@ -168,8 +168,11 @@ void DistributedBms::Init() void DistributedBms::InitDeviceManager() { if (dbmsDeviceManager_ == nullptr) { - APP_LOGI("Create device manager"); - dbmsDeviceManager_ = std::make_shared(); + std::lock_guard lock(dbmsDeviceManagerMutex_); + if (dbmsDeviceManager_ == nullptr) { + APP_LOGI("Create device manager"); + dbmsDeviceManager_ = std::make_shared(); + } } }