From patchwork Thu Nov 3 13:20:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 17757 X-Patchwork-Delegate: umang.jain@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B68FCC3287 for ; Thu, 3 Nov 2022 13:21:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 38F0D63089; Thu, 3 Nov 2022 14:21:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1667481665; bh=kfmepM45QS7U93rRH4WG1oOHio2OG+kiikAbDbHpmHw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=j4J4f9Y2gPsb74/cPT/Uzm1cNt0fFn0cpTcsU7MsOASwuW2K+s6c2Qs6tXN/Q6+zJ IrWE7gIGU7DxeuOb/4fGaIl0mgE/HpfTRi9c7e+l4GqqAM4DqZFXEWRZhi4WbSuqBY m3Jh+0Zlb19cPTYWhcaSzVVAVMVpqvkSe9l9vgSXmeBkZYyyWu9cV6GNKpfSZ5dxFI 0g1/Z3TgRbsblsPfskUpe5KuFxlODGNcUBTZWBw+Z8xkzVAADUNY3v5/wLBiETWLtR vY9pN66k3J7iDkHw0aoMl6YXxJfuJ1hkXg7GV76gPp+8nWMgsJN//p7ah/cez/y7G3 L3CJ9k8kfOq4Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CDC6E63079 for ; Thu, 3 Nov 2022 14:21:03 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JTnIco7O"; dkim-atps=neutral Received: from umang.jainideasonboard.com (unknown [103.251.226.107]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ED9C856D; Thu, 3 Nov 2022 14:21:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1667481663; bh=kfmepM45QS7U93rRH4WG1oOHio2OG+kiikAbDbHpmHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JTnIco7OJvKaIo+aPeSvV0ERBq0uaAPifQv1vbf2augKtPbm7Bu3HTUZMeJ2XhoBi oaq2cSy5GX+qdJVa+yHgnN+2Z9Ho55iyKdhJ6qVt51cfcCuVh3UuP1+6u4c0wotupj pwgAsFZhKSrPOjaA3YbRIAvdYeqn7vGE1Jn4FXIE= To: libcamera-devel@lists.libcamera.org Date: Thu, 3 Nov 2022 18:50:41 +0530 Message-Id: <20221103132041.64644-6-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221103132041.64644-1-umang.jain@ideasonboard.com> References: <20221103132041.64644-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 5/5] v4l2: v4l2_camera: Apply clang thread safety annotation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Hirokazu Honda This annotates member functions and variables of V4L2Camera by clang thread safety annotations. Signed-off-by: Hirokazu Honda Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain --- src/v4l2/v4l2_camera.cpp | 5 ++--- src/v4l2/v4l2_camera.h | 14 ++++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp index e922b9e6..7b97c2d5 100644 --- a/src/v4l2/v4l2_camera.cpp +++ b/src/v4l2/v4l2_camera.cpp @@ -71,11 +71,10 @@ std::vector V4L2Camera::completedBuffers() { std::vector v; - bufferLock_.lock(); + MutexLocker lock(bufferLock_); for (std::unique_ptr &metadata : completedBuffers_) v.push_back(*metadata.get()); completedBuffers_.clear(); - bufferLock_.unlock(); return v; } @@ -278,7 +277,7 @@ int V4L2Camera::qbuf(unsigned int index) void V4L2Camera::waitForBufferAvailable() { MutexLocker locker(bufferMutex_); - bufferCV_.wait(locker, [&] { + bufferCV_.wait(locker, [&]() LIBCAMERA_TSA_REQUIRES(bufferMutex_) { return bufferAvailableCount_ >= 1 || !isRunning_; }); if (isRunning_) diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index 03e74118..d3483444 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -39,7 +39,7 @@ public: void bind(int efd); void unbind(); - std::vector completedBuffers(); + std::vector completedBuffers() LIBCAMERA_TSA_EXCLUDES(bufferLock_); int configure(libcamera::StreamConfiguration *streamConfigOut, const libcamera::Size &size, @@ -58,13 +58,14 @@ public: int qbuf(unsigned int index); - void waitForBufferAvailable(); - bool isBufferAvailable(); + void waitForBufferAvailable() LIBCAMERA_TSA_EXCLUDES(bufferMutex_); + bool isBufferAvailable() LIBCAMERA_TSA_EXCLUDES(bufferMutex_); bool isRunning(); private: - void requestComplete(libcamera::Request *request); + void requestComplete(libcamera::Request *request) + LIBCAMERA_TSA_EXCLUDES(bufferLock_); std::shared_ptr camera_; std::unique_ptr config_; @@ -77,11 +78,12 @@ private: std::vector> requestPool_; std::deque pendingRequests_; - std::deque> completedBuffers_; + std::deque> completedBuffers_ + LIBCAMERA_TSA_GUARDED_BY(bufferLock_); int efd_; libcamera::Mutex bufferMutex_; libcamera::ConditionVariable bufferCV_; - unsigned int bufferAvailableCount_; + unsigned int bufferAvailableCount_ LIBCAMERA_TSA_GUARDED_BY(bufferMutex_); };