解决条件竞争问题

Signed-off-by: l00804143 <luocheng52@huawei.com>
This commit is contained in:
l00804143
2023-05-13 11:42:55 +08:00
parent 3daecf46cc
commit eee8ca7eb8
2 changed files with 8 additions and 4 deletions
@@ -286,6 +286,7 @@ private:
sptr<IRemoteObject::DeathRecipient> configCallbackDeathRecipient_ = nullptr;
sptr<IRemoteObject::DeathRecipient> bundleManagerDeathRecipient_ = nullptr;
std::vector<sptr<IAccessibleAbilityManagerStateObserver>> stateCallbacks_;
std::mutex mutex_;
};
} // namespace Accessibility
} // namespace OHOS
@@ -291,10 +291,13 @@ uint32_t AccessibleAbilityManagerService::RegisterStateObserver(
return;
}
callback->AsObject()->AddDeathRecipient(stateCallbackDeathRecipient_);
auto iter = std::find(stateCallbacks_.begin(), stateCallbacks_.end(), callback);
if (iter == stateCallbacks_.end()) {
stateCallbacks_.push_back(callback);
HILOG_INFO("RegisterStateObserver successfully");
{
std::lock_guard<std::mutex> lock(mutex_);
auto iter = std::find(stateCallbacks_.begin(), stateCallbacks_.end(), callback);
if (iter == stateCallbacks_.end()) {
stateCallbacks_.push_back(callback);
HILOG_INFO("RegisterStateObserver successfully");
}
}
sptr<AccessibilityAccountData> accountData = GetCurrentAccountData();