[{"id":24809,"web_url":"https://patchwork.libcamera.org/comment/24809/","msgid":"<Ywu1glqJn9/TTEoU@pendragon.ideasonboard.com>","date":"2022-08-28T18:35:46","subject":"Re: [libcamera-devel] [PATCH v2 5/5] v4l2: v4l2_camera: Apply clang\n\tthread safety annotation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang and Hiro,\n\nThank you for the patch.\n\nOn Mon, Jun 20, 2022 at 10:20:27PM +0530, Umang Jain via libcamera-devel wrote:\n> From: Hirokazu Honda <hiroh@chromium.org>\n> \n> This annotates member functions and variables of V4L2Camera by\n> clang thread safety annotations.\n> \n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>  src/v4l2/v4l2_camera.cpp |  5 ++---\n>  src/v4l2/v4l2_camera.h   | 14 ++++++++------\n>  2 files changed, 10 insertions(+), 9 deletions(-)\n> \n> diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp\n> index e922b9e6..7b97c2d5 100644\n> --- a/src/v4l2/v4l2_camera.cpp\n> +++ b/src/v4l2/v4l2_camera.cpp\n> @@ -71,11 +71,10 @@ std::vector<V4L2Camera::Buffer> V4L2Camera::completedBuffers()\n>  {\n>  \tstd::vector<Buffer> v;\n>  \n> -\tbufferLock_.lock();\n> +\tMutexLocker lock(bufferLock_);\n\nNot strictly within the scope of the commit message, but this is a fine\nchange.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \tfor (std::unique_ptr<Buffer> &metadata : completedBuffers_)\n>  \t\tv.push_back(*metadata.get());\n>  \tcompletedBuffers_.clear();\n> -\tbufferLock_.unlock();\n>  \n>  \treturn v;\n>  }\n> @@ -278,7 +277,7 @@ int V4L2Camera::qbuf(unsigned int index)\n>  void V4L2Camera::waitForBufferAvailable()\n>  {\n>  \tMutexLocker locker(bufferMutex_);\n> -\tbufferCV_.wait(locker, [&] {\n> +\tbufferCV_.wait(locker, [&]() LIBCAMERA_TSA_REQUIRES(bufferMutex_) {\n>  \t\t\t       return bufferAvailableCount_ >= 1 || !isRunning_;\n>  \t\t       });\n>  \tif (isRunning_)\n> diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h\n> index 03e74118..d3483444 100644\n> --- a/src/v4l2/v4l2_camera.h\n> +++ b/src/v4l2/v4l2_camera.h\n> @@ -39,7 +39,7 @@ public:\n>  \tvoid bind(int efd);\n>  \tvoid unbind();\n>  \n> -\tstd::vector<Buffer> completedBuffers();\n> +\tstd::vector<Buffer> completedBuffers() LIBCAMERA_TSA_EXCLUDES(bufferLock_);\n>  \n>  \tint configure(libcamera::StreamConfiguration *streamConfigOut,\n>  \t\t      const libcamera::Size &size,\n> @@ -58,13 +58,14 @@ public:\n>  \n>  \tint qbuf(unsigned int index);\n>  \n> -\tvoid waitForBufferAvailable();\n> -\tbool isBufferAvailable();\n> +\tvoid waitForBufferAvailable() LIBCAMERA_TSA_EXCLUDES(bufferMutex_);\n> +\tbool isBufferAvailable() LIBCAMERA_TSA_EXCLUDES(bufferMutex_);\n>  \n>  \tbool isRunning();\n>  \n>  private:\n> -\tvoid requestComplete(libcamera::Request *request);\n> +\tvoid requestComplete(libcamera::Request *request)\n> +\t\tLIBCAMERA_TSA_EXCLUDES(bufferLock_);\n>  \n>  \tstd::shared_ptr<libcamera::Camera> camera_;\n>  \tstd::unique_ptr<libcamera::CameraConfiguration> config_;\n> @@ -77,11 +78,12 @@ private:\n>  \tstd::vector<std::unique_ptr<libcamera::Request>> requestPool_;\n>  \n>  \tstd::deque<libcamera::Request *> pendingRequests_;\n> -\tstd::deque<std::unique_ptr<Buffer>> completedBuffers_;\n> +\tstd::deque<std::unique_ptr<Buffer>> completedBuffers_\n> +\t\tLIBCAMERA_TSA_GUARDED_BY(bufferLock_);\n>  \n>  \tint efd_;\n>  \n>  \tlibcamera::Mutex bufferMutex_;\n>  \tlibcamera::ConditionVariable bufferCV_;\n> -\tunsigned int bufferAvailableCount_;\n> +\tunsigned int bufferAvailableCount_ LIBCAMERA_TSA_GUARDED_BY(bufferMutex_);\n>  };","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 1FA62C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 28 Aug 2022 18:35:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 87FBA61FC0;\n\tSun, 28 Aug 2022 20:35:56 +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 0B4DD61FBD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 28 Aug 2022 20:35:55 +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 65A27E5;\n\tSun, 28 Aug 2022 20:35:54 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661711756;\n\tbh=KonHyfeZWMJO5FFWrQW2438AScVcWoi9pVfUpM5j2PQ=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=oQJIkg6wwivtKwD0Lvc+Yd77hu4dUpnxHOExLEm3MXgoY5d2jQe4uwHYrVegj+dZh\n\tpBSTBATY8WRPC6AHZOOZCETiyQycc89633ErfetqAkFafUkK6X5ZDINBHc9rRxV+nb\n\tvpKCa5raltcHlhvpgE1F2JDEMF25rVB7ri7grbI5P4bRMXcTA1ZKp9g2ShJHn0/NUw\n\tvxamFgZAp86Gw5TAY6G39x3kfAHqadsLj7f8tF9RYxBzm067qVwrWsyTnH8bYC6FcX\n\tfyJfWJGG87fWJAT8ivYAxcJ6R+re+mOt2WpkccJNnm2Skgwmn6DMfoC5ueZMkdxv9p\n\tK+QsWastF6Rjg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661711754;\n\tbh=KonHyfeZWMJO5FFWrQW2438AScVcWoi9pVfUpM5j2PQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=iZ0h7g8zoG3oDMaRyO9PXtVFyFUA+CQlE5ve73blZD91bwxcNWvxe78PthD6VWdzT\n\t9CVAcIGc7gi3MkeQnoJORH2YxIMvRVEZq+N9cfNZP08ecdF3eOFSWjsX05xHk7IOdH\n\tKHO/SUJ947Ha36Htmrx+stHn0Gj1elUJenS9kQ0w="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"iZ0h7g8z\"; dkim-atps=neutral","Date":"Sun, 28 Aug 2022 21:35:46 +0300","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<Ywu1glqJn9/TTEoU@pendragon.ideasonboard.com>","References":"<20220620165027.549085-1-umang.jain@ideasonboard.com>\n\t<20220620165027.549085-6-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220620165027.549085-6-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 5/5] v4l2: v4l2_camera: Apply clang\n\tthread safety annotation","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]