已合并
allocator代码整改 #2046
allocator代码整改 #2046
已合并
wanghongen创建于 7月28日
2 个文件变更+8-3
@@ -84,8 +84,11 @@ public:
84 virtual ~DisplayBufferHdiImpl()84 virtual ~DisplayBufferHdiImpl()
85 {85 {
86 if (recipient_ != nullptr) {86 if (recipient_ != nullptr) {
87- sptr<IRemoteObject> remoteObj = OHOS::HDI::hdi_objcast<IAllocator>(allocator_);87+ std::unique_lock lock(allocMutex_);
88- remoteObj->RemoveDeathRecipient(recipient_);88+ if (allocator_ != nullptr) {
89+ sptr<IRemoteObject> remoteObj = OHOS::HDI::hdi_objcast<IAllocator>(allocator_);
90+ remoteObj->RemoveDeathRecipient(recipient_);
91+ }
89 recipient_ = nullptr;92 recipient_ = nullptr;
90 }93 }
91 }94 }
@@ -118,6 +121,7 @@ public:
118 121 
119 bool AddDeathRecipientLocked(const sptr<IRemoteObject::DeathRecipient>& recipient) const122 bool AddDeathRecipientLocked(const sptr<IRemoteObject::DeathRecipient>& recipient) const
120 {123 {
124+ CHECK_NULLPOINTER_RETURN_VALUE(allocator_, false);
121 sptr<IRemoteObject> remoteObj = OHOS::HDI::hdi_objcast<IAllocator>(allocator_);125 sptr<IRemoteObject> remoteObj = OHOS::HDI::hdi_objcast<IAllocator>(allocator_);
122 if (recipient_ != nullptr) {126 if (recipient_ != nullptr) {
123 HDF_LOGE("%{public}s: the existing recipient is removed, and add the new. %{public}d",127 HDF_LOGE("%{public}s: the existing recipient is removed, and add the new. %{public}d",
@@ -143,8 +147,8 @@ public:
143 badClient_ = false;147 badClient_ = false;
144 }148 }
145 if (allocator_ == nullptr) {149 if (allocator_ == nullptr) {
146- return false;
147 HDF_LOGE("%{public}s: allocator_ is nullptr", __func__);150 HDF_LOGE("%{public}s: allocator_ is nullptr", __func__);
151+ return false;
148 }152 }
149 return AddDeathRecipientLocked(recipient);153 return AddDeathRecipientLocked(recipient);
150 }154 }
@@ -100,6 +100,7 @@ public:
100 {100 {
101 DISPLAY_TRACE;101 DISPLAY_TRACE;
102 CheckAllocator();102 CheckAllocator();
103+ std::shared_lock lock(allocMutex_);
103 CHECK_NULLPOINTER_RETURN_VALUE(allocator_, HDF_FAILURE);104 CHECK_NULLPOINTER_RETURN_VALUE(allocator_, HDF_FAILURE);
104 sptr<NativeBuffer> hdiBuffer;105 sptr<NativeBuffer> hdiBuffer;
105 int32_t ret = allocator_->AllocMem(info, hdiBuffer);106 int32_t ret = allocator_->AllocMem(info, hdiBuffer);