From patchwork Mon Jun 20 16:50:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16292 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 B06F3BE173 for ; Mon, 20 Jun 2022 16:50:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 62E2165639; Mon, 20 Jun 2022 18:50:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655743849; bh=TNAo5JOE5ucC6xv4gLIeCiKNL45QTePppXzuWox7h2A=; 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=QcpFBvkTg4Ozm9EMA6cwzGwQRfj9h16BlZCooKCSpD5zbyfjKE2N0BVn9t+DX2TCb HyvfEVi/gBQifaBfZvZwWPegu3vt3gzYbvoaEaHPISo3LH5gRbAIgxylGu1aFo5zaN 96OjnXes0VyauoI0YOh4xlCUSTcMbj9sWUbZp+8xHGrA8ee5IKvInNL16gGeeWr6iq zb1Dywvpw9n7b6+RKxEUn/jvwYo6KR33LbLwHPGf2XHuvsC1x/sIqK7G7HFRO6jtxp tIbo4b2wUU4PK3mQXc01XQeLIeZyf1vWqOvpNSZZuNm03ErfdI37sK9P0Ufap+PMzp h/8a4WgDKAQpQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A9E5565634 for ; Mon, 20 Jun 2022 18:50:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Et/hdK7g"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [IPv6:2401:4900:1f3f:e389:cb58:4104:f66:a571]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 771A9883; Mon, 20 Jun 2022 18:50:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655743847; bh=TNAo5JOE5ucC6xv4gLIeCiKNL45QTePppXzuWox7h2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Et/hdK7gMPrVrLV76lRQapRvPitC1nJobOizYsUEG2Iq5chJdWloqwpUNH05bKuj/ WlqYOGvO98EWS9LMoloRwndN67dctDy7WZIkDql+ayllP0eW8WgmylmtOqwwtYpcg1 AOzxG/lVK/FMX4xJY7ejgpcXd1ptqVVvVJPoqrCs= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 22:20:27 +0530 Message-Id: <20220620165027.549085-6-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220620165027.549085-1-umang.jain@ideasonboard.com> References: <20220620165027.549085-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 --- 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_); };