From patchwork Thu Nov 3 13:20:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 17753 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 F1EFBC3285 for ; Thu, 3 Nov 2022 13:20:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E72A63081; Thu, 3 Nov 2022 14:20:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1667481653; bh=xehfdJ8bkEZHFwHbUtXONtyLqRSwjY8EfbL0qgWYzUc=; 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=GihTOB2QJ/H/SHN+TdjwvQwsA/l8Bq/QDrc1rc3FLyKJmROjAloI056cuLRGPiFXS 6kPAI6kaAD58E1Ro3S/JLL8YNjJo/xvLnylGjJzA0TUzsuNzcPhAKzrFtpN6fYToaW Yh5d5drT6/h0UlBYvUiU794X1E62FHWRUg2ZV24G5vjt7KxIoQc8ZPf9k8I9iWhqVT eFvZJ060i2FJWqDvLWuuQ/DasHOcZ71V7jufzbi1DMa6PBvt7pwjHbDyAfmvhvvrNQ inFzZMNoeLx63m+jcWa+bNwKrlgejCg46mHKp/fGCGTimBqgmNyRHe2P3hWiRpu4Ct dMUMAuJG7NusQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1088261F42 for ; Thu, 3 Nov 2022 14:20:52 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SXqdvjWp"; dkim-atps=neutral Received: from umang.jainideasonboard.com (unknown [103.251.226.107]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D98334B2; Thu, 3 Nov 2022 14:20:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1667481651; bh=xehfdJ8bkEZHFwHbUtXONtyLqRSwjY8EfbL0qgWYzUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SXqdvjWpzyYQgdeN0iqQUH9qOzfNoHK2gcIspM32p58uUGcVbLfUkXQlHJHUPCr4K D71z1IvYb4whWEL2I0FXRYWFfLklEMdLYQUNUHL9Cbb4M9g58nymlf+jyHllfHQD0N lfFj/S9x890xfrnEjGOzDieqPNXc29f2AxaIPXIg= To: libcamera-devel@lists.libcamera.org Date: Thu, 3 Nov 2022 18:50:37 +0530 Message-Id: <20221103132041.64644-2-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 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 Reviewed-by: Umang Jain --- include/libcamera/base/semaphore.h | 10 +++++----- src/libcamera/base/semaphore.cpp | 4 +++- 2 files changed, 8 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..6217e386 100644 --- a/src/libcamera/base/semaphore.cpp +++ b/src/libcamera/base/semaphore.cpp @@ -56,7 +56,9 @@ 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; }