[{"id":21499,"web_url":"https://patchwork.libcamera.org/comment/21499/","msgid":"<f0c06eda-0f33-c1af-0348-14f32dfa6681@ideasonboard.com>","date":"2021-12-01T10:23:55","subject":"Re: [libcamera-devel] [PATCH v5 02/12] android: Consolidate mutex\n\tclasses to Mutex and MutexLocker","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Hiro,\n\nOn 12/1/21 1:23 PM, Hirokazu Honda wrote:\n> std::mutex and std::unique_lcok are used in android directories,\n\n\ns/lcok/lock/\n\n> mixing Mutex and MutexLocker. This consolidates them to Mutex\n> and MutexLocker.\n>\n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n> ---\n>   src/android/camera_device.h      |  1 -\n>   src/android/camera_hal_manager.h |  7 ++-----\n>   src/android/camera_request.h     |  4 ++--\n>   src/android/camera_stream.cpp    | 12 ++++++------\n>   src/android/camera_stream.h      |  3 +--\n>   5 files changed, 11 insertions(+), 16 deletions(-)\n>\n> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> index 51fe7da2..bda0b376 100644\n> --- a/src/android/camera_device.h\n> +++ b/src/android/camera_device.h\n> @@ -9,7 +9,6 @@\n>   \n>   #include <map>\n>   #include <memory>\n> -#include <mutex>\n>   #include <queue>\n>   #include <vector>\n>   \n> diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h\n> index 192f2fc5..cc310f90 100644\n> --- a/src/android/camera_hal_manager.h\n> +++ b/src/android/camera_hal_manager.h\n> @@ -8,7 +8,6 @@\n>   #pragma once\n>   \n>   #include <map>\n> -#include <mutex>\n>   #include <stddef.h>\n>   #include <tuple>\n>   #include <vector>\n> @@ -18,6 +17,7 @@\n>   #include <system/camera_metadata.h>\n>   \n>   #include <libcamera/base/class.h>\n> +#include <libcamera/base/thread.h>\n>   \n>   #include <libcamera/camera_manager.h>\n>   \n> @@ -44,9 +44,6 @@ public:\n>   private:\n>   \tLIBCAMERA_DISABLE_COPY_AND_MOVE(CameraHalManager)\n>   \n> -\tusing Mutex = std::mutex;\n> -\tusing MutexLocker = std::unique_lock<std::mutex>;\n> -\n>   \tstatic constexpr unsigned int firstExternalCameraId_ = 1000;\n>   \n>   \tCameraHalManager();\n> @@ -64,7 +61,7 @@ private:\n>   \tconst camera_module_callbacks_t *callbacks_;\n>   \tstd::vector<std::unique_ptr<CameraDevice>> cameras_;\n>   \tstd::map<std::string, unsigned int> cameraIdsMap_;\n> -\tMutex mutex_;\n> +\tlibcamera::Mutex mutex_;\n>   \n>   \tunsigned int numInternalCameras_;\n>   \tunsigned int nextExternalCameraId_;\n> diff --git a/src/android/camera_request.h b/src/android/camera_request.h\n> index f3cb6d64..88d501a8 100644\n> --- a/src/android/camera_request.h\n> +++ b/src/android/camera_request.h\n> @@ -9,10 +9,10 @@\n>   \n>   #include <map>\n>   #include <memory>\n> -#include <mutex>\n>   #include <vector>\n>   \n>   #include <libcamera/base/class.h>\n> +#include <libcamera/base/thread.h>\n>   \n>   #include <libcamera/camera.h>\n>   #include <libcamera/framebuffer.h>\n> @@ -58,7 +58,7 @@ public:\n>   \n>   \t/* Keeps track of streams requiring post-processing. */\n>   \tstd::map<CameraStream *, StreamBuffer *> pendingStreamsToProcess_;\n> -\tstd::mutex streamsProcessMutex_;\n> +\tlibcamera::Mutex streamsProcessMutex_;\n>   \n>   \tCamera3RequestDescriptor(libcamera::Camera *camera,\n>   \t\t\t\t const camera3_capture_request_t *camera3Request);\n> diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\n> index 9023c13c..5a62b7cd 100644\n> --- a/src/android/camera_stream.cpp\n> +++ b/src/android/camera_stream.cpp\n> @@ -119,7 +119,7 @@ int CameraStream::configure()\n>   \n>   \tif (type_ == Type::Internal) {\n>   \t\tallocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());\n> -\t\tmutex_ = std::make_unique<std::mutex>();\n> +\t\tmutex_ = std::make_unique<Mutex>();\n>   \n>   \t\tint ret = allocator_->allocate(stream());\n>   \t\tif (ret < 0)\n> @@ -208,7 +208,7 @@ FrameBuffer *CameraStream::getBuffer()\n>   \tif (!allocator_)\n>   \t\treturn nullptr;\n>   \n> -\tstd::lock_guard<std::mutex> locker(*mutex_);\n> +\tMutexLocker locker(*mutex_);\n>   \n>   \tif (buffers_.empty()) {\n>   \t\tLOG(HAL, Error) << \"Buffer underrun\";\n> @@ -226,7 +226,7 @@ void CameraStream::putBuffer(FrameBuffer *buffer)\n>   \tif (!allocator_)\n>   \t\treturn;\n>   \n> -\tstd::lock_guard<std::mutex> locker(*mutex_);\n> +\tMutexLocker locker(*mutex_);\n>   \n>   \tbuffers_.push_back(buffer);\n>   }\n> @@ -239,7 +239,7 @@ CameraStream::PostProcessorWorker::PostProcessorWorker(PostProcessor *postProces\n>   CameraStream::PostProcessorWorker::~PostProcessorWorker()\n>   {\n>   \t{\n> -\t\tlibcamera::MutexLocker lock(mutex_);\n> +\t\tMutexLocker lock(mutex_);\n>   \t\tstate_ = State::Stopped;\n>   \t}\n>   \n> @@ -250,7 +250,7 @@ CameraStream::PostProcessorWorker::~PostProcessorWorker()\n>   void CameraStream::PostProcessorWorker::start()\n>   {\n>   \t{\n> -\t\tlibcamera::MutexLocker lock(mutex_);\n> +\t\tMutexLocker lock(mutex_);\n>   \t\tASSERT(state_ != State::Running);\n>   \t\tstate_ = State::Running;\n>   \t}\n> @@ -308,7 +308,7 @@ void CameraStream::PostProcessorWorker::run()\n>   \n>   void CameraStream::PostProcessorWorker::flush()\n>   {\n> -\tlibcamera::MutexLocker lock(mutex_);\n> +\tMutexLocker lock(mutex_);\n>   \tstate_ = State::Flushing;\n>   \tlock.unlock();\n>   \n> diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\n> index e4808369..adb5a37d 100644\n> --- a/src/android/camera_stream.h\n> +++ b/src/android/camera_stream.h\n> @@ -8,7 +8,6 @@\n>   #pragma once\n>   \n>   #include <memory>\n> -#include <mutex>\n>   #include <queue>\n>   #include <vector>\n>   \n> @@ -173,7 +172,7 @@ private:\n>   \t * The class has to be MoveConstructible as instances are stored in\n>   \t * an std::vector in CameraDevice.\n>   \t */\n> -\tstd::unique_ptr<std::mutex> mutex_;\n> +\tstd::unique_ptr<libcamera::Mutex> mutex_;\n>   \tstd::unique_ptr<PostProcessor> postProcessor_;\n>   \n>   \tstd::unique_ptr<PostProcessorWorker> worker_;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id E105DBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  1 Dec 2021 10:24:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 35BBF60723;\n\tWed,  1 Dec 2021 11:24:03 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9BC1E6011D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Dec 2021 11:24:01 +0100 (CET)","from [192.168.1.106] (unknown [103.251.226.170])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8A5D58AE;\n\tWed,  1 Dec 2021 11:24:00 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"o3r7yZVG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638354241;\n\tbh=RyVnkLrbJWno/yVM9xrTyC5u0xdVronTqOlCQ2jvji4=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=o3r7yZVGK5vlsJJM9YeyuAJ9la5Nl8MZ6sHab94oot8smbE/vSEqFZ9/d2wkBHa3n\n\tyWrI/NpJc5FlHAx1DebNSoIg4+R98UD9jq/wEEQiZe5zJSOvdcksk5C77IFnc/gf5n\n\tdnJq4DVCfb8KH+QohMPulwKADMzeoFz7jdcU9P48=","To":"Hirokazu Honda <hiroh@chromium.org>, libcamera-devel@lists.libcamera.org","References":"<20211201075348.3121186-1-hiroh@chromium.org>\n\t<20211201075348.3121186-3-hiroh@chromium.org>","From":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<f0c06eda-0f33-c1af-0348-14f32dfa6681@ideasonboard.com>","Date":"Wed, 1 Dec 2021 15:53:55 +0530","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.10.2","MIME-Version":"1.0","In-Reply-To":"<20211201075348.3121186-3-hiroh@chromium.org>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"7bit","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH v5 02/12] android: Consolidate mutex\n\tclasses to Mutex and MutexLocker","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]