[{"id":17138,"web_url":"https://patchwork.libcamera.org/comment/17138/","msgid":"<YKqZg3a9CRB/XTMH@pendragon.ideasonboard.com>","date":"2021-05-23T18:05:55","subject":"Re: [libcamera-devel] [PATCH v3 5/8] android: Replace scoped_lock<>\n\twith libcamera::MutexLocker","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Fri, May 21, 2021 at 05:42:24PM +0200, Jacopo Mondi wrote:\n> The CameraDevice class uses std::scoped_lock<> to guard access to the\n> class' descriptors_ member.\n> \n> std::scoped_lock<> provides a set of features that guarantees safety\n> when locking multiple mutexes in a critical section, while for single\n> locks happening in a scoped block it does not provides benefits compared\n> to the simplest std::unique_lock<> which libcamera provides the\n> MutexLocker type for.\n> \n> Replace usage of std::scoped_lock<> with libcamera::MutexLocker to make\n> the implementation consistent with the rest of the code base.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>\n\nFor additional consistency, you may want to use Mutex instead of\nstd::mutex in camera_device.h (and then drop the #include <mutex>).\nAnother option would be to use std::unique_lock<> instead of MutexLocker\nin this patch. Or you could keep it as-is :-) Up to you, in any case.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/android/camera_device.cpp | 5 +++--\n>  1 file changed, 3 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index cf0e5e459213..fceae96a8b7c 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -23,6 +23,7 @@\n>  \n>  #include \"libcamera/internal/formats.h\"\n>  #include \"libcamera/internal/log.h\"\n> +#include \"libcamera/internal/thread.h\"\n>  #include \"libcamera/internal/utils.h\"\n>  \n>  #include \"system/graphics.h\"\n> @@ -1947,7 +1948,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n>  \tworker_.queueRequest(descriptor.request_.get());\n>  \n>  \t{\n> -\t\tstd::scoped_lock<std::mutex> lock(mutex_);\n> +\t\tMutexLocker lock(mutex_);\n>  \t\tdescriptors_[descriptor.request_->cookie()] = std::move(descriptor);\n>  \t}\n>  \n> @@ -1958,7 +1959,7 @@ void CameraDevice::requestComplete(Request *request)\n>  {\n>  \tdecltype(descriptors_)::node_type node;\n>  \t{\n> -\t\tstd::scoped_lock<std::mutex> lock(mutex_);\n> +\t\tMutexLocker lock(mutex_);\n>  \t\tauto it = descriptors_.find(request->cookie());\n>  \t\tif (it == descriptors_.end()) {\n>  \t\t\t/*","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 AF3FDC3201\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 23 May 2021 18:06:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3067D6891D;\n\tSun, 23 May 2021 20:06:00 +0200 (CEST)","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 3BB87601A9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 May 2021 20:05:59 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 454942A8;\n\tSun, 23 May 2021 20:05:58 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"VHD/DZmY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1621793158;\n\tbh=Q7pk61iQE8W7nH630Dg7uDj4qA54ik/CjIxBytuxXNE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=VHD/DZmY87+S9XE2k8U3GcoqzrCA825Pmx6bNIWVCob/z3w4VcfoKeiuRholr49OL\n\tr7USU9c1otM1CqU0WmzZpqJcRozsHXO6LZpsI5Msrbh7ciqJP/x4ahG+c7ofjkiL1Z\n\tMTvMcT8n43gXFlNoY86fNC9AVHAchvKPA1JgONUw=","Date":"Sun, 23 May 2021 21:05:55 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YKqZg3a9CRB/XTMH@pendragon.ideasonboard.com>","References":"<20210521154227.60186-1-jacopo@jmondi.org>\n\t<20210521154227.60186-6-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20210521154227.60186-6-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v3 5/8] android: Replace scoped_lock<>\n\twith libcamera::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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]