From b2a65610debde191f8bb49c28f287fc86ea9b55a Mon Sep 17 00:00:00 2001 From: Yin-Chia Yeh Date: Thu, 7 Sep 2017 16:30:46 -0700 Subject: [PATCH] Camera: synchronize access to mHidlMemPoolMap Test: stress test by HAL1 partner Bug: 65431027 Change-Id: Ia13f0f65b72ff459f59bb4a566b571de37ee4716 Merged-In: Ia13f0f65b72ff459f59bb4a566b571de37ee4716 --- .../libcameraservice/device1/CameraHardwareInterface.cpp | 6 ++++++ .../libcameraservice/device1/CameraHardwareInterface.h | 1 + 2 files changed, 7 insertions(+) diff --git a/services/camera/libcameraservice/device1/CameraHardwareInterface.cpp b/services/camera/libcameraservice/device1/CameraHardwareInterface.cpp index 469c86c55e..b7f7af035f 100644 --- a/services/camera/libcameraservice/device1/CameraHardwareInterface.cpp +++ b/services/camera/libcameraservice/device1/CameraHardwareInterface.cpp @@ -108,11 +108,13 @@ hardware::Return CameraHardwareInterface::registerMemory( ALOGE("%s: CameraHeapMemory has FD %d (expect >= 0)", __FUNCTION__, memPoolId); return 0; } + std::lock_guard lock(mHidlMemPoolMapLock); mHidlMemPoolMap.insert(std::make_pair(memPoolId, mem)); return memPoolId; } hardware::Return CameraHardwareInterface::unregisterMemory(uint32_t memId) { + std::lock_guard lock(mHidlMemPoolMapLock); if (mHidlMemPoolMap.count(memId) == 0) { ALOGE("%s: memory pool ID %d not found", __FUNCTION__, memId); return hardware::Void(); @@ -126,6 +128,7 @@ hardware::Return CameraHardwareInterface::unregisterMemory(uint32_t memId) hardware::Return CameraHardwareInterface::dataCallback( DataCallbackMsg msgType, uint32_t data, uint32_t bufferIndex, const hardware::camera::device::V1_0::CameraFrameMetadata& metadata) { + std::lock_guard lock(mHidlMemPoolMapLock); if (mHidlMemPoolMap.count(data) == 0) { ALOGE("%s: memory pool ID %d not found", __FUNCTION__, data); return hardware::Void(); @@ -140,6 +143,7 @@ hardware::Return CameraHardwareInterface::dataCallback( hardware::Return CameraHardwareInterface::dataCallbackTimestamp( DataCallbackMsg msgType, uint32_t data, uint32_t bufferIndex, int64_t timestamp) { + std::lock_guard lock(mHidlMemPoolMapLock); if (mHidlMemPoolMap.count(data) == 0) { ALOGE("%s: memory pool ID %d not found", __FUNCTION__, data); return hardware::Void(); @@ -151,6 +155,7 @@ hardware::Return CameraHardwareInterface::dataCallbackTimestamp( hardware::Return CameraHardwareInterface::handleCallbackTimestamp( DataCallbackMsg msgType, const hidl_handle& frameData, uint32_t data, uint32_t bufferIndex, int64_t timestamp) { + std::lock_guard lock(mHidlMemPoolMapLock); if (mHidlMemPoolMap.count(data) == 0) { ALOGE("%s: memory pool ID %d not found", __FUNCTION__, data); return hardware::Void(); @@ -169,6 +174,7 @@ hardware::Return CameraHardwareInterface::handleCallbackTimestampBatch( std::vector msgs; msgs.reserve(messages.size()); + std::lock_guard lock(mHidlMemPoolMapLock); for (const auto& hidl_msg : messages) { if (mHidlMemPoolMap.count(hidl_msg.data) == 0) { ALOGE("%s: memory pool ID %d not found", __FUNCTION__, hidl_msg.data); diff --git a/services/camera/libcameraservice/device1/CameraHardwareInterface.h b/services/camera/libcameraservice/device1/CameraHardwareInterface.h index 1c38d0023c..2f1e2e98e4 100644 --- a/services/camera/libcameraservice/device1/CameraHardwareInterface.h +++ b/services/camera/libcameraservice/device1/CameraHardwareInterface.h @@ -523,6 +523,7 @@ private: uint64_t mNextBufferId = 1; static const uint64_t BUFFER_ID_NO_BUFFER = 0; + std::mutex mHidlMemPoolMapLock; // protecting mHidlMemPoolMap std::unordered_map mHidlMemPoolMap; };