accountCommonEventManager_添加锁保护

Signed-off-by: wangzhaohao <wangzhaohao@huawei.com>
This commit is contained in:
wangzhaohao 2024-11-08 11:51:20 +08:00
parent 1c60081980
commit 163a91ffea
2 changed files with 7 additions and 2 deletions

View File

@ -94,6 +94,7 @@ private:
void ClearProfileCache();
private:
std::mutex accountCommonEventManagerMtx_;
std::shared_ptr<DpAccountCommonEventManager> accountCommonEventManager_;
std::shared_ptr<AppExecFwk::EventHandler> unloadHandler_;
std::mutex unloadMutex_;

View File

@ -628,8 +628,11 @@ void DistributedDeviceProfileServiceNew::OnAddSystemAbility(int32_t systemAbilit
void DistributedDeviceProfileServiceNew::SubscribeAccountCommonEvent()
{
HILOGI("Start");
if (accountCommonEventManager_ == nullptr) {
accountCommonEventManager_ = std::make_shared<DpAccountCommonEventManager>();
{
std::lock_guard<std::mutex> lock(accountCommonEventManagerMtx_);
if (accountCommonEventManager_ == nullptr) {
accountCommonEventManager_ = std::make_shared<DpAccountCommonEventManager>();
}
}
AccountEventCallback callback = [=](const auto &arg1, const auto &arg2) {
this->AccountCommonEventCallback(arg1, arg2);
@ -639,6 +642,7 @@ void DistributedDeviceProfileServiceNew::SubscribeAccountCommonEvent()
AccountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED);
AccountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT);
AccountCommonEventVec.emplace_back(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN);
std::lock_guard<std::mutex> lock(accountCommonEventManagerMtx_);
if (accountCommonEventManager_->SubscribeAccountCommonEvent(AccountCommonEventVec, callback)) {
HILOGI("Success");
}