From patchwork Wed Dec 1 07:07:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14927 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 83C95BF415 for ; Wed, 1 Dec 2021 07:07:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3A79160729; Wed, 1 Dec 2021 08:07:40 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="JMcenpf8"; dkim-atps=neutral Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5C89D60718 for ; Wed, 1 Dec 2021 08:07:38 +0100 (CET) Received: by mail-pj1-x1031.google.com with SMTP id gf14-20020a17090ac7ce00b001a7a2a0b5c3so20280982pjb.5 for ; Tue, 30 Nov 2021 23:07:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RfQVNtG/v2bEcPhs3B2DWL5RmPs7AC4Gxpfmf3NMFrs=; b=JMcenpf8dH7NwKRwY8hrOWG0uS3BL8IeXdCsLY3mkn0HgnSsWmNY8eJFd0TpCygPdT is4kYOc0TUsRuLTnEoxaJKQOy1DIcL/tz7ayIObaVD7XcFlLNjT2KU7ZZ6qVt/khDWLy ZvTV3s0UTAfuUPabsO0XkNYfgoiMhETL8dluc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RfQVNtG/v2bEcPhs3B2DWL5RmPs7AC4Gxpfmf3NMFrs=; b=FMc7//2qh1eh/dOCzI715FISZPHo/HwnW6V55j1nugB52rzaywUfDZ7DA7FdlDfvsb kczXWIeP/BRbfzMhYPDOP5ooVhQlM0KPXxm+4+zDjePrGhwry5hXaKW+rvp9UU9geu/o WCkKDqb9+59hDaroWeywoNhqyvEuvJzX2Vbky+FdkLiRqmEsBHpyAnSZhHGEGF0OzphR UKGulgCJFI9s03iO7JaCTrmwtdcPnTl4HCtTRdBb4gaKipqU1glUCRC2+Y23g0eNshd6 VIgiMJjNmw+dA8eFT22rm+/uotye0mfqngiVRIYgQlh0/lpS67wt4F6nZPJ+aZCpQlkH +dhw== X-Gm-Message-State: AOAM531/xY/gy7yWYRNDNjlYyrsH9xLXTqEQ9tSSBnPD9G8DUkAGSick lfeRDkmI7EOlfmNS4BfyVBJ8o0N2kYo3Tw== X-Google-Smtp-Source: ABdhPJzO2ttrZ+Ix4PpCys49FEAVGqiqjmu2L4drqppiJ7lMBBGuC+MR+mdRtyVO0oEu8w+IbiM53A== X-Received: by 2002:a17:902:6a8a:b0:143:905f:aec7 with SMTP id n10-20020a1709026a8a00b00143905faec7mr5482176plk.8.1638342456322; Tue, 30 Nov 2021 23:07:36 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:35 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:17 +0900 Message-Id: <20211201070728.3114247-2-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 01/12] libcamera: base: Introduce ConditionVariable 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" ConditionVariable is alias to std::condition_variable. This replaces std::condition_variable with the ConditionVariable. It enables replacing ConditionVariable implementation easily in the following patches. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- include/libcamera/base/semaphore.h | 4 +--- include/libcamera/base/thread.h | 2 ++ src/android/camera_stream.h | 3 +-- src/libcamera/base/thread.cpp | 8 ++++++-- src/libcamera/camera_manager.cpp | 3 +-- src/v4l2/v4l2_camera.h | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/libcamera/base/semaphore.h b/include/libcamera/base/semaphore.h index ae87d319..ec05fad3 100644 --- a/include/libcamera/base/semaphore.h +++ b/include/libcamera/base/semaphore.h @@ -7,8 +7,6 @@ #pragma once -#include - #include #include @@ -26,7 +24,7 @@ public: private: Mutex mutex_; - std::condition_variable cv_; + ConditionVariable cv_; unsigned int available_; }; diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h index 32ebc80a..1ebf8363 100644 --- a/include/libcamera/base/thread.h +++ b/include/libcamera/base/thread.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -26,6 +27,7 @@ class Object; class ThreadData; class ThreadMain; +using ConditionVariable = std::condition_variable; using Mutex = std::mutex; using MutexLocker = std::unique_lock; diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index e9da75f0..e4808369 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include #include @@ -154,7 +153,7 @@ private: PostProcessor *postProcessor_; libcamera::Mutex mutex_; - std::condition_variable cv_; + libcamera::ConditionVariable cv_; std::queue requests_; State state_ = State::Stopped; diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index d0ca30e3..b893135f 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -158,7 +157,7 @@ private: std::atomic dispatcher_; - std::condition_variable cv_; + ConditionVariable cv_; std::atomic exit_; int exitCode_; @@ -205,6 +204,11 @@ ThreadData *ThreadData::current() return data; } +/** + * \typedef ConditionVariable + * \brief An alias for std::condition_variable + */ + /** * \typedef Mutex * \brief An alias for std::mutex diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index e78bb1d7..77ff3bd1 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -7,7 +7,6 @@ #include -#include #include #include @@ -63,7 +62,7 @@ private: void createPipelineHandlers(); void cleanup(); - std::condition_variable cv_; + ConditionVariable cv_; bool initialized_; int status_; diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index 94263b2f..4afbb331 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -82,6 +82,6 @@ private: int efd_; libcamera::Mutex bufferMutex_; - std::condition_variable bufferCV_; + libcamera::ConditionVariable bufferCV_; unsigned int bufferAvailableCount_; }; From patchwork Wed Dec 1 07:07:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14928 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 23EACBF415 for ; Wed, 1 Dec 2021 07:07:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C3AFD6072A; Wed, 1 Dec 2021 08:07:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="c1SjOnDc"; dkim-atps=neutral Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D3CA260727 for ; Wed, 1 Dec 2021 08:07:39 +0100 (CET) Received: by mail-pg1-x532.google.com with SMTP id 200so22646955pga.1 for ; Tue, 30 Nov 2021 23:07:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hri0Xm34PsgBbaDCXWbRIaQJpAoLrbjERv7g2d7844k=; b=c1SjOnDcOFtqXCE1AvevpQ4Xh0Y4+JEShEzKFl8GGXTE0O+FjZPi00+9NWMOQdUvTT WBNUEaoAmYrVmWuR/grq0+9ZL7If8GXQbw3eSkqvvD15AfeJIeRWBaO2+AtkQzS8U7nD S9aP+fZYrBlb6F+Zt9yBHskG8An2/OIjgQHzM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hri0Xm34PsgBbaDCXWbRIaQJpAoLrbjERv7g2d7844k=; b=SEkIKW15WZztG30Md0lFwXVhbWnSpsjvzY3ZTEbLaVynbMWzNc7XGY3GK1c8biyqat PyIcPaegB3KRKPvTjB8SkUgLmVoezhswOAI4XkZhIFOzmbSOchvftCxwU3iFBWI4/vqk 2vJN3WjHP0fKmsctglU1mGUnebh8Y5DM+dVURRQJD4X65jgx17ngCQO9iHfbRK8WyQRu iwR0OoK3sH+cAHeNAvfAMe2Y4R70e7HRfDeFOImkblLNd9V4aM8zefoQe+/n8juxxVMz tr4bl78GQkAjADEfpPD7WNgdQx1Wzpq5kUJpF55ie3mJc0Urw0yztaaygc6w7ZkI12WR 8K3A== X-Gm-Message-State: AOAM533N94Y3REnyKpwY7ksnov0D4lz1B9KQeL+M9Q2DBpLpJPX/YzuA LPMUpfaA7p0iwURu75cvHatDvjQkT2onYA== X-Google-Smtp-Source: ABdhPJyBKlz+/pz2ESJbqwspKMEKIrZ2bL9RfB87OPte43lNkLdF4ZJtt2lUEEWP/RDJ2KX1t2RfZg== X-Received: by 2002:a05:6a00:9a3:b0:49f:bf9b:3192 with SMTP id u35-20020a056a0009a300b0049fbf9b3192mr4175982pfg.44.1638342458092; Tue, 30 Nov 2021 23:07:38 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:37 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:18 +0900 Message-Id: <20211201070728.3114247-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 02/12] android: Consolidate mutex classes to Mutex and MutexLocker 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" std::mutex and std::unique_lcok are used in android directories, mixing Mutex and MutexLocker. This consolidates them to Mutex and MutexLocker. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.h | 1 - src/android/camera_hal_manager.h | 7 ++----- src/android/camera_request.h | 4 ++-- src/android/camera_stream.cpp | 12 ++++++------ src/android/camera_stream.h | 3 +-- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 51fe7da2..bda0b376 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -9,7 +9,6 @@ #include #include -#include #include #include diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index 192f2fc5..cc310f90 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -8,7 +8,6 @@ #pragma once #include -#include #include #include #include @@ -18,6 +17,7 @@ #include #include +#include #include @@ -44,9 +44,6 @@ public: private: LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraHalManager) - using Mutex = std::mutex; - using MutexLocker = std::unique_lock; - static constexpr unsigned int firstExternalCameraId_ = 1000; CameraHalManager(); @@ -64,7 +61,7 @@ private: const camera_module_callbacks_t *callbacks_; std::vector> cameras_; std::map cameraIdsMap_; - Mutex mutex_; + libcamera::Mutex mutex_; unsigned int numInternalCameras_; unsigned int nextExternalCameraId_; diff --git a/src/android/camera_request.h b/src/android/camera_request.h index f3cb6d64..88d501a8 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -9,10 +9,10 @@ #include #include -#include #include #include +#include #include #include @@ -58,7 +58,7 @@ public: /* Keeps track of streams requiring post-processing. */ std::map pendingStreamsToProcess_; - std::mutex streamsProcessMutex_; + libcamera::Mutex streamsProcessMutex_; Camera3RequestDescriptor(libcamera::Camera *camera, const camera3_capture_request_t *camera3Request); diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 9023c13c..5a62b7cd 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -119,7 +119,7 @@ int CameraStream::configure() if (type_ == Type::Internal) { allocator_ = std::make_unique(cameraDevice_->camera()); - mutex_ = std::make_unique(); + mutex_ = std::make_unique(); int ret = allocator_->allocate(stream()); if (ret < 0) @@ -208,7 +208,7 @@ FrameBuffer *CameraStream::getBuffer() if (!allocator_) return nullptr; - std::lock_guard locker(*mutex_); + MutexLocker locker(*mutex_); if (buffers_.empty()) { LOG(HAL, Error) << "Buffer underrun"; @@ -226,7 +226,7 @@ void CameraStream::putBuffer(FrameBuffer *buffer) if (!allocator_) return; - std::lock_guard locker(*mutex_); + MutexLocker locker(*mutex_); buffers_.push_back(buffer); } @@ -239,7 +239,7 @@ CameraStream::PostProcessorWorker::PostProcessorWorker(PostProcessor *postProces CameraStream::PostProcessorWorker::~PostProcessorWorker() { { - libcamera::MutexLocker lock(mutex_); + MutexLocker lock(mutex_); state_ = State::Stopped; } @@ -250,7 +250,7 @@ CameraStream::PostProcessorWorker::~PostProcessorWorker() void CameraStream::PostProcessorWorker::start() { { - libcamera::MutexLocker lock(mutex_); + MutexLocker lock(mutex_); ASSERT(state_ != State::Running); state_ = State::Running; } @@ -308,7 +308,7 @@ void CameraStream::PostProcessorWorker::run() void CameraStream::PostProcessorWorker::flush() { - libcamera::MutexLocker lock(mutex_); + MutexLocker lock(mutex_); state_ = State::Flushing; lock.unlock(); diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index e4808369..adb5a37d 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -8,7 +8,6 @@ #pragma once #include -#include #include #include @@ -173,7 +172,7 @@ private: * The class has to be MoveConstructible as instances are stored in * an std::vector in CameraDevice. */ - std::unique_ptr mutex_; + std::unique_ptr mutex_; std::unique_ptr postProcessor_; std::unique_ptr worker_; From patchwork Wed Dec 1 07:07:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14929 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 7CAD3BF415 for ; Wed, 1 Dec 2021 07:07:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 359B160727; Wed, 1 Dec 2021 08:07:43 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="RVlZg/yu"; dkim-atps=neutral Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B232160721 for ; Wed, 1 Dec 2021 08:07:41 +0100 (CET) Received: by mail-pf1-x42e.google.com with SMTP id i12so23422842pfd.6 for ; Tue, 30 Nov 2021 23:07:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FEPgOt+Hso6kjyjJCaZkES4+k/22ZXFKdEsxG1OY+gI=; b=RVlZg/yul7nRwKiVmmeL1pYPeIpIXXJeoS9nN/nqT6OOLL9oZfCVRfvD7HoYSzMHlP 03CJosIZo+uQ9xHbH3nZcLNPVDHpUDASE2pJ1oiwelRHt6jSNgLkib/DTUSDYnbjUwAH snF0SkMbESF2IJ9JzMm4dw5kmzOPxvSEYlm6Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FEPgOt+Hso6kjyjJCaZkES4+k/22ZXFKdEsxG1OY+gI=; b=OV86EH4KuPQO7MuB9OjQvjFlCqplOfK4SGe6CNM4/5Rw0RETysiWtef2Sb5ufGU5d3 3+bYjHrEyLeS9k3OnlPcoa/VOT8iGWUYY6E2flXr2vdoh9a7vfLJXREXmD6+TYw+DLRT KWXtVh5Nb3X3B3goVfnjuWLWzPAfBUZ7Nc32CyR35U+lesPct/WlWu5DgTEnbfQ2paHI wvr3VCbBkOXNU4KnNsOCPkl9olXjOPuyJg4uKCUQ16RsLdsaw5C/ToO8J7lHRVZ/z3pB c7M2r1F1Me0Yy81jaU9sBc9tBrC92YG55m12N0ausug8BjKwaBfEVkGggA6JMywx5MG8 X8+A== X-Gm-Message-State: AOAM533cHCFRXU18p6w05kwEo8bGmeOQAKokYGxeXzN/DTkcEEqLZcde Qaq+8B06ADjo/5HWiSoJFuxgsqZeQ9HiLA== X-Google-Smtp-Source: ABdhPJzeyqZ703mGj6oH+q04zvsmSNPKiMyWoBZZfaCGPE5qNUC1/0DBOECwHnhj/Sn/E0YSvJ78uw== X-Received: by 2002:aa7:9acc:0:b0:4a2:b8b5:8813 with SMTP id x12-20020aa79acc000000b004a2b8b58813mr4383036pfp.4.1638342459872; Tue, 30 Nov 2021 23:07:39 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:39 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:19 +0900 Message-Id: <20211201070728.3114247-4-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 03/12] v4l2: Consolidate mutex classes to Mutex and MutexLocker 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" std::mutex and std::unique_lock are used in v4l2 directory, mixing Mutex and MutexLocker. This consolidates them to Mutex and MutexLocker. This also fixes vidioc_dqbuf argument to take Mutex instead of MutexLocker. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/v4l2/v4l2_camera.h | 4 ++-- src/v4l2/v4l2_camera_proxy.cpp | 8 ++++---- src/v4l2/v4l2_camera_proxy.h | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index 4afbb331..bf1b6de4 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -8,10 +8,10 @@ #pragma once #include -#include #include #include +#include #include #include @@ -71,7 +71,7 @@ private: bool isRunning_; - std::mutex bufferLock_; + libcamera::Mutex bufferLock_; libcamera::FrameBufferAllocator *bufferAllocator_; std::vector> requestPool_; diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp index 3610e63c..79bc880d 100644 --- a/src/v4l2/v4l2_camera_proxy.cpp +++ b/src/v4l2/v4l2_camera_proxy.cpp @@ -575,7 +575,7 @@ int V4L2CameraProxy::vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg) } int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, - MutexLocker *locker) + Mutex *lock) { LOG(V4L2Compat, Debug) << "Servicing vidioc_dqbuf fd = " << file->efd(); @@ -593,9 +593,9 @@ int V4L2CameraProxy::vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, return -EINVAL; if (!file->nonBlocking()) { - locker->unlock(); + lock->unlock(); vcam_->waitForBufferAvailable(); - locker->lock(); + lock->lock(); } else if (!vcam_->isBufferAvailable()) return -EAGAIN; @@ -753,7 +753,7 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *ar ret = vidioc_qbuf(file, static_cast(arg)); break; case VIDIOC_DQBUF: - ret = vidioc_dqbuf(file, static_cast(arg), &locker); + ret = vidioc_dqbuf(file, static_cast(arg), &proxyMutex_); break; case VIDIOC_STREAMON: ret = vidioc_streamon(file, static_cast(arg)); diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index fccec241..040954dd 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -14,6 +14,8 @@ #include #include +#include + #include #include "v4l2_camera.h" @@ -57,7 +59,7 @@ private: int vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, - libcamera::MutexLocker *locker); + libcamera::Mutex *lock); int vidioc_streamon(V4L2CameraFile *file, int *arg); int vidioc_streamoff(V4L2CameraFile *file, int *arg); From patchwork Wed Dec 1 07:07:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14930 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 E1590BF415 for ; Wed, 1 Dec 2021 07:07:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9D2A560718; Wed, 1 Dec 2021 08:07:45 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="MXf5iUhT"; dkim-atps=neutral Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5FA546072E for ; Wed, 1 Dec 2021 08:07:43 +0100 (CET) Received: by mail-pf1-x436.google.com with SMTP id n26so23435997pff.3 for ; Tue, 30 Nov 2021 23:07:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bCrfFSftCVaNJq0QCqjXOGL5JcW2aZUftTC49vcY4y4=; b=MXf5iUhToaeQIMMYQWbh2guGRwZZIu56+6CpObuXv5jz0lpp802Zhm18DONFvBm9Y8 vtv7kHoeSTESNrqci48EGlDyTN8+GYbtw3ZC7uKhiSCIdseTG9bUQTDmuz83ojo0mqRZ H1mKLVLKIyCD8/nEAqlXDFnz0kNw/te5X2Lvc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bCrfFSftCVaNJq0QCqjXOGL5JcW2aZUftTC49vcY4y4=; b=iJa7f2KJqpQU+Em/sJFrhi11B5SxTKy+jgrDzt+NRiSXwHVHNNp7qeAelTGMWt1dgF V+VZ+RQi2oINwU0J5ApkYa3j3SOJr+L8Ukq842zTU0vEf15QKApsmMK0KnNaVteCkbCo Y4usXxiF0HDk6EkI6CKny+D3QnXxgSgtIWvN0hn8to/i/9QUeD1xexV5WkvmYQ2P9dCF P6vD4HqkYb/VTzV1L72Xh59yUTr8abfdlN0GtB9CkNpFPKrG5b3zrCpn1cIe8bYIlaL1 AEtAdfrmgAfOHniXoanEvWdosHN3T8JiKghNvSXkf2bs63Opz50zDmPYfja7HfgDnI09 rowA== X-Gm-Message-State: AOAM533PTERgfpryy/RmyMRf6LMnpXCEvsW7POdN+OR5wGwdZ3Egn2v1 SpETMobwrN7gXwFZcXF64HX0SVC3fhJLeA== X-Google-Smtp-Source: ABdhPJwLckxkPYHfAuQC1a49ViG5gITt17rlGYhmqrk0G3pNbxPyHUlGk4sVjwaMR8qi4ibqOiyoWg== X-Received: by 2002:a63:6947:: with SMTP id e68mr3324861pgc.292.1638342461639; Tue, 30 Nov 2021 23:07:41 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:41 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:20 +0900 Message-Id: <20211201070728.3114247-5-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 04/12] libcamera: base: Add thread safety annotation macros 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Clang compiler is able to do a thread safety analysis with annotations [1]. This introduces the thread safety annotation macros and also enable the analysis by adding -Wthread-safety if a clang compiler is used. [1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- include/libcamera/base/meson.build | 1 + include/libcamera/base/thread_annotations.h | 80 +++++++++++++++++++++ meson.build | 1 + 3 files changed, 82 insertions(+) create mode 100644 include/libcamera/base/thread_annotations.h diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build index 525aba9d..1a71ce5a 100644 --- a/include/libcamera/base/meson.build +++ b/include/libcamera/base/meson.build @@ -19,6 +19,7 @@ libcamera_base_headers = files([ 'signal.h', 'span.h', 'thread.h', + 'thread_annotations.h', 'timer.h', 'utils.h', ]) diff --git a/include/libcamera/base/thread_annotations.h b/include/libcamera/base/thread_annotations.h new file mode 100644 index 00000000..e81929f6 --- /dev/null +++ b/include/libcamera/base/thread_annotations.h @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * thread_annotation.h - Macro of Clang thread safety analysis + */ + +#pragma once + +/* + * Enable thread safety attributes only with clang. + * The attributes can be safely erased when compiling with other compilers. + */ +#if defined(__clang__) && !defined(SWIG) +#define LIBCAMERA_TSA_ATTRIBUTE__(x) __attribute__((x)) +#else +#define LIBCAMERA_TSA_ATTRIBUTE__(x) /* no-op */ +#endif + +/* See https://clang.llvm.org/docs/ThreadSafetyAnalysis.html for these usages. */ + +#define LIBCAMERA_TSA_CAPABILITY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(capability(x)) + +#define LIBCAMERA_TSA_SCOPED_CAPABILITY \ + LIBCAMERA_TSA_ATTRIBUTE__(scoped_lockable) + +#define LIBCAMERA_TSA_GUARDED_BY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(guarded_by(x)) + +#define LIBCAMERA_TSA_PT_GUARDED_BY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(pt_guarded_by(x)) + +#define LIBCAMERA_TSA_ACQUIRED_BEFORE(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(acquired_before(__VA_ARGS__)) + +#define LIBCAMERA_TSA_ACQUIRED_AFTER(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(acquired_after(__VA_ARGS__)) + +#define LIBCAMERA_TSA_REQUIRES(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(requires_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_REQUIRES_SHARED(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_ACQUIRE(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(acquire_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_ACQUIRE_SHARED(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_RELEASE(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(release_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_RELEASE_SHARED(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(release_shared_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_RELEASE_GENERIC(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(release_generic_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_TRY_ACQUIRE(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_TRY_ACQUIRE_SHARED(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__)) + +#define LIBCAMERA_TSA_EXCLUDES(...) \ + LIBCAMERA_TSA_ATTRIBUTE__(locks_excluded(__VA_ARGS__)) + +#define LIBCAMERA_TSA_ASSERT_CAPABILITY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(assert_capability(x)) + +#define LIBCAMERA_TSA_ASSERT_SHARED_CAPABILITY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(assert_shared_capability(x)) + +#define LIBCAMERA_TSA_RETURN_CAPABILITY(x) \ + LIBCAMERA_TSA_ATTRIBUTE__(lock_returned(x)) + +#define LIBCAMERA_TSA_NO_THREAD_SAFETY_ANALYSIS \ + LIBCAMERA_TSA_ATTRIBUTE__(no_thread_safety_analysis) diff --git a/meson.build b/meson.build index 7892a9e3..7147a108 100644 --- a/meson.build +++ b/meson.build @@ -72,6 +72,7 @@ if cc.get_id() == 'clang' cpp_arguments += [ '-Wextra-semi', + '-Wthread-safety', ] endif From patchwork Wed Dec 1 07:07:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14931 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 422A4C324F for ; Wed, 1 Dec 2021 07:07:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 03F9D60592; Wed, 1 Dec 2021 08:07:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="NfX9d8IZ"; dkim-atps=neutral Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 06D4560718 for ; Wed, 1 Dec 2021 08:07:45 +0100 (CET) Received: by mail-pf1-x431.google.com with SMTP id g18so23440607pfk.5 for ; Tue, 30 Nov 2021 23:07:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oZp64mXZiZeYVL9CTQw76XHFZfemTX2TWMnA+db8H0c=; b=NfX9d8IZJMWymzH5rRCXlu7nob0L9WYU6OMGweulYKTk9S6IZ5U1MJtuPiwr9LEorS IT16t793BF1GLavE6+g5gy3vyRuD53ZcitqilXxGV15CK/muYIUdxlTlsoHcH1Ge27hO 25Tj61gYAREOhqoS1iUcI+UKmGxM6rxhqABsQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oZp64mXZiZeYVL9CTQw76XHFZfemTX2TWMnA+db8H0c=; b=5g7aF0VzJgMTFzA9hEoUGCmdcn7k0qebXcaTQFIRfcAL8/7TcJBoooa8Q78RerC8gL NUHbek6uJR/fbmEd5Z0HAcnfOSayzvMGt80ooiqArgJqBsxL0lPJ8K2iZAtOZur89YnW XDWQXWeG4XF477LgCooP2cuD2Bi45Og72Nib+Do2WXbOQlHXQz4KnRELgD3KIGrfXWiR FwHTgIsNwCekaoVkCGvAHkcvXDj8jp5MxsZsWsExjjWtyL/chUJ+YosdsXm4SWf/NLgU 7g/9iUufjFXf8PUfZDdMaq8KIRZiqowdqMTIoJwqF3wscUxhRjV9vQ7FyIUXkXNAGRSS 3ulw== X-Gm-Message-State: AOAM533/vXVtKsrV8f/k9NvvTKsqtbXQqon0K1aehwcVawPcbct3f6y6 W/YzelDikkOGXQ4ZI3HZZ94KzBa51Hkl2g== X-Google-Smtp-Source: ABdhPJxGatymLx0fWSdazdkJgVxQRNbqvthqYg0OdixW1wydjmku83dil+epNNR9kia2S18cOKasDQ== X-Received: by 2002:a63:b44a:: with SMTP id n10mr3310442pgu.432.1638342463247; Tue, 30 Nov 2021 23:07:43 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:42 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:21 +0900 Message-Id: <20211201070728.3114247-6-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 05/12] libcamera: base: Add mutex classes with thread safety annotations 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This replaces Mutex and MutexLocker with our own defined classes. The classes are annotated by clang thread safety annotations. So we can add annotation to code where the classes are used. v4l2 code needs to be annotated, which violates Mutex capability. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- include/libcamera/base/meson.build | 1 + include/libcamera/base/mutex.h | 132 +++++++++++++++++++++++++++++ include/libcamera/base/thread.h | 7 +- src/libcamera/base/meson.build | 1 + src/libcamera/base/mutex.cpp | 65 ++++++++++++++ src/libcamera/base/thread.cpp | 15 ---- src/v4l2/v4l2_camera_proxy.h | 4 +- 7 files changed, 202 insertions(+), 23 deletions(-) create mode 100644 include/libcamera/base/mutex.h create mode 100644 src/libcamera/base/mutex.cpp diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build index 1a71ce5a..37c4435a 100644 --- a/include/libcamera/base/meson.build +++ b/include/libcamera/base/meson.build @@ -13,6 +13,7 @@ libcamera_base_headers = files([ 'flags.h', 'log.h', 'message.h', + 'mutex.h', 'object.h', 'private.h', 'semaphore.h', diff --git a/include/libcamera/base/mutex.h b/include/libcamera/base/mutex.h new file mode 100644 index 00000000..8b70508e --- /dev/null +++ b/include/libcamera/base/mutex.h @@ -0,0 +1,132 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * mutex.h - Mutex classes with clang thread safety annotation + */ + +#pragma once + +#include +#include + +#include + +namespace libcamera { + +/* \todo using Mutex = std::mutex if lib++ is used. */ + +#ifndef __DOXYGEN__ + +class LIBCAMERA_TSA_CAPABILITY("mutex") Mutex final +{ +public: + constexpr Mutex() + { + } + + void lock() LIBCAMERA_TSA_ACQUIRE() + { + mutex_.lock(); + } + + void unlock() LIBCAMERA_TSA_RELEASE() + { + mutex_.unlock(); + } + +private: + friend class MutexLocker; + + std::mutex mutex_; +}; + +class LIBCAMERA_TSA_SCOPED_CAPABILITY MutexLocker final +{ +public: + explicit MutexLocker(Mutex &mutex) LIBCAMERA_TSA_ACQUIRE(mutex) + : lock_(mutex.mutex_) + { + } + + MutexLocker(Mutex &mutex, std::defer_lock_t t) noexcept LIBCAMERA_TSA_EXCLUDES(mutex) + : lock_(mutex.mutex_, t) + { + } + + ~MutexLocker() LIBCAMERA_TSA_RELEASE() + { + } + + void lock() LIBCAMERA_TSA_ACQUIRE() + { + lock_.lock(); + } + + bool try_lock() LIBCAMERA_TSA_TRY_ACQUIRE(true) + { + return lock_.try_lock(); + } + + void unlock() LIBCAMERA_TSA_RELEASE() + { + lock_.unlock(); + } + +private: + friend class ConditionVariable; + + std::unique_lock lock_; +}; + +class ConditionVariable final +{ +public: + ConditionVariable() + { + } + + void notify_one() noexcept + { + cv_.notify_one(); + } + + void notify_all() noexcept + { + cv_.notify_all(); + } + + template + void wait(MutexLocker &locker, Predicate stopWaiting) + { + cv_.wait(locker.lock_, stopWaiting); + } + + template + bool wait_for(MutexLocker &locker, + const std::chrono::duration &relTime, + Predicate stopWaiting) + { + return cv_.wait_for(locker.lock_, relTime, stopWaiting); + } + +private: + std::condition_variable cv_; +}; + +#else /* __DOXYGEN__ */ + +class Mutex final +{ +}; + +class MutexLocker final +{ +}; + +class ConditionVariable final +{ +}; + +#endif /* __DOXYGEN__ */ +} /* namespace libcamera */ diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h index 1ebf8363..44678c34 100644 --- a/include/libcamera/base/thread.h +++ b/include/libcamera/base/thread.h @@ -7,15 +7,14 @@ #pragma once -#include #include -#include #include #include #include #include +#include #include #include @@ -27,10 +26,6 @@ class Object; class ThreadData; class ThreadMain; -using ConditionVariable = std::condition_variable; -using Mutex = std::mutex; -using MutexLocker = std::unique_lock; - class Thread { public: diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build index 05fed7ac..b93b8505 100644 --- a/src/libcamera/base/meson.build +++ b/src/libcamera/base/meson.build @@ -11,6 +11,7 @@ libcamera_base_sources = files([ 'flags.cpp', 'log.cpp', 'message.cpp', + 'mutex.cpp', 'object.cpp', 'semaphore.cpp', 'signal.cpp', diff --git a/src/libcamera/base/mutex.cpp b/src/libcamera/base/mutex.cpp new file mode 100644 index 00000000..313bcb20 --- /dev/null +++ b/src/libcamera/base/mutex.cpp @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * mutex.cpp - Mutex classes with clang thread safety annotation + */ + +#include + +/** + * \file base/mutex.h + * \brief Mutex classes with clang thread safety annotation + */ + +namespace libcamera { + +/** + * \class Mutex + * \brief std::mutex wrapper with clang thread safety annotation + * + * The Mutex class wraps a std::mutex instance to add clang thread safety + * annotation support. The class exposes the same interface as std::mutex and + * can be used as a transparent replacement. It integrates with the + * MutexLocker and ConditionVariable classes. + * + * See https://en.cppreference.com/w/cpp/thread/mutex for the complete API + * documentation. + */ + +/** + * \class MutexLocker + * \brief std::unique_lock wrapper with clang thread safety annotation + * + * The MutexLocker class wraps a std::unique_lock instance to add clang thread + * safety annotation support. The class exposes the same interface as + * std::unique_lock and can be used as a transparent replacement. It integrates + * with the Mutex and ConditionVariable classes. + * + * See https://en.cppreference.com/w/cpp/thread/mutex for the complete API + * documentation. + */ + +/** + * \class MutexLocker + * \brief std::unique_lock wrapper with clang thread safety annotation + * + * The MutexLocker class wraps a std::unique_lock instance to add clang thread + * safety annotation support. The class exposes the same interface as + * std::unique_lock and can be used as a transparent replacement. It integrates + * with the Mutex and ConditionVariable classes. + * + * See https://en.cppreference.com/w/cpp/thread/mutex for the complete API + * documentation. + */ + +/** + * \class ConditionVariable + * \brief std::condition_variable wrapper integrating with MutexLocker + * + * The ConditionVariable class wraps a std::condition_variable instance to + * integrate MutexLocker. The class exposes the same interface as + * std::condition_variable and can be used as a transparent replacement. + */ + +} /* namespace libcamera */ diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index b893135f..b2043b7e 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -204,21 +204,6 @@ ThreadData *ThreadData::current() return data; } -/** - * \typedef ConditionVariable - * \brief An alias for std::condition_variable - */ - -/** - * \typedef Mutex - * \brief An alias for std::mutex - */ - -/** - * \typedef MutexLocker - * \brief An alias for std::unique_lock - */ - /** * \class Thread * \brief A thread of execution diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h index 040954dd..fa0a49e0 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include @@ -59,7 +59,7 @@ private: int vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg); int vidioc_dqbuf(V4L2CameraFile *file, struct v4l2_buffer *arg, - libcamera::Mutex *lock); + libcamera::Mutex *lock) LIBCAMERA_TSA_REQUIRES(*lock); int vidioc_streamon(V4L2CameraFile *file, int *arg); int vidioc_streamoff(V4L2CameraFile *file, int *arg); From patchwork Wed Dec 1 07:07:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14932 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 28094BF415 for ; Wed, 1 Dec 2021 07:07:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C29D26072E; Wed, 1 Dec 2021 08:07:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="nk+0wyud"; dkim-atps=neutral Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 84AEE60723 for ; Wed, 1 Dec 2021 08:07:46 +0100 (CET) Received: by mail-pg1-x533.google.com with SMTP id k4so12484304pgb.8 for ; Tue, 30 Nov 2021 23:07:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3CYC0HTSWasKnwiOsbUHOHaSlDLMf4cDu1MT4Oe3Lps=; b=nk+0wyudf6bW3UPEQGZQd9/LgrINZpbfeqUdr9fQfTOTvYOX+WwjpEn0VTAixKjTbL ylVGlWSSOKyTZ0VMJ8+DiQ90NsGVe3XYqTTtJHjY8rN+KSkZjXSvsgbQMZ7Nwki+MphX k9ieQh6XhD2nPSSi4ritJcUqCKRCLf5lvYlrM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3CYC0HTSWasKnwiOsbUHOHaSlDLMf4cDu1MT4Oe3Lps=; b=WiZ2qDCiYdd48C9QoHfMQTsjxvEmCVFiaMWYmjKTSeIz3udNyTFLkpQTYmTWV66+EU hWgV3LGg6bihVvSx8Ug5HSzlcpCU6xXJ801Vb9VRLm3ECpI7/abTVpFdRV1xuOumnhJl ANKMuD8WZD0qX5/45AFSIaaX4Rvtc2vm6zeLlUjZxW2omADzs/HQmQusFibGkS82yrqN +Si97+qTE1h0uNt4dRsIBWJdtuYzEo1Kb30dI4vvwhTVTr1kXPT2irxK0ch/WRStRjNp I0QwSyBfQBYY9h/ixJncrggF6m3XGwjZHVo5oMmhjq/HDit5ALuixWs3cMzzEHhr2wOR 5Q3g== X-Gm-Message-State: AOAM530DnNTmAqx0Ed1QKW3go4MtIZg2UDwWrOiQ0y7kHfciEh9h4ugx DlDwyRQkSgI2EylrCottDpw6Hx/McOigiA== X-Google-Smtp-Source: ABdhPJz6sVRX5+GZqjflznrc/UvoqQT1DwBAVeLQF0KSss+rgw0vrCClIcjk5JKaTRXJy+Q4F6OlDg== X-Received: by 2002:a63:2c91:: with SMTP id s139mr3291407pgs.501.1638342464835; Tue, 30 Nov 2021 23:07:44 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:44 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:22 +0900 Message-Id: <20211201070728.3114247-7-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 06/12] libcamera: Correct include headers for Mutex classes 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Mutex classes are defined in mutex.h. This replaces thread.h include for the Mutex classes with mutex.h. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- include/libcamera/base/semaphore.h | 3 ++- include/libcamera/base/thread.h | 1 - src/android/camera_device.cpp | 1 - src/android/camera_device.h | 2 +- src/android/camera_hal_manager.h | 2 +- src/android/camera_request.h | 2 +- src/android/camera_stream.h | 1 + src/libcamera/base/semaphore.cpp | 1 - src/libcamera/base/signal.cpp | 2 +- src/libcamera/base/thread.cpp | 1 + src/libcamera/camera_manager.cpp | 1 + src/v4l2/v4l2_camera.h | 2 +- 12 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/libcamera/base/semaphore.h b/include/libcamera/base/semaphore.h index ec05fad3..c11e8dd1 100644 --- a/include/libcamera/base/semaphore.h +++ b/include/libcamera/base/semaphore.h @@ -8,7 +8,8 @@ #pragma once #include -#include + +#include namespace libcamera { diff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h index 44678c34..9d00f102 100644 --- a/include/libcamera/base/thread.h +++ b/include/libcamera/base/thread.h @@ -14,7 +14,6 @@ #include #include -#include #include #include diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index f2e0bdbd..d74307a2 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include diff --git a/src/android/camera_device.h b/src/android/camera_device.h index bda0b376..a945f5de 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index cc310f90..765701b2 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -17,7 +17,7 @@ #include #include -#include +#include #include diff --git a/src/android/camera_request.h b/src/android/camera_request.h index 88d501a8..887dbe86 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index adb5a37d..e4eb953a 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -13,6 +13,7 @@ #include +#include #include #include diff --git a/src/libcamera/base/semaphore.cpp b/src/libcamera/base/semaphore.cpp index bf730c87..4fe30293 100644 --- a/src/libcamera/base/semaphore.cpp +++ b/src/libcamera/base/semaphore.cpp @@ -6,7 +6,6 @@ */ #include -#include /** * \file base/semaphore.h diff --git a/src/libcamera/base/signal.cpp b/src/libcamera/base/signal.cpp index 9c2319c5..9df45d07 100644 --- a/src/libcamera/base/signal.cpp +++ b/src/libcamera/base/signal.cpp @@ -7,7 +7,7 @@ #include -#include +#include /** * \file base/signal.h diff --git a/src/libcamera/base/thread.cpp b/src/libcamera/base/thread.cpp index b2043b7e..6bda9d14 100644 --- a/src/libcamera/base/thread.cpp +++ b/src/libcamera/base/thread.cpp @@ -17,6 +17,7 @@ #include #include #include +#include /** * \page thread Thread Support diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 77ff3bd1..70d73822 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index bf1b6de4..9307d61d 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -10,8 +10,8 @@ #include #include +#include #include -#include #include #include From patchwork Wed Dec 1 07:07:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14933 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 AD057C324F for ; Wed, 1 Dec 2021 07:07:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 583B760725; Wed, 1 Dec 2021 08:07:50 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="B++QrKmb"; dkim-atps=neutral Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6657E6072E for ; Wed, 1 Dec 2021 08:07:48 +0100 (CET) Received: by mail-pf1-x432.google.com with SMTP id 8so23411477pfo.4 for ; Tue, 30 Nov 2021 23:07:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yfiTHE7WZmDZfQa0nPUIu56mr46Z/OnMWR39IqW4+bk=; b=B++QrKmbwh/n3+MYOLw/l5+RbHh2JYli/K5Z8O0Z53ck9Wa72Ym6zkZq4lZcAke2Rb CJeN1UqZg4ObotEhYmXqymUTb+4t6A7FkaWIgAhxRAvk2UvtazkwYXOMR7BRPyTBduqX sV81cOh6fjNbWaF/PKpUSmx4Jnkk1ePsLKEsI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yfiTHE7WZmDZfQa0nPUIu56mr46Z/OnMWR39IqW4+bk=; b=asKIY/A8XJdpTnV/k27ESXw/iN5edsdyNX+UWL6mAjFlJDEbaormB2zNkSF5MD/xIs P/3imD6I8z2QeHo2+Fv7ylk532Nj4x/dVWT6Z8t4vvuUjfV+y0KNLTFz86GiY52ZVsVr vhs3vzJN4xXMGI2DRQaA5DaC2f4TuWgxZ0e1Xy0nEUtY9i2nAoIWC5Mt9pJPf/kldTD4 MDrxFUUo9w9RD+ib/ywt6/MNhow5iiyLFRrY7uLredwoHeGN8SAZlKMIRSS7V9RCwaTE ye+N9utEkshu5nabH36kDub1fzBYuPJL3fOGc59PexGbp4sdMASswKVctYRXApEFlt47 iZDQ== X-Gm-Message-State: AOAM5300ZUlKZzpWx+6VndlGhmavXxPDTfdOm5vPHrr4p0IGcZH1gRL3 PYaX7NPtyPiK9JchFQ9FX2t3t6IqM91GjQ== X-Google-Smtp-Source: ABdhPJzUz81gVE+/ViZRx3TsxxCzPAl/k53F0wDEmMEnb1WryEhCkxGgVWw5GthUsZpxI5dagcV8kg== X-Received: by 2002:a63:155f:: with SMTP id 31mr3358972pgv.156.1638342466735; Tue, 30 Nov 2021 23:07:46 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:46 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:23 +0900 Message-Id: <20211201070728.3114247-8-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 07/12] android: camera_hal_manager: Add 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This applies clang thread safety annotation to CameraHalManager. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain --- src/android/camera_hal_manager.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index 765701b2..a5f8b933 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -53,14 +53,14 @@ private: void cameraAdded(std::shared_ptr cam); void cameraRemoved(std::shared_ptr cam); - CameraDevice *cameraDeviceFromHalId(unsigned int id); + CameraDevice *cameraDeviceFromHalId(unsigned int id) LIBCAMERA_TSA_REQUIRES(mutex_); std::unique_ptr cameraManager_; CameraHalConfig halConfig_; const camera_module_callbacks_t *callbacks_; - std::vector> cameras_; - std::map cameraIdsMap_; + std::vector> cameras_ LIBCAMERA_TSA_GUARDED_BY(mutex_); + std::map cameraIdsMap_ LIBCAMERA_TSA_GUARDED_BY(mutex_); libcamera::Mutex mutex_; unsigned int numInternalCameras_; From patchwork Wed Dec 1 07:07:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14934 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 2C931BF415 for ; Wed, 1 Dec 2021 07:07:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C439D60733; Wed, 1 Dec 2021 08:07:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Eq5l+sKk"; dkim-atps=neutral Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 255DB60723 for ; Wed, 1 Dec 2021 08:07:50 +0100 (CET) Received: by mail-pl1-x634.google.com with SMTP id o14so16957664plg.5 for ; Tue, 30 Nov 2021 23:07:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aisRSY5NBfEGCdy/9ndvSRH0p2htKgt/zk8gIFRC0cU=; b=Eq5l+sKk1W0jOMRADeIbtVPK009O9SFWnT+blrulAn6fP85hL6y8TYVyb+Z5rugRKL lm1YGDihPRoFG/Lov1guQf+ZugqWBAZfFioa3Q3m9AL5Dmy0flmBAaPJfyXCohLf+9+E EjesJhdYRegHbrbcJeDEbLXE8ZVqabUEwgITc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aisRSY5NBfEGCdy/9ndvSRH0p2htKgt/zk8gIFRC0cU=; b=LrrB1B6Cl06M3+Hadr25YLOI2E/vHm5SRm/XEgsN7DIh8JA2ygwlXHP5GtWu7QO02x UkwZ9GT4NeuMrGOGwwFk9uNh/W94r/4bqp5/hUDKhli4kBBTm1HwsrybMmSR+A3vDyVI m05hL8SwaLE1NCILFxS/9DihTmksxLUeF5XJ/lFhf6K6gl2qKf2B9+q3IfiqkCl8gNEX SIkBlwoRj+wwJl9PNvCdqPRQ1eY79NMWJkJ18+BBYdk8h05wqnbYtaTWj28es0LseipT V4gmdNvk5UUf4T3we6t1iMHMAqQgoI12168+DCPmmgCudBPEoSAwnz3YV+/Om2RbwkvS wOvQ== X-Gm-Message-State: AOAM533Jark84wav+lO/RncNJums/bwwNS8dmnFGAeEnlLj1tNAaRx83 LF0BB/mfsl90wsqu6lZML56eWI1L2bB0OQ== X-Google-Smtp-Source: ABdhPJwWxyuqUyyMTkedNmDfpFhBTdg0cWyg2mEJv8v1PRP7rm3AAAp3koWdcem7D9mOpfNEZ5HQNw== X-Received: by 2002:a17:90b:94:: with SMTP id bb20mr5251057pjb.210.1638342468486; Tue, 30 Nov 2021 23:07:48 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:48 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:24 +0900 Message-Id: <20211201070728.3114247-9-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 08/12] android: camera_stream: Protect buffers initialization by mutex_ 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The initialization on buffers_ in CameraStrean::configure() is not protected by mutex_. It is no problem because configure() is not invoked simultaneously while other functions are called. This protects it to keep the thread safety consistency for buffers access. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_stream.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 5a62b7cd..2181d094 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -125,6 +125,7 @@ int CameraStream::configure() if (ret < 0) return ret; + MutexLocker lock(*mutex_); /* Save a pointer to the reserved frame buffers */ for (const auto &frameBuffer : allocator_->buffers(stream())) buffers_.push_back(frameBuffer.get()); From patchwork Wed Dec 1 07:07:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14935 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 64E67BDB13 for ; Wed, 1 Dec 2021 07:07:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 241C560727; Wed, 1 Dec 2021 08:07:54 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="mthpzqzP"; dkim-atps=neutral Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 253096072B for ; Wed, 1 Dec 2021 08:07:52 +0100 (CET) Received: by mail-pl1-x630.google.com with SMTP id p18so16926592plf.13 for ; Tue, 30 Nov 2021 23:07:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AQIBNqacdqTMVVj1+/N7sLikHJdd0HfW4RrtBwMeJFk=; b=mthpzqzPHyAwhR37Zbphnf0hXhOcL9HHVoNUj8FM29OvTRmpGxP/F5F2luO3FA8m7z DoM08Uo7txGV2qV8dhE2GohFPtup9ZbYjbxv6/Ti8Rtq0AgFoDeG2M2fnA3i5G9e9J+J ipuUbPVAtGqxy37PARZv/TB9dA6FI5lPfJTok= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AQIBNqacdqTMVVj1+/N7sLikHJdd0HfW4RrtBwMeJFk=; b=KYzQuoc6Rre5WXRGlpwE+YkEW9VNfUcRkuqUuM18az2bHnmjrvpiKUqXbenzLt0he6 57AJL4VJUHrMOWRskr8263vikq4SOvr1mTlePazDvPQh4N0azMUbJve/suLCW7rfQqca 338PdL3b/jrOlx2K1OMkR7mTmrsd62Al4Saw7LzqO2raoRPL1jNmPyWdmdVZ6/EDqEYM pg6iG6danU6xtCG+AF4S5KBU+sMAr6DqdYj4MfALMwQ7IY5pTEO8rNj9XQDrPUYMq111 QbuUc9a3ITzxnDopBO27mmOaB6vPwv+i5GGOGBpLYiu5Yj+kTcgiRrmjQzBoCd0zXGF+ S/eQ== X-Gm-Message-State: AOAM533Pr3iIt13jOPyohCqXTEFau9ZxmJZzjCoBOQ7tnc+geq+NYepv wDsSWDoCKiWknDrzUsL70PEhnlwQfoJzEg== X-Google-Smtp-Source: ABdhPJxF+9+F0MIBhfToCAo9Pvku8gnqP56wcsOhHINrekNanXKMggJ353by+qWsrf3q6wcCHeMOOg== X-Received: by 2002:a17:90b:4c44:: with SMTP id np4mr5233285pjb.195.1638342470477; Tue, 30 Nov 2021 23:07:50 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:49 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:25 +0900 Message-Id: <20211201070728.3114247-10-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 09/12] android: camera_stream: Add 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This applies clang thread safety annotation to CameraStream. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain --- src/android/camera_stream.cpp | 2 +- src/android/camera_stream.h | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 2181d094..ae659808 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -275,7 +275,7 @@ void CameraStream::PostProcessorWorker::run() MutexLocker locker(mutex_); while (1) { - cv_.wait(locker, [&] { + cv_.wait(locker, [&]() LIBCAMERA_TSA_REQUIRES(mutex_) { return state_ != State::Running || !requests_.empty(); }); diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index e4eb953a..7b1a2980 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -155,8 +155,10 @@ private: libcamera::Mutex mutex_; libcamera::ConditionVariable cv_; - std::queue requests_; - State state_ = State::Stopped; + std::queue requests_ + LIBCAMERA_TSA_GUARDED_BY(mutex_); + + State state_ LIBCAMERA_TSA_GUARDED_BY(mutex_) = State::Stopped; }; int waitFence(int fence); @@ -168,7 +170,7 @@ private: const unsigned int index_; std::unique_ptr allocator_; - std::vector buffers_; + std::vector buffers_ LIBCAMERA_TSA_GUARDED_BY(mutex_); /* * The class has to be MoveConstructible as instances are stored in * an std::vector in CameraDevice. From patchwork Wed Dec 1 07:07:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14936 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 CEEDFBDB13 for ; Wed, 1 Dec 2021 07:07:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8748760720; Wed, 1 Dec 2021 08:07:56 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="BhBksRNQ"; dkim-atps=neutral Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DDB1F60720 for ; Wed, 1 Dec 2021 08:07:53 +0100 (CET) Received: by mail-pg1-x52c.google.com with SMTP id 137so15552668pgg.3 for ; Tue, 30 Nov 2021 23:07:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SdRdtSaVWQne/+wW0BuBr2489jUGsU+9DzmNFD9RRSU=; b=BhBksRNQ52z8DCgmnV0UwKdMSk/zvSR1QqtdqSva7lO2c5e7UCIoEfJ3ZwOy8fO0de VsZyiyc1BbcixIJcGQFp4Ar5BMVlNpl03pmIaD9salRqNHJO50XN7O7p1QHZtUnO8wFZ qgFdhdk2D06gWACTGSut95E6teaDkgGX2R+qA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SdRdtSaVWQne/+wW0BuBr2489jUGsU+9DzmNFD9RRSU=; b=bzgBuqPzZvxRqKhIZvhDncnVpUbgiM93/6rwOCCVGq3bRAiervYHURrkZb7asl/r94 l5MPoRS6p7+Cw+AeU2T/VO1yIKNPpFLOd/tnJ4iaDHeL/RYcpaE0qcy908U6C5O7b/+F dQYHTDAPUwZwZba7C+ErIm5eGlMeuSYMfnqvF7ioQgefwJQh9sHtx3gXKD+3dBx6LD3V I0x24wsrtjbi0kj6jEiKGKolf+X3k1XxmXL+8iHJK9F0MjuVzaAmzxA+ngCB0xyMzf85 vL3fS44VNOGfjYVh+lyrB8kaDELzVCE6DBFS7Tft1t5tdCNTkCiG6XDWllFrBlLboUgd pIHA== X-Gm-Message-State: AOAM533OUSkkOhyNUUMJE5bYLYf6whnnCeEp26HcX9YFXv491KpLZpis YXog6XPhefHxmWqGpU+ZoPEkZojT5BE2lA== X-Google-Smtp-Source: ABdhPJwi93Gr9q8pHWYVzJiKGXRAQMzBKPeJUnY8eUKU96QJIgHJNMFJkuRDKrF1N5o6bDdsu1a2LQ== X-Received: by 2002:a63:81c8:: with SMTP id t191mr3340297pgd.369.1638342472172; Tue, 30 Nov 2021 23:07:52 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:51 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:26 +0900 Message-Id: <20211201070728.3114247-11-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 10/12] android: camera_device: Fix variables access without protection 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This fixes the code accessing descriptors and Camera3RequestDescriptor::pendingStreamsToProcess_ without holding descriptorsMutex_ and Camera3RequestDescriptor::streamProcessMutex_ in CameraDevice. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index d74307a2..c7de5da0 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -421,7 +421,11 @@ void CameraDevice::stop() worker_.stop(); camera_->stop(); - descriptors_ = {}; + { + MutexLocker descriptorsLock(descriptorsMutex_); + descriptors_ = {}; + } + streams_.clear(); state_ = State::Stopped; @@ -918,6 +922,9 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques */ FrameBuffer *frameBuffer = nullptr; int acquireFence = -1; + + MutexLocker lock(descriptor->streamsProcessMutex_); + switch (cameraStream->type()) { case CameraStream::Type::Mapped: /* From patchwork Wed Dec 1 07:07:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14937 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 3F91CBDB13 for ; Wed, 1 Dec 2021 07:07:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E98B86072E; Wed, 1 Dec 2021 08:07:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="iKaG2p6K"; dkim-atps=neutral Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ADE5660718 for ; Wed, 1 Dec 2021 08:07:55 +0100 (CET) Received: by mail-pf1-x436.google.com with SMTP id b68so23406980pfg.11 for ; Tue, 30 Nov 2021 23:07:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t1EdNmb2krgv/F9K2Ewspd25zRV1hwTxg1Jn4yjsZWU=; b=iKaG2p6KR6qwcJz68fTFOUccDIxNwBSEgBc7rupt1WO5I10C/cxvZqp/JMwcQq6pVU wFl6/pX+TJPOi9E1RZX1P6kVt4/pXTBam/ppGekWZ37NphvPV0Yq1Jzl0wY5BzEFJT41 A0XmGA3uI7cSQ3Tgl0wZdlvTDV9gwo/yRQ+x4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t1EdNmb2krgv/F9K2Ewspd25zRV1hwTxg1Jn4yjsZWU=; b=Vj8wFBfgRM2gPZeXDBI00kO87CNZ0yXR7YwJqPVNuJIOwxjjnw1or/RLei8bQIA0BS NL8ja2JM145lCAzbqJrOoq8tY5N80cnAn9HoG8BkqUERIRkM4KP5lcPqzaQ4HEzkxL1x X6GBGN+ZCnPIHV7jGr0XblH73PXGgotxW1vRKy+YjJxxtXWaB3sbelYXXBmZvjd5gQyN ofcIWXhJxlQuSNdUgyE4b6HcODiFlB2gcLlu4p8A8KLhOtVxNmDkvVnxa+qHf5yEeBgo ahnGoZt0MRfy9HUJ8sVa6zvwg2zwQ9BBVLYXPYS36SVDdiZdRauw1snEfA0pg8wSmdoe T0tQ== X-Gm-Message-State: AOAM531tX0N7fFla+1fAr3D5g1MdNssY1/iOI+pk0dYgQJJoEL7RuETG X8xSxiMlrxEhDaS4m0fJcQP7srmdXv3qEw== X-Google-Smtp-Source: ABdhPJzUsfihOASXc76xlhPYU4nYFFmaIQTqXcKBVpXCOn+G/1Kg1hcmhTEUWyozSaNofKNT5QzoAA== X-Received: by 2002:aa7:9e9c:0:b0:49f:c7cf:ff5 with SMTP id p28-20020aa79e9c000000b0049fc7cf0ff5mr4144964pfq.62.1638342474034; Tue, 30 Nov 2021 23:07:54 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:53 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:27 +0900 Message-Id: <20211201070728.3114247-12-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 11/12] android: camera_device: Add 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This applies clang thread safety annotation to CameraDevice. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_device.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/android/camera_device.h b/src/android/camera_device.h index a945f5de..e5d9cda2 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -82,7 +82,7 @@ private: Running, }; - void stop(); + void stop() LIBCAMERA_TSA_EXCLUDES(stateMutex_); std::unique_ptr createFrameBuffer(const buffer_handle_t camera3buffer, @@ -94,8 +94,9 @@ private: void notifyError(uint32_t frameNumber, camera3_stream_t *stream, camera3_error_msg_code code) const; int processControls(Camera3RequestDescriptor *descriptor); - void completeDescriptor(Camera3RequestDescriptor *descriptor); - void sendCaptureResults(); + void completeDescriptor(Camera3RequestDescriptor *descriptor) + LIBCAMERA_TSA_EXCLUDES(descriptorsMutex_); + void sendCaptureResults() LIBCAMERA_TSA_REQUIRES(descriptorsMutex_); void setBufferStatus(Camera3RequestDescriptor::StreamBuffer &buffer, Camera3RequestDescriptor::Status status); std::unique_ptr getResultMetadata( @@ -107,7 +108,7 @@ private: CameraWorker worker_; libcamera::Mutex stateMutex_; /* Protects access to the camera state. */ - State state_; + State state_ LIBCAMERA_TSA_GUARDED_BY(stateMutex_); std::shared_ptr camera_; std::unique_ptr config_; @@ -118,8 +119,9 @@ private: std::vector streams_; - libcamera::Mutex descriptorsMutex_; /* Protects descriptors_. */ - std::queue> descriptors_; + libcamera::Mutex descriptorsMutex_ LIBCAMERA_TSA_ACQUIRED_AFTER(stateMutex_); + std::queue> descriptors_ + LIBCAMERA_TSA_GUARDED_BY(descriptorsMutex_); std::string maker_; std::string model_; From patchwork Wed Dec 1 07:07:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14938 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 23331C324F for ; Wed, 1 Dec 2021 07:07:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BAAEA6072C; Wed, 1 Dec 2021 08:07:58 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="k4TjDi2a"; dkim-atps=neutral Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 718DA60723 for ; Wed, 1 Dec 2021 08:07:57 +0100 (CET) Received: by mail-pg1-x531.google.com with SMTP id 137so15552801pgg.3 for ; Tue, 30 Nov 2021 23:07:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uJYG3Nusw/zJT2sBNaxIou0h0BcaN6bUP3w8FXeB2XE=; b=k4TjDi2awPogPpjObRy0CFdaH1tBwYmb8XkxyPrBC8AtVVPG+9OeZ8e/i1UfE26G3J XSgv6QxgXLANF1Xwv9qzOmsZpj1Kz4dMv6gAD/ZgqdZEKUjmkw2kx+Rfnhsb4rjsh1Kp 8xL16RUqNeS9cHcuNqjFyqhmZqBUXj7oH0Br4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uJYG3Nusw/zJT2sBNaxIou0h0BcaN6bUP3w8FXeB2XE=; b=WTxOOP/8W12HBjBUzsp3VuG+cxFIbQXrZzLAAvndrBBomykpX1Rl0os1EL4gFRgkIp n7fQt7sdxheM5jmnmWGzcFW13vshCuJPQ4KO9/wVhH0gDnMWN+Fc9di3TvhJ5IIrK6Wm piddy5JlH3Z3xayK8nua2Uwjh/ClSCnXubU0u0TfJLBUX5dKGi/GloErUTkjxnPGknU/ HIRA2uYVZuO2Er0ppgp5z4ptXlxgDv5XpBEJdDyqNtssd2xSK3PLuQ/0eI2iSVgjUl06 52kGXCATQhSauJzUPyxHkI0ZUj1YLEAtUw8kZhBf3Dh3DA51Rcy+Qi2N8ro1dGz/Rh9q LM5Q== X-Gm-Message-State: AOAM532zxviJqIToqx3B1xIPJdSqqoMXdfQKXWntUYGi6zyg2Ko6Fh/2 rvfd8mqa2IfnsdG2dWck0mNP5fgj65Mg+A== X-Google-Smtp-Source: ABdhPJznpu563TVUSykSU23itZEgDzhM0DizlEdsGg40NurPZMzsKyCLkazq7YOg7qF3pzoxjXnujA== X-Received: by 2002:a63:34c5:: with SMTP id b188mr3410918pga.64.1638342475764; Tue, 30 Nov 2021 23:07:55 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id m10sm16598962pgv.75.2021.11.30.23.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:07:55 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:07:28 +0900 Message-Id: <20211201070728.3114247-13-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201070728.3114247-1-hiroh@chromium.org> References: <20211201070728.3114247-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 12/12] android: camera_request: Add 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This applies clang thread safety annotation to Camera3RequestDescriptor. Signed-off-by: Hirokazu Honda Reviewed-by: Laurent Pinchart --- src/android/camera_request.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/android/camera_request.h b/src/android/camera_request.h index 887dbe86..d9b04f16 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -57,7 +57,8 @@ public: }; /* Keeps track of streams requiring post-processing. */ - std::map pendingStreamsToProcess_; + std::map pendingStreamsToProcess_ + LIBCAMERA_TSA_GUARDED_BY(streamsProcessMutex_); libcamera::Mutex streamsProcessMutex_; Camera3RequestDescriptor(libcamera::Camera *camera,