From patchwork Mon Jun 20 16:50:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16288 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 480ECBE173 for ; Mon, 20 Jun 2022 16:50:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0004765638; Mon, 20 Jun 2022 18:50:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655743841; bh=29qR+ILEBTk8VYV8GzzLgjKDhkhjUBFhr2ov/cZBsTQ=; 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=YFI7m0KgE2EO6DY38TSlS9DIYBFlEheAzK4AnY+VgY4jqvOYBS1BxiLf4I+4t94Cd uhmvz4r06MN6zY/ts1XT70aM0m4CF3ghGGJ6xwJSjouTorGfnDLmhMXorhHIpw9Wiz SZoHuSXYWz1/G1otQuB8BfdMGirQmJ70p2XNGjtbYVnLth+j7LyBgetOhTo6Xr9yub nfKL+Z44ObkNZhe4uo5ZtRV0e+iIJUxS2436rAw023ObeQisakJgF3SMPF7V+wZvef p4Er9DaqC1X7JxE73mGe0nPktyKRnXBxFyYbR3JN8iMLCDeMh35kdJ7U/64AvyYvk6 SdyT/QMwZP2nA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F88B65632 for ; Mon, 20 Jun 2022 18:50:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="QOT0c5Q1"; 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 2F999883; Mon, 20 Jun 2022 18:50:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655743839; bh=29qR+ILEBTk8VYV8GzzLgjKDhkhjUBFhr2ov/cZBsTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QOT0c5Q1VFVv/gfasX6LGvJQP8WlUmZH3PmoYTIolf6LgxjSZQW6baGJcWPD2kKOy 9I0YK1QiwH0nOClv3E8Nz7ozRXHdXBti0O+5nIlw1B0FZ5OsTlH75n8NSM71KfQUuZ U/2G/DnCJV+6qQoRRnOkNn9B1/LoUSXWBoLg/QJw= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 22:20:23 +0530 Message-Id: <20220620165027.549085-2-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 1/5] libcamera: base: semaphore: 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 Semaphore by clang thread safety annotations. Signed-off-by: Hirokazu Honda Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- include/libcamera/base/semaphore.h | 10 +++++----- src/libcamera/base/semaphore.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/libcamera/base/semaphore.h b/include/libcamera/base/semaphore.h index c11e8dd1..f1052317 100644 --- a/include/libcamera/base/semaphore.h +++ b/include/libcamera/base/semaphore.h @@ -18,15 +18,15 @@ class Semaphore public: Semaphore(unsigned int n = 0); - unsigned int available(); - void acquire(unsigned int n = 1); - bool tryAcquire(unsigned int n = 1); - void release(unsigned int n = 1); + unsigned int available() LIBCAMERA_TSA_EXCLUDES(mutex_); + void acquire(unsigned int n = 1) LIBCAMERA_TSA_EXCLUDES(mutex_); + bool tryAcquire(unsigned int n = 1) LIBCAMERA_TSA_EXCLUDES(mutex_); + void release(unsigned int n = 1) LIBCAMERA_TSA_EXCLUDES(mutex_); private: Mutex mutex_; ConditionVariable cv_; - unsigned int available_; + unsigned int available_ LIBCAMERA_TSA_GUARDED_BY(mutex_); }; } /* namespace libcamera */ diff --git a/src/libcamera/base/semaphore.cpp b/src/libcamera/base/semaphore.cpp index 4fe30293..1e1c2efa 100644 --- a/src/libcamera/base/semaphore.cpp +++ b/src/libcamera/base/semaphore.cpp @@ -56,7 +56,7 @@ unsigned int Semaphore::available() void Semaphore::acquire(unsigned int n) { MutexLocker locker(mutex_); - cv_.wait(locker, [&] { return available_ >= n; }); + cv_.wait(locker, [&]() LIBCAMERA_TSA_REQUIRES(mutex_) { return available_ >= n; }); available_ -= n; } From patchwork Mon Jun 20 16:50:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16289 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 B2299BE173 for ; Mon, 20 Jun 2022 16:50:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 74B416563A; Mon, 20 Jun 2022 18:50:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655743843; bh=re4OBnNCW5TdEGTRkkjM/RrhyqeVTtPo5/e/DE+wZ4s=; 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=Y5WY31OR16WUZFBV+idZ9UBz6mSdSeRi78UAOmez1k9B6UqLQoMFskKGZCPZKURFA UgCvYvO8JNhFg4EoKkXX9tBLVLgNhBQI/OddP2qsSB3KBKjaFuzfaEuEDu50QA0d5U M382VwdIciVQcg7lBIHe+U2kndEwaX6UCV2arXKy9wLwPhGO80qMBKWNXsVcPfckaM d/wZM4MF9ANMO0a4gk3/fHP8WaCXD2JDoK17Q2FlYRMc/CDLpmvf9H2jKtv8ymIP9k 3ABIIOefrkV2scz/TfKm3beUD8zyqj6lT7RBg0h1WaYKqx9yKAk+uyM8B+uKY8tbjN eyyS59+hIRJeg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F74A65634 for ; Mon, 20 Jun 2022 18:50:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ek7W0TgT"; 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 595A9883; Mon, 20 Jun 2022 18:50:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655743841; bh=re4OBnNCW5TdEGTRkkjM/RrhyqeVTtPo5/e/DE+wZ4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ek7W0TgTkcTq2f1G1Wb5gAmkHAgRJqaDz6tSsITL9WoW6Fca+HEalLeqTtfxoV83T heUqlzsK58pu4GdoVxDmJ8aPo5S9zPKmxK0g+YOrsSW79mYiZxabjMxQ/s1+sXibUm 2E8DTSe61wjczo7rH/c+ikvPnSPgWkd/Dhtp5Y7k= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 22:20:24 +0530 Message-Id: <20220620165027.549085-3-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 2/5] libcamera: base: thread: 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 variables of ThreadData by clang thread safety annotations. Signed-off-by: Hirokazu Honda Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/libcamera/base/thread.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index 6bda9d14..2e26b83c 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -151,7 +151,7 @@ private: friend class ThreadMain; Thread *thread_; - bool running_; + bool running_ LIBCAMERA_TSA_GUARDED_BY(mutex_); pid_t tid_; Mutex mutex_; @@ -160,7 +160,7 @@ private: ConditionVariable cv_; std::atomic exit_; - int exitCode_; + int exitCode_ LIBCAMERA_TSA_GUARDED_BY(mutex_); MessageQueue messages_; }; @@ -422,11 +422,19 @@ bool Thread::wait(utils::duration duration) { MutexLocker locker(data_->mutex_); - if (duration == utils::duration::max()) - data_->cv_.wait(locker, [&]() { return !data_->running_; }); - else - hasFinished = data_->cv_.wait_for(locker, duration, - [&]() { return !data_->running_; }); + if (duration == utils::duration::max()) { + data_->cv_.wait( + locker, + [&]() LIBCAMERA_TSA_REQUIRES(data_->mutex_) { + return !data_->running_; + }); + } else { + hasFinished = data_->cv_.wait_for( + locker, duration, + [&]() LIBCAMERA_TSA_REQUIRES(data_->mutex_) { + return !data_->running_; + }); + } } if (thread_.joinable()) From patchwork Mon Jun 20 16:50:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16290 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 9E7BBBE173 for ; Mon, 20 Jun 2022 16:50:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C7606563E; Mon, 20 Jun 2022 18:50:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655743845; bh=T6yGjc+PySgh/1/kxCKfvN3M0leBsGQPLp/OacR3Tl0=; 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=YUfjgUwKxf1NefJWkw4N0Myy+WY2w2X4FFoP0OQ1ITNY8deUBTPj0u/7LiltjnaS5 qJ0J+uB+G33YgMG0wXBerESxjwRBg1UltEfLMfIMnzSv0v0/+BPU5BoR5KeMmUZy9H PZx4F0s0WQwhEDXuqpKUTnKi4H3QK1FmRvO8PxXKrwhwN3AHEVTyqQ6LnGriVa613o CN6neUCe2Rjfkf09Xl+W6HiQovbHjRsA9idjI8NDQxYx1fvd6m2rtAixehlIWo6r1B qCqVeq3dDRUPdlvZcOwn5RSHF1Vm+57IxWC6mFoGw4vQaZbwtLLVg9tsfF7bjXFCK1 ssP+xOUmPbh+Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D9E4865637 for ; Mon, 20 Jun 2022 18:50:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="I9MuwbmP"; 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 46A09883; Mon, 20 Jun 2022 18:50:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655743843; bh=T6yGjc+PySgh/1/kxCKfvN3M0leBsGQPLp/OacR3Tl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I9MuwbmPGzOf1EBfzF3WEzeOx0m0fjtTbpNczCrgDp/XInluVAJuPkimCScl6ZujZ AloZ1E9FQJgmc/t4pJrO7xgAy9wERsitiwHT9QT63N75Vld78VNI4PD8ovEKtdV58+ 99nR4mwdD5c8BzoEFbbC3G6E3+gaQHscF050Qp90= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 22:20:25 +0530 Message-Id: <20220620165027.549085-4-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 3/5] libcamera: camera_manager: 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 CameraManager::Private by clang thread safety annotations. Signed-off-by: Hirokazu Honda Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/libcamera/camera_manager.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 70d73822..4f946516 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -42,8 +42,8 @@ public: int start(); void addCamera(std::shared_ptr camera, - const std::vector &devnums); - void removeCamera(Camera *camera); + const std::vector &devnums) LIBCAMERA_TSA_EXCLUDES(mutex_); + void removeCamera(Camera *camera) LIBCAMERA_TSA_EXCLUDES(mutex_); /* * This mutex protects @@ -52,8 +52,8 @@ public: * - cameras_ and camerasByDevnum_ after initialization */ mutable Mutex mutex_; - std::vector> cameras_; - std::map> camerasByDevnum_; + std::vector> cameras_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + std::map> camerasByDevnum_ LIBCAMERA_TSA_GUARDED_BY(mutex_); protected: void run() override; @@ -61,11 +61,11 @@ protected: private: int init(); void createPipelineHandlers(); - void cleanup(); + void cleanup() LIBCAMERA_TSA_EXCLUDES(mutex_); ConditionVariable cv_; - bool initialized_; - int status_; + bool initialized_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + int status_ LIBCAMERA_TSA_GUARDED_BY(mutex_); std::unique_ptr enumerator_; @@ -87,7 +87,8 @@ int CameraManager::Private::start() { MutexLocker locker(mutex_); - cv_.wait(locker, [&] { return initialized_; }); + cv_.wait(locker, + [&]() LIBCAMERA_TSA_REQUIRES(mutex_) { return initialized_; }); status = status_; } From patchwork Mon Jun 20 16:50:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16291 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 331B1BE173 for ; Mon, 20 Jun 2022 16:50:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DDC8A65641; Mon, 20 Jun 2022 18:50:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655743846; bh=UAJykEr45Nf0wkT3z56vMjcJNiCLAm/eR/9iX6k9oDc=; 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=yuyWgZMZWvfH53EOY8bw8SIRxVfZ5iu0XM0veE/XpOm6VlRTmm5vW6cKNmUMb8HMo IHqeGn4mKxxJrUJ7ZQXv9KUn2RewezL1wwx7pRsCt5hDhwOY15i58QnmNUXChf1QvQ in8kLjBtYCB5xu4sSd37WPfbkXJHP4MvM2w88Tq4ZJFhgruX2ZKsKJuOVQX8OagW6+ TNvtYHkqj7C9qyIR0+I1FiV5ctmvBBiuioSa0fF/uQkKZTLc5K/F6LllKtIM7psAHR eYwdTjlUiGYq7hEeL6+RppfmdcCyfsuptvv81oKTh9Q0U7DQA7OiPGCiy2uEub4ypH Pz8AxGBU4iVrw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 97A8F65640 for ; Mon, 20 Jun 2022 18:50:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZC4mHayR"; 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 6C4B0883; Mon, 20 Jun 2022 18:50:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655743845; bh=UAJykEr45Nf0wkT3z56vMjcJNiCLAm/eR/9iX6k9oDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZC4mHayRmMCy5CxWDmJDAAva9UBlCPQMrJdBhxR2ResLE3mAG2PJcXX6eg2E6Dr8b 4mKfehjgjYFef9JbNmKAbab7CKtqZ8nCurKb2bT0oCzKNQUcIdxtb0xRJkIeii6T6i zzIGpEtRmm4TKoBmOQIRpsBdPilA/qEaZgpGbUpI= To: libcamera-devel@lists.libcamera.org Date: Mon, 20 Jun 2022 22:20:26 +0530 Message-Id: <20220620165027.549085-5-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 4/5] v4l2: v4l2_camera_proxy: 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 of V4L2CameraProxy by clang thread safety annotations. Signed-off-by: Hirokazu Honda Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/v4l2/v4l2_camera_proxy.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index 76ca2d8a..8a0195e1 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -27,13 +27,15 @@ class V4L2CameraProxy public: V4L2CameraProxy(unsigned int index, std::shared_ptr camera); - int open(V4L2CameraFile *file); - void close(V4L2CameraFile *file); + int open(V4L2CameraFile *file) LIBCAMERA_TSA_EXCLUDES(proxyMutex_); + void close(V4L2CameraFile *file) LIBCAMERA_TSA_EXCLUDES(proxyMutex_); void *mmap(V4L2CameraFile *file, void *addr, size_t length, int prot, - int flags, off64_t offset); - int munmap(V4L2CameraFile *file, void *addr, size_t length); + int flags, off64_t offset) LIBCAMERA_TSA_EXCLUDES(proxyMutex_); + int munmap(V4L2CameraFile *file, void *addr, size_t length) + LIBCAMERA_TSA_EXCLUDES(proxyMutex_); - int ioctl(V4L2CameraFile *file, unsigned long request, void *arg); + int ioctl(V4L2CameraFile *file, unsigned long request, void *arg) + LIBCAMERA_TSA_EXCLUDES(proxyMutex_); private: bool validateBufferType(uint32_t type); 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_); };