diff --git a/display/composer/cache_manager/cache_manager.h b/display/composer/cache_manager/cache_manager.h index 1532299f90002ff9b33bbed6cc6d937f1aef1f90..87a27c787fb020c4e94482cf2cb1d01d0adf9625 100644 --- a/display/composer/cache_manager/cache_manager.h +++ b/display/composer/cache_manager/cache_manager.h @@ -71,15 +71,16 @@ public: bool InsertCache(IdType id, CacheType* cache) { - if (SearchCache(id) != nullptr) { + std::lock_guard lock(mutex_); + auto cacheItem = caches_.find(id); + if (cacheItem != caches_.end()) { HDF_LOGI("%{public}s: intend to insert a existing cache, SeqNo=%{public}d", __func__, id); } else { - if (cacheCountMax_ != 0 && Size() >= cacheCountMax_) { + if (cacheCountMax_ != 0 && caches_.size() >= cacheCountMax_) { HDF_LOGE("%{public}s: Caches is full, new seqNo:%{public}d can't be inserted", __func__, id); return false; } } - std::lock_guard lock(mutex_); caches_[id] = std::move(*(new std::unique_ptr(cache))); return true; @@ -87,10 +88,11 @@ public: bool EraseCache(IdType id) { + std::lock_guard lock(mutex_); bool ret = false; - if (SearchCache(id) != nullptr) { - std::lock_guard lock(mutex_); - caches_.erase(id); + auto cacheItem = caches_.find(id); + if (cacheItem != caches_.end()) { + caches_.erase(cacheItem); ret = true; } else { HDF_LOGE("%{public}s: Cache %{public}d is not existing\n", __func__, id); diff --git a/display/composer/v1_0/display_command/display_cmd_utils.h b/display/composer/v1_0/display_command/display_cmd_utils.h index f2c33735bcb4fde1ad2dc025029888d0770121d5..73145ae37574604104e36a626bd82b35439a878b 100644 --- a/display/composer/v1_0/display_command/display_cmd_utils.h +++ b/display/composer/v1_0/display_command/display_cmd_utils.h @@ -76,22 +76,22 @@ public: } } - static int32_t StartPack(int32_t cmdId, std::shared_ptr packer) + static int32_t StartPack(int32_t cmdId, std::shared_ptr& packer) { return packer->PackBegin(cmdId) ? HDF_SUCCESS : HDF_FAILURE; } - static int32_t EndPack(std::shared_ptr packer) + static int32_t EndPack(std::shared_ptr& packer) { return packer->PackEnd(CONTROL_CMD_REQUEST_END) ? HDF_SUCCESS : HDF_FAILURE; } - static int32_t StartSection(int32_t cmdId, std::shared_ptr packer) + static int32_t StartSection(int32_t cmdId, std::shared_ptr& packer) { return packer->BeginSection(cmdId) ? HDF_SUCCESS : HDF_FAILURE; } - static int32_t SetupDevice(uint32_t devId, uint32_t layerId, std::shared_ptr packer) + static int32_t SetupDevice(uint32_t devId, uint32_t layerId, std::shared_ptr& packer) { DISPLAY_CHK_RETURN(packer->WriteUint32(devId) == false, HDF_FAILURE, HDF_LOGE("%{public}s, write devId error", __func__)); @@ -100,7 +100,7 @@ public: return HDF_SUCCESS; } - static int32_t EndSection(std::shared_ptr packer) + static int32_t EndSection(std::shared_ptr& packer) { return packer->EndSection() ? HDF_SUCCESS : HDF_FAILURE; } @@ -132,7 +132,7 @@ public: return false; } - static int32_t RectPack(const IRect& rect, std::shared_ptr packer) + static int32_t RectPack(const IRect& rect, std::shared_ptr& packer) { DISPLAY_CHK_RETURN(packer->WriteInt32(rect.x) == false, HDF_FAILURE, HDF_LOGE("%{public}s, write rect.x error", __func__)); @@ -145,7 +145,7 @@ public: return HDF_SUCCESS; } - static int32_t LayerColorPack(const LayerColor& layerColor, std::shared_ptr packer) + static int32_t LayerColorPack(const LayerColor& layerColor, std::shared_ptr& packer) { DISPLAY_CHK_RETURN(packer->WriteUint8(layerColor.r) == false, HDF_FAILURE, HDF_LOGE("%{public}s, write layerColor.r error", __func__)); @@ -159,7 +159,7 @@ public: } static int32_t FileDescriptorPack( - const int32_t fd, std::shared_ptr packer, std::vector& hdiFds) + const int32_t fd, std::shared_ptr& packer, std::vector& hdiFds) { HdifdInfo hdifdInfo; hdifdInfo.id = GenerateHdifdSeqid(); @@ -181,7 +181,7 @@ public: return HDF_SUCCESS; } - static int32_t BufferHandlePack(const BufferHandle* buffer, std::shared_ptr packer, + static int32_t BufferHandlePack(const BufferHandle* buffer, std::shared_ptr& packer, std::vector& hdiFds) { if (buffer == nullptr) { @@ -228,7 +228,7 @@ public: return HDF_SUCCESS; } - static int32_t SetupDeviceUnpack(std::shared_ptr unpacker, uint32_t& devId, uint32_t& layerId) + static int32_t SetupDeviceUnpack(std::shared_ptr& unpacker, uint32_t& devId, uint32_t& layerId) { DISPLAY_CHK_RETURN(unpacker->ReadUint32(devId) == false, HDF_FAILURE, HDF_LOGE("%{public}s, read devId failed", __func__)); @@ -237,7 +237,7 @@ public: return HDF_SUCCESS; } - static int32_t RectUnpack(std::shared_ptr unpacker, IRect& rect) + static int32_t RectUnpack(std::shared_ptr& unpacker, IRect& rect) { DISPLAY_CHK_RETURN(unpacker->ReadInt32(rect.x) == false, HDF_FAILURE, HDF_LOGE("%{public}s, read rect.x failed", __func__)); @@ -251,7 +251,7 @@ public: } static int32_t FileDescriptorUnpack( - std::shared_ptr unpacker, const std::vector& hdiFds, int32_t& fd) + std::shared_ptr& unpacker, const std::vector& hdiFds, int32_t& fd) { int32_t fdId = -1; DISPLAY_CHK_RETURN(unpacker->ReadInt32(fdId) == false, HDF_FAILURE, @@ -263,7 +263,7 @@ public: return HDF_SUCCESS; } - static bool UnpackBasicInfo(std::shared_ptr unpacker, const std::vector& hdiFds, + static bool UnpackBasicInfo(std::shared_ptr& unpacker, const std::vector& hdiFds, BufferHandle *handle) { int32_t ret = FileDescriptorUnpack(unpacker, hdiFds, handle->fd); @@ -285,7 +285,7 @@ public: return retVal; } - static bool UnpackExtraInfo(std::shared_ptr unpacker, const std::vector& hdiFds, + static bool UnpackExtraInfo(std::shared_ptr& unpacker, const std::vector& hdiFds, BufferHandle *handle) { bool retVal = true; @@ -308,7 +308,7 @@ public: return retVal; } - static int32_t BufferHandleUnpack(std::shared_ptr unpacker, + static int32_t BufferHandleUnpack(std::shared_ptr& unpacker, const std::vector& hdiFds, BufferHandle*& buffer) { uint32_t fdsNum = 0; @@ -340,7 +340,7 @@ public: return retVal ? HDF_SUCCESS : HDF_FAILURE; } - static int32_t LayerColorUnpack(std::shared_ptr unpacker, LayerColor& layerColor) + static int32_t LayerColorUnpack(std::shared_ptr& unpacker, LayerColor& layerColor) { DISPLAY_CHK_RETURN(unpacker->ReadUint8(layerColor.r) == false, HDF_FAILURE, HDF_LOGE("%{public}s, read layerColor.r failed", __func__));