From patchwork Wed Dec 1 07:53:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14941 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 604EFBF415 for ; Wed, 1 Dec 2021 07:53:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1E6F460718; Wed, 1 Dec 2021 08:53:59 +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="JyjcwSYz"; dkim-atps=neutral Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C286460723 for ; Wed, 1 Dec 2021 08:53:57 +0100 (CET) Received: by mail-pf1-x42c.google.com with SMTP id n85so23507344pfd.10 for ; Tue, 30 Nov 2021 23:53: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=RfQVNtG/v2bEcPhs3B2DWL5RmPs7AC4Gxpfmf3NMFrs=; b=JyjcwSYzD38HqNjvbFMNMYF3FaDfjicow+so1nvqGCqSNfvVsB6G9oSaDWMjvtut6T yzRtSVAfHpywukN66RIyvjtMfXu0gR0tDeEPCmmwxM8NZ1BCdNrNS9ZLtYhmAbQhcbzN xFS6Q7jx/h94Hk9knxNlEThpiZIDMbsdd3e4s= 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=qsZVBbhulFiTpMsleidF0I9wEinD0fzkIb58uZFA6nSO5OABrbxfCVvJUGnxw5iEie j2eQ42AVwQYybMDyK2CvWoVGD/sd+mu2UcFztoWXVOL2x3ec1rdQE1Yl0L4ubINNuM3B BUveAxLtN/IvV4yO0aig2Te0I7PnpEf5lL/jooe62rNv1lOp9sTi+b+jWsl2kLDHBj51 M3gaRhlmpf8Bz+JTzJvJb8l2JolowMv1yNfaNOIZv6M5WQ3fIYnJwpTUwbQJgwwXHK6y EKcIH1qgi0g4B7jPqiXm+1bfRhJOzVCOAcSSCP3o8ypixIIV8oAluGr6fiqIq2boACH5 F+MQ== X-Gm-Message-State: AOAM533+XaY3Y4/qAZE0/8pf4xhRxzt2FaXmrlSPWTAk/tqDq5KNbVdF iTPqxLQ2UTYkWj/HPqX1qx0ZDKqIlN7ZOA== X-Google-Smtp-Source: ABdhPJy3+fLDXV/ZbUeibs52I82ZGI5yb1Im2YGtqghxbWE5eWDSvGVQBduLApxUut9gmikNJWP/6g== X-Received: by 2002:aa7:804b:0:b0:4a4:b2e2:e046 with SMTP id y11-20020aa7804b000000b004a4b2e2e046mr4492014pfm.81.1638345236158; Tue, 30 Nov 2021 23:53:56 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.53.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:53:55 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:37 +0900 Message-Id: <20211201075348.3121186-2-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Reviewed-by: Umang Jain --- 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:53:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14942 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 D0C08BF415 for ; Wed, 1 Dec 2021 07:54:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 82B4260718; Wed, 1 Dec 2021 08:54:01 +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="BvX48i06"; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC51A60710 for ; Wed, 1 Dec 2021 08:53:59 +0100 (CET) Received: by mail-pj1-x1034.google.com with SMTP id gt5so17337192pjb.1 for ; Tue, 30 Nov 2021 23:53:59 -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=BvX48i06h4MxzzEwpkr2M6jb3Gb5DN2qJSTfniEIiP4OtbryLbNyHoc1DfrT1+nItO 0LG+hlhVUA7KxJ4iOSRi63CC6tvouPaEigmLXOHG0E/vevUllSMKQ8rcd991T2kQ2ory DKP182njMLwdbHLv+K8HtP1UW+kyeC6gAGCas= 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=zv0LP85qKXXI81yyaYtiQwE2FQXHyB+gx+r0pvu9aCb8KFFe4MX4dZWv7A/nyY5YfH mF7DPpb5qk03/ITcSmw0opnKbF92qPQxVHhzmSmFwJOmOkH/nKfN021ntMaPlFbmTEiR LbjHUANZfreDndcwrvDwPon9x11l+zMIWHDsDdlbjYn3Ln908FJBWW/ptqCvb7kkxibs f4lTF2e7QwHMvUvZMhloKbtBP3oRKo5KO6SUcZbXIcsrv7stPYXF07HNKrzmxEmQd5wd jAONQay1ek/l8ZFk/jtU2NkRcDj2NvIFbSl3W0EP26MD9ajdllrJlrPck7hKeYmOtgnB +bxQ== X-Gm-Message-State: AOAM530cI9ckcoTcjvRDlnWZ7aH56rex291YqT6Wx6HgEDomOtZAFdTi Eh1NG2y9T/xZn5VaVI2q3F4AKIeT2D6/KQ== X-Google-Smtp-Source: ABdhPJwXOGnGUkAQcGrVELBSEB2SXp3dzc1v+ibpGTdLHDGPaj+VXq8TAC8vQxEQ2+3iVpvwhf0EGA== X-Received: by 2002:a17:90a:db81:: with SMTP id h1mr5628120pjv.46.1638345237874; Tue, 30 Nov 2021 23:53:57 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:53:57 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:38 +0900 Message-Id: <20211201075348.3121186-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Reviewed-by: Umang Jain --- 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:53:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14943 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 BB4C7BF415 for ; Wed, 1 Dec 2021 07:54:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6E50C60720; Wed, 1 Dec 2021 08:54:03 +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="Fp0Q8t1/"; dkim-atps=neutral Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 437EA60723 for ; Wed, 1 Dec 2021 08:54:01 +0100 (CET) Received: by mail-pj1-x1034.google.com with SMTP id h24so17350579pjq.2 for ; Tue, 30 Nov 2021 23:54:01 -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=Fp0Q8t1/6lvrBvGE21gpKg1QOwzZOhNMczPpJKOTxrG/QvK8aM3xTHQyopCzfcXqn4 vHZrLfO5ijZwi7G9QH7TgVtLt6yeIyG+3k/48YXg8ynJ69QCxomABSiApKrvXqzYNS2i wDQMQUI1lUnU5UoTkOVak/z+cd5ciRDscxVLw= 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=1lwX0ZBHMQINx/8lZzdFyG8NFMOVENxPkw4Nb6RgKAOea8wOXEhlI6souAfnapOTBD vLMbc2JdQs67ta2Pc/wqo7dpAzG4veeXzFw+Fs/iQaJC665cSfS5TdnpuWme/tAP6Uxx fHJHo8Qg4AxIlULfeZH/r49rIH+3Q0rdJp2bqh/9qa3lMAbpKElERkYiLsFILKZBN6Kz fqAI/OsA3OFF0FWi7ZO3GartfbeqRCm51XXPni4wOVg8Hzqfi2Tn5d+E6rgHV0VToRYr T3wJKyzs20f+963XiB5a6HnxilRQmxPDLS9lWUvixxq4KeKeFYDfdGAT9iOsj506KRwQ 8Kvw== X-Gm-Message-State: AOAM531YIspINi6CrqKu47SEsfztnOkqsYQhrec2YG+6q39OseuE/lah 4D9FaHXwXSk6VKDZwK34hXBTO1uPDSvCrw== X-Google-Smtp-Source: ABdhPJwWES7Wl1w2iqOuT8+3Sid/dygEzg6pDHCsGnQIerBhHacRilJOHAKqI99b90I1aFstDrtX3g== X-Received: by 2002:a17:903:1208:b0:143:e4e9:4ce3 with SMTP id l8-20020a170903120800b00143e4e94ce3mr5540793plh.21.1638345239607; Tue, 30 Nov 2021 23:53:59 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.53.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:53:59 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:39 +0900 Message-Id: <20211201075348.3121186-4-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Reviewed-by: Umang Jain --- 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:53:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14944 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 4CC65C3250 for ; Wed, 1 Dec 2021 07:54:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CFCCE60592; Wed, 1 Dec 2021 08:54:03 +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="e9XPZQMe"; dkim-atps=neutral Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D57D60721 for ; Wed, 1 Dec 2021 08:54:03 +0100 (CET) Received: by mail-pg1-x52e.google.com with SMTP id 200so22758803pga.1 for ; Tue, 30 Nov 2021 23:54:02 -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=e9XPZQMewZ8w/T6ZwK7a3YaHlHyi1jH/bUkXj26CFA+eGdbutUtXJRCdcLIYOb0znh CuOxXfo6isBk9sybZeegxY1MNZu7v6MqPXw0yGWN9nJHbLdhQ8qttwHnqcrPTmZMc6Ft Z5YqJZljefZqBWe7IJbJ1oHB5MqEq1jnG0wQM= 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=z7Tv/c5RlcIBBgrImBTIT7m/I7caU3tGkAi0IJzYOJ0Pqe+jPJz+XVc5gJ5B5V4jJT 0j/hO6mnVl6AbR2LLE9+1jIBlMkBf29PsmIs+lF5JSnnu/deSYKzR3Z/RMXWduzekURK X3hQgDhlFOiGspCBDeVhWb9O4mESad6ySUfFI7KyldFg+d0frDaphSkOxYn2O2H+q4rL GyRs9WhV8+ZyqQiFVId9MRxeqxpoz6MrQtCTo3QcHSrEoAZjvf41YmvroMfjnRVZacVI gipZCGsW0AKTfRePKW4Cr9z8QbIJnzvIpJu3SiHEO0NvE316yO+mSNCQ+AiG79L1XLZY szfQ== X-Gm-Message-State: AOAM530JKB7OHhCZY7BSDVKetv8RIaAa0h0FZwRaquYN8mcK914OZ3jw oEuGUf3S0mMWl32oEegCzcup4JVyllSibw== X-Google-Smtp-Source: ABdhPJwnxuPN0PuCMEHemoUR6K5NgDEKRiGkYFVW7OEXBKi+8dEnMPxg7OXFUUDl6w2t9qlXT8lEtQ== X-Received: by 2002:a63:8948:: with SMTP id v69mr3472507pgd.250.1638345241365; Tue, 30 Nov 2021 23:54:01 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:54:00 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:40 +0900 Message-Id: <20211201075348.3121186-5-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Reviewed-by: Umang Jain --- 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:53:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14945 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 97436BF415 for ; Wed, 1 Dec 2021 07:54:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3DD4960725; Wed, 1 Dec 2021 08:54:06 +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="Zz/VLi57"; 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 DE22760710 for ; Wed, 1 Dec 2021 08:54:04 +0100 (CET) Received: by mail-pl1-x634.google.com with SMTP id y7so17062702plp.0 for ; Tue, 30 Nov 2021 23:54:04 -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=p476CjgLIqlUgkGdPTqOjZB8ocadpuQ6TllpiWK1U7w=; b=Zz/VLi57tX4ORBqYicI2XCiUQjHvX/wDXEH2tAdjztebsTL+j18TJrWcyD/nUswwKB 0e9hGtf15cwL50aPw54AGAbjGZZXNgG8abwYTBDp0NT1vTUc3521vC74HS7XOwUEKWop WSnDAhYonRZAMtq8v8tsCF+66ACtcc8emUrkA= 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=p476CjgLIqlUgkGdPTqOjZB8ocadpuQ6TllpiWK1U7w=; b=fccXUqQ4nTSEd756yOSNVzb1ojBdux37CRV6YhnSymIyURN5MWa4bFx/4IJBo1UJ9J kzyOEdO21DFCYRDZYTaGL2DBwopRFM7ezGF6YYvdXlEfLAngOVGnQUwrdFKukBhitdmq WsnYFdFib1o0HDpZQuGU2RIO7mk2epHWeekm+94L7692WwTp6TYPjb49TYoEr44VG6nx PZNurpCQ4kZfbh6QCy6x9uXeB25SBsZTsIUhCypfO4LlHhuv3Vq9L7Af+NP5UagTqW3Z kvyKph0UJJsnF1IXY5QIVOM5CqKPAdKhpM1OVa76vDxLze5BxoOd4PHdgA6lSEfJhu6z G41A== X-Gm-Message-State: AOAM5336kp2NXOQ2AZ6RcKZu9mbiaDBnw++jWJdP9TbUfuCI2idMOabm GxpI0LVYSBaCUHa8T8LyXhNZgCvQJRLXpg== X-Google-Smtp-Source: ABdhPJwHSlbWCuC+oMydPe+zby3fieQQ4+8XvO4bau4QJLJcBTKeuODz4yW8+S3p+GmPptfvXbFhlQ== X-Received: by 2002:a17:90b:314d:: with SMTP id ip13mr5440861pjb.228.1638345243104; Tue, 30 Nov 2021 23:54:03 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:54:02 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:41 +0900 Message-Id: <20211201075348.3121186-6-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Reviewed-by: Umang Jain --- 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 | 56 ++++++++++++ src/libcamera/base/thread.cpp | 15 ---- src/v4l2/v4l2_camera_proxy.h | 4 +- 7 files changed, 193 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..8e63387b --- /dev/null +++ b/src/libcamera/base/mutex.cpp @@ -0,0 +1,56 @@ +/* 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/unique_lock 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 with the MutexLocker class. The class exposes the same interface as + * std::condition_variable and can be used as a transparent replacement. + * + * See https://en.cppreference.com/w/cpp/thread/condition_variable for the + * complete API documentation. + * + */ + +} /* 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:53:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14946 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 E298FBF415 for ; Wed, 1 Dec 2021 07:54:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9D19160720; Wed, 1 Dec 2021 08:54:08 +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="CJ8CHRed"; dkim-atps=neutral Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED66360710 for ; Wed, 1 Dec 2021 08:54:06 +0100 (CET) Received: by mail-pj1-x1032.google.com with SMTP id v23so17312724pjr.5 for ; Tue, 30 Nov 2021 23:54:06 -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=1BXuhHBtpeQuWZSbzzWWhH2MYUJgctAU4AJvuOG+YC4=; b=CJ8CHRedDaV2d4lqnEU09wqjl9vA2hOcPNTak46H39dCUEqzmM3cdGcqfNyGydAow9 8ScIYQU/L2NIIzrkCAlwIqH3k78C8qwKfkLw491B22S0drq/UfE5PEJeY4u6+hotYmDC oFMChaVqU7saUcP+NZpd+brqkpoJNDuZaEB0Q= 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=1BXuhHBtpeQuWZSbzzWWhH2MYUJgctAU4AJvuOG+YC4=; b=oBokvXppJmvYpdJiqtfRlvkOPMP+vHjfV1fWOO/hbX6XINUP1Tweb8ZNHI7E0FB9la mAg2/D2zGai0T5renJxD6PNh8mdSVNQvkXdulLpLS4JidZmK543mzr5wrhrs48owwpI0 tQEa/dy6o375lNgUeAqcN1/ss5snqmHQsYewSlODlT42r2YIEp4Qhbmv9wZJ2+iXu9fr TDlHc0bcPSsAEnt0COMA2/aDLq2fr/nZ8DqF1W+L67+34BNz94kMufzkGb4O635hPtPz 3ox0BIPerqs3969OBcQL6cyTH7v53wiT9YQFueWbqpOAzO4nqlYneqvax4TjH8KEwIZJ SmsQ== X-Gm-Message-State: AOAM531njAJwIh6TSktQMw5IuBjqWF/CjESFRrhhJ0EOrql6rhhEnRiJ eWGdpv5Jla3j/KmPRyV5/gciMeLFoCNV8g== X-Google-Smtp-Source: ABdhPJwV4KjCDtJvfhLbROvoMCSun3nECcZgwg8yHTzI54xm/bSVMaELgU/xZ6110P5HOJj+6zBqtw== X-Received: by 2002:a17:902:b78b:b0:143:baac:2ebc with SMTP id e11-20020a170902b78b00b00143baac2ebcmr5446807pls.77.1638345244841; Tue, 30 Nov 2021 23:54:04 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.54.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:54:04 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:42 +0900 Message-Id: <20211201075348.3121186-7-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Reviewed-by: Umang Jain --- 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:53:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14947 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 AF4A4BF415 for ; Wed, 1 Dec 2021 07:54:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6EA5D60723; Wed, 1 Dec 2021 08:54:10 +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="F4B8YGqw"; 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 58B3F60724 for ; Wed, 1 Dec 2021 08:54:08 +0100 (CET) Received: by mail-pl1-x634.google.com with SMTP id o14so17040048plg.5 for ; Tue, 30 Nov 2021 23:54:08 -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=F4B8YGqw2F26pQG50le1AIsGG53ZUpOqfteIA66HcQnxv0wfnWut6v9AFyWE3FNnpZ NINe7ApTKli56zce5j/UK9bhtQfs3MPF5w0aMjupQAaCScKeCyqFcRlAKZAL4q08ESWC pubiS8bWgXjQlMSiDuYaGUXWvJWhDPZEzIx3o= 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=rzlmjRR2Iub5ogZp3UzTKaP5fZQq5TjGZKRWrCa43eyqCHWqhOHwhEEtGngXLmHKGN CQfMMlCTtpgl5rmkw2jSDLHj1bRU9zFnq6qax82MfGB7mXDD9FxTfWr6A+7LfB+FfgRT uCPjY/mxjoVFfkuyoTqBaIl0yT2BQgzb/w5GXZM3H5NeLH8w2bcEAfFC3xTHv85/Z/Oa ZyMvSMbtk9myZZaxDO8uV/KqNmTpgPSA1+RBM3wlQkO3kldoE1Ww4CkK/TG7QPsbEJfU jr7FWgcgkjIQ4cjwlAmw8+RugC77QvolPNr8HTBBxSth1t8fVX76eB23VOAqfhcMgHx4 SZvA== X-Gm-Message-State: AOAM532+5hlPQaHMrJuUnPRvQQgCPhG2XF+O+yQVN6ljvB2D2RLb2u2F yYByFbV1lZFaeX0Z75DeoCrF9BXQ8sWHhA== X-Google-Smtp-Source: ABdhPJxH6Quf09cAe8T168/0LYPZ5MVLKlJpyUcKeKmNQFfrZpgRadwXQ/tAyEQ6e5kx2MQaMKILGg== X-Received: by 2002:a17:90a:d481:: with SMTP id s1mr5405915pju.66.1638345246747; Tue, 30 Nov 2021 23:54:06 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.54.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:54:06 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:43 +0900 Message-Id: <20211201075348.3121186-8-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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:53:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14948 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 0F94FBF415 for ; Wed, 1 Dec 2021 07:54:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C278460721; Wed, 1 Dec 2021 08:54:11 +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="XyFo/fmN"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 258A760710 for ; Wed, 1 Dec 2021 08:54:10 +0100 (CET) Received: by mail-pj1-x102d.google.com with SMTP id j5-20020a17090a318500b001a6c749e697so531340pjb.1 for ; Tue, 30 Nov 2021 23:54:10 -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=XyFo/fmNmHhyJptbdLHThfl1YPgVWDzdxGMGiG+QiCgTR57IpCCISXLrRrdKDTZDNF ltsjKSAXKGUDYHtelx/pPOzrOwENKEAX2DFsu5jsQKYNEUTHrDnXtgfNEGOZk931hfww LVWl5LcrInL9Td0tS5c9PeepYusLfuQzoSXZM= 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=JgWZTcpyvLNAep/YJEPCI29zznZ7/5ligmJtSS+hfji2DniaHcAXl7p8CYnveUKlfo FNC5sXuB+DI+/DmVBsOM9IXFI7jC2l9XTePfTNt5A8GK4MRkCrXvIwXUQlgjiVEaYC8l tZNCAbgTJZvJInriKuI9xh452CS8D9AUpGz1Rx4WMJnZTDpuMxcgmitpeWO3q6uNqdHj PF1LEiboifULq9jcXBIbtKJaqCbpPz0xh7qFyGFjZVcmnnMpoZMrZBMHMUBUGiWg7eP0 hqT6zX3grwXD+5RYiFgoU5ouhA5xKeJAs1Wih9x5VAnUBqeoP2vbMqILKqVdxmj7P+PO 93RA== X-Gm-Message-State: AOAM531WmivLTFoQmXqvkbLrhKe6ZtM1tdqhisfcv9rxs/2KSrVK4FhV nYPn03kZAV74K2M2GwCg5qAMXWGepnPs8w== X-Google-Smtp-Source: ABdhPJz8sqssnFAwOcugDiPCT4CKmZILqz1mRLbrqINz2rwKFzQqiBIGlELZnMN4uTHO5WRZN+HbQQ== X-Received: by 2002:a17:90a:670e:: with SMTP id n14mr5580256pjj.144.1638345248475; Tue, 30 Nov 2021 23:54:08 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:54:08 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:44 +0900 Message-Id: <20211201075348.3121186-9-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Reviewed-by: Umang Jain --- 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:53:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14949 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 A8BD5BF415 for ; Wed, 1 Dec 2021 07:54:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 23F2460710; Wed, 1 Dec 2021 08:54:13 +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="PPJwu3K4"; dkim-atps=neutral Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1410F60727 for ; Wed, 1 Dec 2021 08:54:12 +0100 (CET) Received: by mail-pl1-x636.google.com with SMTP id o14so17040167plg.5 for ; Tue, 30 Nov 2021 23:54:12 -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=PPJwu3K4h7g4wpWqG1pLHsM45BREkw+UL8ixhzcQ0BJP1vU2DU+sS0aMsPo6mb23S+ fngmPI9+YpB77xf6xfsRqXNb7YeyJtCd/9gieX7+WwtUjFp63GM19JhsCxC8WWtxxYfZ /zol5Q66ubyfBk10PPjhzb4VfZ7uZF1QrCozs= 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=vQm92Ie92ATbMgj26B4Kf817I/GdAIa2orGQZg6zz4DpueybI0AOfAMz7TkCPBqj34 bMpWs1Y84ch8AUkB1aO/pGMJ7q4uT3p0NvULmyREowAT2f0xEyqS9RhpyA4lYufBHxgl QbNl3M1JNQYvff3Ey9/zKXyfZ3yvmF27R0v+I/pnZbsROnnK6n7y2K1k3nf+sie8FPHQ mncEWyNfObQxVWYjmWy1RPpQ4egezgJkHpkGhJ+Li9d2pi7cwNBuwSFKIiRr4DLTJ8CR 61IVR/50gfuauJ1s4tojIyTuRh7yl4WOIaQ74z7vxW/9G7KFObstoyJEZZzpw3kbfPiH OCJg== X-Gm-Message-State: AOAM533BDBAoHZDeEIjirxBpu74n8kznPxZjHbkj/x2sQJVlT9PZdN6F hOELFnC6xwC0PmcSdnb9gAdSVHJXdJCIZA== X-Google-Smtp-Source: ABdhPJwOyThNx/xsjT9+3BnoZ1q1tPITOyu1FpmqpzPg2pm9BvntNH2jX4e4c5g3SvXE5gE+fZy5gg== X-Received: by 2002:a17:902:e84e:b0:141:e3f2:36c5 with SMTP id t14-20020a170902e84e00b00141e3f236c5mr5582248plg.74.1638345250392; Tue, 30 Nov 2021 23:54:10 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:54:10 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:45 +0900 Message-Id: <20211201075348.3121186-10-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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:53:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14950 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 0D8A6BF415 for ; Wed, 1 Dec 2021 07:54:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B9F5F60725; Wed, 1 Dec 2021 08:54:15 +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="mNT0xJqE"; dkim-atps=neutral Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D670D60727 for ; Wed, 1 Dec 2021 08:54:13 +0100 (CET) Received: by mail-pg1-x536.google.com with SMTP id q16so22709912pgq.10 for ; Tue, 30 Nov 2021 23:54:13 -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=mNT0xJqE2t/JW87M9LAUBLMBhCxWyaNcEqJXjg0TLBEGrji/108TQvuutSTdTozDgY 3BUAL24rbb/vj5JLdbw2jAV87Rrqo37I1pTzHeIFEn/QEZ/UgSfLpboRuXNacWMBsco4 1+ClV193+WxN2q1206tVE8U5gwMq8w7/Pl6hs= 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=MdJBigVknYBboCKMXbVaQkAOZYBpoiaZA1j/ipFbd5grqpzcOejT+lPcJaTGQcP4S1 GNERdH6k7b0De5xXWVhx67s0GIaY6DZFfntV+8NEStdjzWsB+6AVV7oZtAaLmOvoH4zB hcgfRl//sfWc29ADEj5Ahzd9lhn8UcFJaVt8U9qxLHq/N58p/JThnxU3M10phtjxj2Vy jQmxxH8iAsRGe2muL50O2i05kjQqqNbD5EErhPJCAHYo39wNidbBstrWiec50hzuCW64 qhcMLPetqTSWCIBDj48FqOc18vOJ3VtcIjA8RREOkJdk3bg0bE2i0llneGcD1pdju0sQ td6A== X-Gm-Message-State: AOAM5322FyeNQKIf4o5C64X0lKUhYdWb109PMry5Nq+L4Tf5CXUCfTug 1o4U6lbM2ASIHYW64bESCToHJ+lXHRDzUg== X-Google-Smtp-Source: ABdhPJwogPHv0C8Gz8pC5FaNmENXLz6wFQuul7Xx5cy0MkVgcVtOK0RcLoz/pqv7fL6xChNpnCSedw== X-Received: by 2002:a62:7a92:0:b0:49f:9a0f:6bcd with SMTP id v140-20020a627a92000000b0049f9a0f6bcdmr4343153pfc.43.1638345252146; Tue, 30 Nov 2021 23:54:12 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:54:11 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:46 +0900 Message-Id: <20211201075348.3121186-11-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Reviewed-by: Umang Jain --- 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:53:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14951 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 6BAFCBF415 for ; Wed, 1 Dec 2021 07:54:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 21F6960727; Wed, 1 Dec 2021 08:54:17 +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="Ixaxy3Gu"; dkim-atps=neutral Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 838AD60720 for ; Wed, 1 Dec 2021 08:54:15 +0100 (CET) Received: by mail-pj1-x1030.google.com with SMTP id cq22-20020a17090af99600b001a9550a17a5so20378892pjb.2 for ; Tue, 30 Nov 2021 23:54:15 -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=Ixaxy3GuVLG803pXWFsSj724qX0bH9FhLluVkALfzhW9pbT0U4cams0KYhBsmn7Du6 vfRCRFLkNWozkHmze3CjNCrjGvBXTrQvIrcSXFufF6/xykwUgpd3h/jKIZrZFbYSkxqR RMqjh2sU2btC04rZd7MQbmcVWJMWlxlgH9HBA= 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=bicwEAYSA6R5UGbGr/Ke2QN8IeuKEQb/zk6hvmSll82s1JsREu0OSygLzjKiTD8e+f ub+nOBYNGu17zugrHkwka0cVfpk4neVr/XH4pQM6tjd8KE7y80f5d425zfHDMja8fBnu BNg1mD5jZX9JdotDnZqtPevO9jbWWBZ5f/imuHPSGKt5hdkE9dXh0abGOzt2YCIxFj7n ZCcJ1nSK/N+JrUKpgVmLuGIQVNRIQPrw6k9ufXkPvbpBgJoLLbplVpMVuwr8ldDA1mjH Avaij7eRdecriE7YV1V5jflQSA/8QeqGyf6eSeorHEzscNVRK4cYFhtN2tWwkVP3aNqX vGWQ== X-Gm-Message-State: AOAM532fOb6Qw1ogge5kTqQ9Jx/jw1U7tDyMAK33lZBtZ9MBD+d8e1aN kmtV0e7AHzokuB9Oy0eVX09770xAx2ziPg== X-Google-Smtp-Source: ABdhPJzSrtaVr5SrRdbdJrScoHOaCe/Aw6S5bombvA/O2/lVNTLIqYUSwHe5HsEtTE4agx7uRVKAnQ== X-Received: by 2002:a17:903:4053:b0:143:6d84:984c with SMTP id n19-20020a170903405300b001436d84984cmr5582218pla.37.1638345253909; Tue, 30 Nov 2021 23:54:13 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:54:13 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:47 +0900 Message-Id: <20211201075348.3121186-12-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Reviewed-by: Umang Jain --- 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:53:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14952 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 CC4BBBF415 for ; Wed, 1 Dec 2021 07:54:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8805B60726; Wed, 1 Dec 2021 08:54:19 +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="MYxZEy7d"; dkim-atps=neutral Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 63E626072E for ; Wed, 1 Dec 2021 08:54:17 +0100 (CET) Received: by mail-pg1-x52f.google.com with SMTP id r138so22682216pgr.13 for ; Tue, 30 Nov 2021 23:54:17 -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=MYxZEy7d8HWtbbD6Q3PRGz6u/6DmCOmOrNAZEuQZdfLTrys9oYTfg9PnMQPOeSD9u9 quW3sJhb28BZ5PvkUfVBGxQaK1aNInrWoOK25EUM0LkY7IUK1RRg+y3yYS2gQDj9mJEj eC96ngG66r4paGxrn41ZgvmOnfjDBPgUTFd3s= 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=XslOSXTUy4VTex5O1grJKvwOdu1pkjVAYTJfLXB01qvcs5UpRj7zGMGrShvld6Ci/U XTZgrNeHHY5l1VvgAHaSSvlXU2dDZ/0qmMMHQAx8WjNMOno6hBq1rqlwkYqqqi4S7I2L m+BJCBVrmHROXp+bqjAfRmuJtbUjO4t1+/nOPCWNsn3GrF6UVly8tWk/I0JxA6YvBdQD Eqf/Mb+UAFA58jp31L46iZZdwoezwCdZdEtelqxqfabYF9PdIVqmkYAH638aqilWEMvZ Nz2WvSydtsrG4vFxaJDhXBznAn29bJvHmaVuvBGGal8zM1E2U5uSnHkLEu3J21aDOrSo LPPw== X-Gm-Message-State: AOAM530PIB2rKeO5GD1cGqXoMJERX6dPC3V+42gFdl+UdUk1ZeaTshaX UdjChGPJlopp6nJqWPeC07dI4IskkxhfRA== X-Google-Smtp-Source: ABdhPJyT6cIt08yy25L3+SmnTOpjivWub0TjU/Vhn2eK+jcO0ffOoqAPzb1iBWtRW0T/456K4o/2sQ== X-Received: by 2002:a63:1d13:: with SMTP id d19mr3586408pgd.383.1638345255741; Tue, 30 Nov 2021 23:54:15 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3892:a049:59ba:c772]) by smtp.gmail.com with ESMTPSA id l9sm3500848pfu.55.2021.11.30.23.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 23:54:15 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 16:53:48 +0900 Message-Id: <20211201075348.3121186-13-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211201075348.3121186-1-hiroh@chromium.org> References: <20211201075348.3121186-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Reviewed-by: Umang Jain --- 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,