From patchwork Tue Nov 30 15:55:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14898 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 CE079BF415 for ; Tue, 30 Nov 2021 15:56:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7778B60725; Tue, 30 Nov 2021 16:56: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="XFooAvm9"; dkim-atps=neutral Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 82D6360710 for ; Tue, 30 Nov 2021 16:56:10 +0100 (CET) Received: by mail-pg1-x534.google.com with SMTP id s37so10567648pga.9 for ; Tue, 30 Nov 2021 07:56: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=RfQVNtG/v2bEcPhs3B2DWL5RmPs7AC4Gxpfmf3NMFrs=; b=XFooAvm9HTjN2nuHjmizEWxIfAMJjX2h8N6mCH3eBjBFHuzE3b+dlJlB2L+hVNnzEt 5UXp/gznK6SuEUdLGwmOLalOa9ESmPTR7m5Epc7DYLPOMI07TOlA9fVgtWDjHj1InGsL eJ72cimj8DerLVaTjdB02nPRYcQYZdwP2iFGk= 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=qLy46waWRURDOBGvrnuWjvwlzQuv+tCrF8Ch7SIHX0USLarFIGgjw0Fm2w9pk5EXuc gvdlU/eZs2V26fXlVT1nWHuaD1eO4XKHW97s1GvLd/t+rgYmrEVdIK1XBN/VQRrrelqS Mz4uzGnvPQrWEFPTLFKgxVf5vk4Hh3ytiobzScLG2SGwD/hcCSWO94toDJXc899yHWbC Jk+3dc73ij53FCl4gGVRoi57Yo6ytbnB0OmiKWPxJK3zoV3xNW1AxKpzn1LyqbjZ9WAR TFu6tcOmM5rCCuwUQnKVAPcbd5A7+Ad0R+h/0lEOzQNQLA5II5+9uWjPcIz9gNCKG4tU /kng== X-Gm-Message-State: AOAM530HoviXO9gnRl/GghjN45cEqivQ4BhyxC3+RgRswpvoBFjusjKb GR0yU52eoM/vb/VdigjMF84AdpdMHrCgAA== X-Google-Smtp-Source: ABdhPJy9+UV1SFbz+7tD83/BGC5Odi/zN3luvchLAI5NHw9QwZoNvlJ95zp9VbBMvyTkY/KiFLO2ZQ== X-Received: by 2002:a63:5520:: with SMTP id j32mr39034899pgb.443.1638287768893; Tue, 30 Nov 2021 07:56:08 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:08 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:49 +0900 Message-Id: <20211130155600.2203123-2-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 Tue Nov 30 15:55:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14899 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 437BBBF415 for ; Tue, 30 Nov 2021 15:56:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 41D0660729; Tue, 30 Nov 2021 16:56:14 +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="RCBnXTOT"; dkim-atps=neutral Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 63040605C4 for ; Tue, 30 Nov 2021 16:56:12 +0100 (CET) Received: by mail-pg1-x535.google.com with SMTP id r5so20189937pgi.6 for ; Tue, 30 Nov 2021 07:56: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=hri0Xm34PsgBbaDCXWbRIaQJpAoLrbjERv7g2d7844k=; b=RCBnXTOTviLcSK2W20Eo6ALjoCqLDIH4sBqnbEyQC3f49H8OkCwgCDmDnBleBwKW6S uJVp3dlyUfEsubbxq19hQuisJQ/abev2hPuXTe7KxVOTWGYF2Wm4SGHpIUhHi8gKRj38 p6wcLDd7RL+QXlfdboXpSLiAFNELJbs6OzOZ8= 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=4WaYBD4obeLdxh7ziL643IgPWydj67msBoubRxzE5ZcpM5xvZUDORX5LU4lL/AlGvt XWk//6Omhz05PRw0Cm1AsL4YZaIVGk283GWypGlQ+zjTu63bR10Dz8864uodxJo7Lk90 Np+QnHicEg1X1JuIFGfqRyEnhuhyRwFNEmOTKemaC49xJ37GMkvE4LQyqSOf99HTIA7b EncbQvNeKzyZQYahNNipb/f37oF7eWoZqk5o8mXZor0C8Pw12FFsj90nv29FrbibGKFM A8j1JlSL3og9IlEWoxYsbyfN3XjKtDh+3KTidk23x9uWzJl78EIf0tRczVxFnatCM8Q2 gNrw== X-Gm-Message-State: AOAM533yeo615Q12Bxy/yLHvdaq4fovOMTkUHAks507EZIhncYWDK6dP 6Sv2OWyp32JoLXkVgc/Y1dR6M/B3IvXOwQ== X-Google-Smtp-Source: ABdhPJwSP6zwtlzePuscHfYFTbBQN7SfTxsDOq3gAMDLqxeds4KpTKLOzCkRWh7jATp+FOuKAxwHTw== X-Received: by 2002:a05:6a00:b89:b0:49f:f600:658f with SMTP id g9-20020a056a000b8900b0049ff600658fmr47648644pfj.71.1638287770696; Tue, 30 Nov 2021 07:56:10 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:10 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:50 +0900 Message-Id: <20211130155600.2203123-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 Tue Nov 30 15:55:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14900 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 3B103BF415 for ; Tue, 30 Nov 2021 15:56:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E570560726; Tue, 30 Nov 2021 16:56:18 +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="oUbCTLia"; dkim-atps=neutral Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 20BE660727 for ; Tue, 30 Nov 2021 16:56:14 +0100 (CET) Received: by mail-pf1-x433.google.com with SMTP id n85so21034870pfd.10 for ; Tue, 30 Nov 2021 07:56:14 -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=ZWvi+XISmmJU6hgwONNDHHxe6yS4Ts75cVJ3qhZsk8k=; b=oUbCTLiaVQ10SE8v6+rWXrWyYDz5CrrJG3TqLq9jCeW/3KNHdoKS7oG4pycUCo1sLL DWL9u0F1Z+KUZEGQzyG0n52roEEksiWarYC7vJdnSu/GyYD3GuAVUm1CY1Ba2gsGV/fS bDcrnEDiNNhzS0uHiRUZ5ZBEzzeR9oTYUGDIU= 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=ZWvi+XISmmJU6hgwONNDHHxe6yS4Ts75cVJ3qhZsk8k=; b=5khnCRYsCQSTny6AuV2jz8mIvJC7eVKOw2Qez+fxaM/K6q5S39kSmKtwXe9Orde06b OqewMly9hF0sh8vR6nfy3cQ4JmH/SZnmBgpKH+8ni48JvzzqRASV+p6+QFHpXFXujdJc dIh3PG2lzXAdwz2v+j3AmdG8o+POE0g7zY4bDMf2DJm8OE/XXt7eIMMfTzH4WO0XGy4r x5wcFJc0YqIVdPytm1crwz+gWhh/MnOnYskOFmdMOyZybf57r2bQxFj7lng6OpLV5E3Q 65aSplJnmirN6IxJZ0xRYjgw/57P6ILKJ/EJru9J/EqFYzB1y/sVzdXlqoWzmdg9NdZP sc2Q== X-Gm-Message-State: AOAM530YEEr0LdbwYmgWzuDSO2GWDePpU4mRosm894TC4D0OEwGvWA5Q AajG9hvdhy6VSJapioG4cnk35XbclTfT6Q== X-Google-Smtp-Source: ABdhPJyghGmKKOKdanFvsfcVevgkQZHN2eYiF2/swexU3JfvHx54RhNbkhXXx6J1H5J9UaJUCXyjWQ== X-Received: by 2002:a62:e406:0:b0:49f:dc1c:f3e1 with SMTP id r6-20020a62e406000000b0049fdc1cf3e1mr46870733pfh.21.1638287772491; Tue, 30 Nov 2021 07:56:12 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:12 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:51 +0900 Message-Id: <20211130155600.2203123-4-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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_lcok are used in v4l2 directory, mixing Mutex and MutexLocker. This consolidates them to Mutex and MutexLocker. This also fixes vidoc_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 Tue Nov 30 15:55:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14901 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 55CCAC324F for ; Tue, 30 Nov 2021 15:56:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C451A60720; Tue, 30 Nov 2021 16:56: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="LK48A4Qd"; dkim-atps=neutral Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3369C6071B for ; Tue, 30 Nov 2021 16:56:16 +0100 (CET) Received: by mail-pj1-x102e.google.com with SMTP id x7so15717701pjn.0 for ; Tue, 30 Nov 2021 07:56:16 -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=LK48A4QdqaC35VtHXSsgZrmlZYjBukm9Pjbjv5S3daXMXoIaQjfIELHO9nUJf5Z23L qkCPQMnxXXN54f1jKZcyfgJMdKplD2mT7/BxIllJR2AJMgVoi4ztWFcNUA9AZgSglkka 5T+nhvVa8ndULmlvLlvpMLWz/3C/nTuuU3oUg= 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=gqWBh2wYT2RupnSrkb+XBDIQSDTVU9x5HEzwyggwDCHhb8j/QhPbNtwFT1mWR90y1q ynLJzzxra5Td79aUC668VIp3K0P645wuohrLu2cJF1WqzgG/YVq/iposazA8NCBtZYsw iRfWXEnRc6NodMkg154iO4qHSSaBPIN48DAXfmgczZwaauBfcQvS/egv65O1hWm/dNQa QTzwdqrcnUFgO3Ccrbq7HKd4KSv9VYr3doqAv0/9edaMuQx9SNVCwHKvcYqEsrAxfkQs SkXdlLFjk3RRekf89y/tq4qJBXccCi1nyGApUkoOq1SgBKq299TNvHD9sbTnidfykqoM FBeQ== X-Gm-Message-State: AOAM533grWg9DTJhVggs6n8fmYjok/Hf2hlX+b1edt8+dT6y3S4zQwje z1S8ODLreMCX+huqtOhHH2hmhTWh03JqMQ== X-Google-Smtp-Source: ABdhPJwcVo1BT7bFY+G7KZ9Y0csrcgW1mlNDevssb8q4hr4CJyWLSAOxmLTdArJc1LBKW+I+7D6c/w== X-Received: by 2002:a17:90a:2ec8:: with SMTP id h8mr323256pjs.168.1638287774271; Tue, 30 Nov 2021 07:56:14 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:13 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:52 +0900 Message-Id: <20211130155600.2203123-5-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 Tue Nov 30 15:55:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14902 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 45C51BF415 for ; Tue, 30 Nov 2021 15:56:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 018506072C; Tue, 30 Nov 2021 16:56:24 +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="gimMj3GU"; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A778C60721 for ; Tue, 30 Nov 2021 16:56:17 +0100 (CET) Received: by mail-pj1-x1029.google.com with SMTP id j5-20020a17090a318500b001a6c749e697so14095491pjb.1 for ; Tue, 30 Nov 2021 07:56: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=AAc/KAYnNTACC5cCKhDfWsaHmWoRqjF3AfvdOey73Xk=; b=gimMj3GUVwJXigxBhYuAFj7Ak867vEEmM20+zmSiewdMRQ5tdsH9c2KCle4wTY2mYM CbcSYH8OO6XYAwJ623ZEEYpc8As5MCEBWBbNPQjZgkZc0BdreqhCaQAi+KnqrwoZnjpi 92pwW6q/pbhOpSnCNvxscUHDvkY6EYWxXzwE8= 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=AAc/KAYnNTACC5cCKhDfWsaHmWoRqjF3AfvdOey73Xk=; b=3sK+a9zlB8BND82TPyjxWU20fWUByjyxJ61DQU2wc5z0brAvQRZ6R8xH4YdVmOm/e9 82j2QmuV2m7gUUS+XY2BTlwja6c58UPxyXAuRQ746Er+kyR1Q9MtAtkk38kAWgfXRA32 Fyp/b/jIgkEL203R8SPGOJWHBgh1mumFV01+uBJB4QIE5mjzaYhoxCwW7gJdub3gufFp pfWBSINLGh1YpiPP835LZ7NRZHZHmpcv0QtpqSoAWUmQ5vc5CDQAASVu731uulSjx0fS 8USaQ66+IiWoIjSciKOPcm6RdBIVjhEiaGzN9UA1qMvnwRMtS4u6RLLmPARTSHVAh+dd XqzQ== X-Gm-Message-State: AOAM533PYFu/UdJCPOW8fu359o8k1y0xGYX01yDzJJlvLYqbUw8XtlM0 ZzebQ9qSl9axEnfuxsdE36VsmFrrYyy8Sg== X-Google-Smtp-Source: ABdhPJzsZVdZgQjRb420INIYgioxYUGFUzHh92MIOuAz/hIn9wxTZAZUPZscDNQnzVdif9Hf/7et7g== X-Received: by 2002:a17:90b:230c:: with SMTP id mt12mr285357pjb.63.1638287775909; Tue, 30 Nov 2021 07:56:15 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:15 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:53 +0900 Message-Id: <20211130155600.2203123-6-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 --- include/libcamera/base/meson.build | 1 + include/libcamera/base/mutex.h | 131 +++++++++++++++++++++++++++++ include/libcamera/base/thread.h | 7 +- src/libcamera/base/meson.build | 1 + src/libcamera/base/mutex.cpp | 121 ++++++++++++++++++++++++++ src/libcamera/base/thread.cpp | 15 ---- src/v4l2/v4l2_camera_proxy.h | 5 +- 7 files changed, 258 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..2792551c --- /dev/null +++ b/include/libcamera/base/mutex.h @@ -0,0 +1,131 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * thread.h - Thread support + */ + +#pragma once + +#include +#include + +#include + +namespace libcamera { + +class ConditionVariable; + +#ifndef __DOXYGEN__ +class LIBCAMERA_TSA_SCOPED_CAPABILITY MutexLocker; +#else +class MutexLocker; +#endif /* __DOXYGEN__ */ + +/* \todo using Mutex = std::mutex if lib++ is used. */ + +#ifndef __DOXYGEN__ +class LIBCAMERA_TSA_CAPABILITY("mutex") Mutex final +#else +class Mutex final +#endif /* __DOXYGEN__ */ +{ +public: + constexpr Mutex() + { + } + + void lock() LIBCAMERA_TSA_ACQUIRE() + { + mutex_.lock(); + } + + void unlock() LIBCAMERA_TSA_RELEASE() + { + mutex_.unlock(); + } + +private: + friend MutexLocker; + + std::mutex mutex_; +}; + +#ifndef __DOXYGEN__ +class LIBCAMERA_TSA_SCOPED_CAPABILITY MutexLocker final +#else +class MutexLocker final +#endif /* __DOXYGEN__ */ +{ +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 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_; +}; + +} /* 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..327b90c0 --- /dev/null +++ b/src/libcamera/base/mutex.cpp @@ -0,0 +1,121 @@ +/* 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 + */ + +/** + * \fn Mutex::Mutex() + * \brief Construct a Mutex instance + */ + +/** + * \fn Mutex::lock() + * \brief Locks std::mutex + */ + +/** + * \fn Mutex::unlock() + * \brief Unlocks std::mutex + */ + +/** + * \class MutexLocker + * \brief std::unique_lock wrapper with clang thread safety annotation + */ + +/** + * \fn MutexLocker::MutexLocker(Mutex &mutex) + * \brief Constructs MutexLocker with \a mutex as as the associated mutex and + * locks \a mutex + * \param[in] mutex Mutex to be locked/unlocked by MutexLocker + * + * This blocks until \a mutex is acquired. + */ + +/** + * \fn MutexLocker::MutexLocker(Mutex &mutex, std::defer_lock_t t) + * \brief Constructs MutexLocker with \a mutex as as the associated mutex but + * does not lock \a mutex + * \param[in] mutex Mutex to be locked/unlocked by MutexLocker + * \param[in] t mark to specify this constructor is called1 + * + */ + +/** + * \fn MutexLocker::~MutexLocker() + * \brief Destroys MutexLocker and unlock the associated mutex if it is locked + */ + +/** + * \fn MutexLocker::lock() + * \brief Locks the associated mutex + */ + +/** + * \fn MutexLocker::try_lock() + * \brief Tries to lock the associated mutex + * \return True if the ownership of the mutex has been acquired successfully, + false otherwise. + */ + +/** + * \fn MutexLocker::unlock() + * \brief Unlocks the associated mutex + */ + +/** + * \class ConditionVariable + * \brief std::condition_variable wrapper with clang thread safety annotation + */ + +/** + * \fn ConditionVariable::ConditionVariable() + * \brief Constructs ConditionVariable + */ + +/** + * \fn ConditionVariable::notify_one() + * \brief Delegates std::condition_variable::notify_one() + */ + +/** + * \fn ConditionVariable::notify_all() + * \brief Delegates std::condition_variable::notify_all() + */ + +/** + * \fn ConditionVariable::wait(MutexLocker& locker, Predicate stopWaiting) + * \brief Call std::condition_variable::wait() with \a locker and \a stopWaiting + * \param[in] locker MutexLocker that is locked/unlocked during wait() + * \param[in] stopWaiting The predicate to be satisfied + */ + +/** + * \fn ConditionVariable::wait_for(MutexLocker& locker, + const std::chrono::duration &relTime, + Predicate stopWaiting) + * \brief Call std::condition_variable::wait_for() with \a locker, \a relTime, + \a stopWaiting + * \param[in] locker MutexLocker that is locked/unlocked during wait() + * \param[in] relTime std::chrono::duration representing the maximum time to + spend waiting + * \param[in] stopWaiting The predicate to be satisfied + */ + +} /* 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..23be995d 100644 --- a/src/v4l2/v4l2_camera_proxy.h +++ b/src/v4l2/v4l2_camera_proxy.h @@ -14,7 +14,8 @@ #include #include -#include +#include +#include #include @@ -59,7 +60,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 Tue Nov 30 15:55:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14903 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 D53E0C324F for ; Tue, 30 Nov 2021 15:56:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 70A6F60710; Tue, 30 Nov 2021 16:56:24 +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="iGKJuh7E"; dkim-atps=neutral Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 83DEF6071A for ; Tue, 30 Nov 2021 16:56:19 +0100 (CET) Received: by mail-pl1-x62c.google.com with SMTP id v19so15253544plo.7 for ; Tue, 30 Nov 2021 07:56:19 -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=ax9Q5IE+2lzgN/6viRT9yW1Y2YQJjHoAjbGe2VAh9io=; b=iGKJuh7EUsxWv79EK/FERPm4p5aQ2CwTLxQn9hPLzjrUkxb7CFt1imWlEl1CYJ6P6g 1icLEPXuUD5t32t1M+jZfj90K3ivgjeSN6O8LzeIniZFGF1DsFD68MkO9TcZDM0rATpC j8YQu7bfeAm9HN8RQDqwO/i1hepztMshbjNjI= 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=ax9Q5IE+2lzgN/6viRT9yW1Y2YQJjHoAjbGe2VAh9io=; b=A9zo3mcDgDvJ2URMuNNey6UKWV+E44yc3RjOEe5XhaVhQhL2tWBWSy2DyMHqo1mtHV tpwRbDgNxIHQ+NRLnwL2i2PiQPL9AlUPIIWlpUtbBUxAFn3E/KeE6bQXdfNHSqGGp2vZ fxUBTf8MuPTeUpPf9PhqwKEO33FG8EjxFOahKGrP5tBZZe6I1uk3T5OA6PUPpeTiU98T y1YTo1CxuV6u+/YLrC7PsgZU1k9EeLvjOvvJ3ZTMy3c+jWsH4uUF8xpj0Ge+hylIT4G3 0wErZoPnWdIRg0BtGu5DGwNYxt68Bo/L7BMCFiOzCLif0zuu5kjOIELIAyTpB+CMi5a0 YFrA== X-Gm-Message-State: AOAM530NXB/tQREI1ZOWt81E9vDs54LGUwldRThU16IRBfleb3ACRC66 BFPdXoMXPAFVNU7owf3foJu1xiAaL/eBYQ== X-Google-Smtp-Source: ABdhPJyIuehuy+Z8VkjzabKQAiS6Ldd+RhpDnk4sYMDhr83e2tEMr+uVlfTPnIwcT82arIQm57LAxw== X-Received: by 2002:a17:902:7616:b0:143:a8cd:ef0 with SMTP id k22-20020a170902761600b00143a8cd0ef0mr259355pll.48.1638287777810; Tue, 30 Nov 2021 07:56:17 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:17 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:54 +0900 Message-Id: <20211130155600.2203123-7-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 | 2 +- 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 | 3 +-- src/libcamera/base/thread.cpp | 1 + src/libcamera/camera_manager.cpp | 1 + src/v4l2/v4l2_camera.h | 2 +- 12 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/libcamera/base/semaphore.h b/include/libcamera/base/semaphore.h index ec05fad3..271d5427 100644 --- a/include/libcamera/base/semaphore.h +++ b/include/libcamera/base/semaphore.h @@ -8,7 +8,7 @@ #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..2fd7e01d 100644 --- a/src/libcamera/base/signal.cpp +++ b/src/libcamera/base/signal.cpp @@ -5,10 +5,9 @@ * signal.cpp - Signal & slot implementation */ +#include #include -#include - /** * \file base/signal.h * \brief Signal & slot implementation 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 Tue Nov 30 15:55:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14904 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 D463CBF415 for ; Tue, 30 Nov 2021 15:56:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6979160733; Tue, 30 Nov 2021 16:56:25 +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="KpZMwVfQ"; dkim-atps=neutral Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 78C7B6071A for ; Tue, 30 Nov 2021 16:56:21 +0100 (CET) Received: by mail-pl1-x62a.google.com with SMTP id o14so15275749plg.5 for ; Tue, 30 Nov 2021 07:56:21 -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=NsLHxMNeXQ7lFsLe7Zk5ZpE411R8RH9qkNzSxw4joS4=; b=KpZMwVfQmOhY4Ia+BnF/ZMCnA1mZJ0c0O9o8444w8Yj5wYSAQBdcJk5dFWUrSLAXin 3CuuD0EBNxfTKL4R/QEb9wscyLSDufti4b0OQ3OetXU1xqH6dQ5Iw2pV9SGEcjU2QVJw RYh5cqUrVkYA0vrwSp5MgHW/s+5VatnGWvNOM= 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=NsLHxMNeXQ7lFsLe7Zk5ZpE411R8RH9qkNzSxw4joS4=; b=nQW04zgzfs6rVpCooPTwVHpPnlL5EL9coIdcZY2pL/k8kYdfDsFoZam45kSTI3J+rL qP0etTs2STGJquQaqq2HIAJeGzwa2KJhzaGr5UPfUDimO4krZebZjIuCY/YK1rNt2VTx J8henygyv5VT/uYSaQQq2cwx79sz5XzvlPac8xbw60KCllBBIy6TKVuwjwA+fu+MMK3m DNxfi3n6c8k4etvQHO2Mvlnge94TBgslUQWD+i7d6Krh+2DVgG6ukCRbsFnbaBgRWct0 jSjO4Jzx3pkg4YLqczhm9WMiqNn+HCE1lW6I0BIZg/dZkb+ISqU0TJ0Zn71FuneaBxvU YElw== X-Gm-Message-State: AOAM530yonSapeun4IDQOVxRmaTZ9a/bHndetmEwb/bpzFEtORHSLQWh gYCzyGcvVwdL8IS96AkrwHD108H5hhnUKA== X-Google-Smtp-Source: ABdhPJzlfLtqaF4Ejtw+UQiYc5uFNo7FHwc7+ZmhCvwy65E7ZmhWfoVQ85n+DX54IvRGZe7NuzSw+A== X-Received: by 2002:a17:902:f209:b0:141:99d1:7cef with SMTP id m9-20020a170902f20900b0014199d17cefmr124394plc.70.1638287779809; Tue, 30 Nov 2021 07:56:19 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:19 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:55 +0900 Message-Id: <20211130155600.2203123-8-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/android/camera_hal_manager.h b/src/android/camera_hal_manager.h index 765701b2..5395d419 100644 --- a/src/android/camera_hal_manager.h +++ b/src/android/camera_hal_manager.h @@ -18,6 +18,7 @@ #include #include +#include #include @@ -53,14 +54,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 Tue Nov 30 15:55:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14905 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 E7BC3C324F for ; Tue, 30 Nov 2021 15:56:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6BE1560727; Tue, 30 Nov 2021 16:56:26 +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="nu5eTPmP"; dkim-atps=neutral Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3468F605C4 for ; Tue, 30 Nov 2021 16:56:23 +0100 (CET) Received: by mail-pj1-x1035.google.com with SMTP id h24so15695057pjq.2 for ; Tue, 30 Nov 2021 07:56:23 -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=nu5eTPmP+cc4a6g2SsJKzg55jkuH8Kn4pITBi/BlD0LS3FN59j4VBGUpK7kus1j4Ks JeVfZE6FuBYUWjynExev/tbkPLl43I3MtPfznSQFHVtiXLifQrkYQhhjQkjEPSCksBe/ ULYHeOik5AoOIxmbXOZ+Gg2Niz3uTBFxdSR6M= 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=ybvb37FJZtROlLEzc9+vcLA/NPBwoNxay75T930Csbb0LJBo7ccHJq99bm3YuuNjuT fUwg8nk/tA50FLHTB0HM97K+oa+G18A8m+CZdZJviDuC7k7L/N4WH+DltFkV701hOTV6 1mkRVNwf4mgPhwSEdMkNihc0kq73cjhQBRNCwehCPuJjV89497a5sz3KP5PJB35240q0 jp440IkmEtsfJandmMpV84qG5SNKPMUs07gSMVJrmPCG09Lvr2RJEybAqFVapjsOqJOh dMmO9xwtxt2TvZRo5u9VhlQKX/rr+mumTA0ST5kyk8q6gEr27GUCuE3IxYdaZDNh/Dle 2mzA== X-Gm-Message-State: AOAM530lRAZQyYHBmDvOt1ZVaAbQU7JSgrSr0s/SEYtTISnWfst9EVeM EbUBHO7b5Th10T+eyIszbB2QUtFH25FCTg== X-Google-Smtp-Source: ABdhPJyZeZBkttFlNHi8w1Ic7qIZjqNSEdPbXf7J8WbaK9xi5zlqBtkX64gdncQUWgwTCjj1J35Q6A== X-Received: by 2002:a17:902:b78b:b0:143:baac:2ebc with SMTP id e11-20020a170902b78b00b00143baac2ebcmr187265pls.77.1638287781579; Tue, 30 Nov 2021 07:56:21 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:21 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:56 +0900 Message-Id: <20211130155600.2203123-9-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 Tue Nov 30 15:55:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14906 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 B2395BF415 for ; Tue, 30 Nov 2021 15:56:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 689CC60732; Tue, 30 Nov 2021 16:56:30 +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="YGQa92f6"; dkim-atps=neutral Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A8A560732 for ; Tue, 30 Nov 2021 16:56:25 +0100 (CET) Received: by mail-pg1-x52b.google.com with SMTP id k4so10108442pgb.8 for ; Tue, 30 Nov 2021 07:56:25 -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=p0wg4tkm5r0N24uGxepa+fD7mFrPPlTowXc6iiDkvuY=; b=YGQa92f6L0xiioUkgo/I/6vQHqthKYUlSgSq4LvK+Bj1z/82AmOs8tgLBSHRP+7Zle 6NRJ89ae7EdwWibRO1wciKa9LOuq6GswTmNkLMJrRWgSuPK+geKGosPBS3Y93WIm6ZnH cd9eQMeo3y+Q6/kOPzmRPEODzBZ4GWBNhnX50= 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=p0wg4tkm5r0N24uGxepa+fD7mFrPPlTowXc6iiDkvuY=; b=R8CIyLmSyyrmCOrL5BEeKU3M/OXkshptQpaCe365wl0IyRG9nI87P++ebmRxr740tY DgOVktsqAgYLSxkNu6PB9N2XwLA+gPXHMP+d320LHhxB04EVr3i5tZ+1RUwhCeTVfcI5 NJoK0J41XtmtqQ68T/ln6NarkYkLYZde2ZHwY3W96L3HaAmQktUZq6mhuIBR030cz7Vz 12Pqh8aFXwRjg010bOHF7/JETt2Q7na+KwnzacBBvF3d7Nfv+BQa/NASsJWbJw37kSPO IV4/0wND6w6kJmNgH4YdvZbLxNm4RldVMl+Lvl0jsT4wKiJKlKZpXOn3EJegyazGdRMx DMcA== X-Gm-Message-State: AOAM533KAxd2jyp8b/C+5DQwH1vfBOT+7SzK1g7LP6hpWkAmatcitkgl 9nf8izMTnNuGHGi2X1MN2gLiwGBHIK5eXg== X-Google-Smtp-Source: ABdhPJztii9AUAjdRcEn7DPfpJ9pI2uOzaM/zT6kyHLY6pDr4C9NAe9h0AIqrNXndEu7N3zq/Ej4lQ== X-Received: by 2002:a05:6a00:148d:b0:49f:def7:9cfe with SMTP id v13-20020a056a00148d00b0049fdef79cfemr48470475pfu.69.1638287783587; Tue, 30 Nov 2021 07:56:23 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:23 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:57 +0900 Message-Id: <20211130155600.2203123-10-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 | 9 ++++++--- 2 files changed, 7 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..6737bd2d 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -155,8 +156,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 +171,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 Tue Nov 30 15:55:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14907 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 2A4B9C324F for ; Tue, 30 Nov 2021 15:56:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CFFFA60723; Tue, 30 Nov 2021 16:56:30 +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="NMV5WYyG"; dkim-atps=neutral Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3CE5960726 for ; Tue, 30 Nov 2021 16:56:27 +0100 (CET) Received: by mail-pj1-x102f.google.com with SMTP id p18-20020a17090ad31200b001a78bb52876so18619792pju.3 for ; Tue, 30 Nov 2021 07:56:27 -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=Tsh0ApXzuilv6KhoR6vFwK3R224VNxnPJpnFf/qtahg=; b=NMV5WYyGHr0N5C+ZjPPGUqX1iBMRa8k0MHaM3s5JCoKQA/zEiDpeBMlykT99YuHGA7 hUyswhm+jnZoPBzTERHGblAkp5FXuMiZ/UYxWIMG24sIOvKvbq6AHU5YKMqHJQi0lr56 7uo7zcepi9j5h6FH+zpNQTc+VifpByhpCnK3A= 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=Tsh0ApXzuilv6KhoR6vFwK3R224VNxnPJpnFf/qtahg=; b=4OTh6xbsf2GBjtsZbvGfXG6Hp+Jg1vU/NDypFSf+KOFX/0kyI23uyQyddvxReEOjAm i+qOYRAlreh1PSrIS20OUEZt+dEYVvITNb9Qywnk4EsmwaVCgHE7sHUISqOjCqW0TmzF PVBX7RlJshoEDJ3sEv4EVxj2HQbJ0Bxipr2rU+2NQZp5rNvcT7uyWBoqlt9LqjO5fDM2 73qEHmnIU6qd2ArafI8PyEfGi1VIDOWPVK3nyGMbID0vnknk/oHpUnhvSQEYovPDBVpF tFJw43SkZYbLWTGwuUBSQ3ucAUsOYfYA+NoRLR4fG4Z/oRmfEjcxMhwBlrW0r6nyPFGN UdpQ== X-Gm-Message-State: AOAM530UuvRu/5SQ4IF80XFmZoNnNH+0/pOJnH49hFamFSQaQGKcw3rG WaRjSIqwfg2Sgae2YfwXR2aT9iDIb2LjPQ== X-Google-Smtp-Source: ABdhPJyFAypmTM1vI7ia5kplJF66NJiHs5OFzuy6PlPR9GAmL2XWWPipeC/et3C7G8TMJHJvb/IxDg== X-Received: by 2002:a17:90b:4c8c:: with SMTP id my12mr262389pjb.157.1638287785518; Tue, 30 Nov 2021 07:56:25 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:24 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:58 +0900 Message-Id: <20211130155600.2203123-11-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index d74307a2..e513cd84 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,8 @@ 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 Tue Nov 30 15:55:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14908 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 807FFBF415 for ; Tue, 30 Nov 2021 15:56:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1B83260721; Tue, 30 Nov 2021 16:56:32 +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="Wj7dn/VB"; 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 0B61560723 for ; Tue, 30 Nov 2021 16:56:29 +0100 (CET) Received: by mail-pl1-x634.google.com with SMTP id p18so15242885plf.13 for ; Tue, 30 Nov 2021 07:56:28 -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=eSIHoo+cZo+7Eu+mUseGv7nouggocX5mQcNX6VZPt/o=; b=Wj7dn/VBoCkyK3OdSafLMwafDC4WgV8+iw1QWl08AuXtVZvjumsYNsrJxN1IoTrLm/ y3BHLjlswxroyQstVczyCwJre6G49EQacDa7hv6Ayh7gnk2gzS7D6eVeT9zMVxi8nMs/ P/frg9PPUo/5c9FsSzuZZGk7dG/4vlEd09n/s= 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=eSIHoo+cZo+7Eu+mUseGv7nouggocX5mQcNX6VZPt/o=; b=KaOG1u4GqKvIVlYjuZ80MW/86tbt+LoqNPcd5OIatmLdV2Hi936WZJmvnbY1u1XOt8 OPTT9FHshDEtkCIT5TDiR3503Pb4eNe3y8RIq3tcD9hRUdwZQdbHQqKxNnumdgbc5ts/ BD9CBux19oB253KD5sn/GNDT5juuLj6pY4VGBhoTkUDxrjXNs10U8Q2hAk37O39Sz+iT Bo1oI3Xvh6sNb4e9v96ttq6qHRtrVJUFtFU7Lq+pN+iEPrbjLCOV0+yXpRf9+17VnydZ Od7yuwVOjl6RGpmQz+Gk5sTIjIoRFn6xEszbYT7mNRGGaAuNewTm1NbWdivu0kAK4V8/ HagA== X-Gm-Message-State: AOAM531XL04rFbWrTZbDzDqYDN0YLs5492XOpDThPrYkogEhgyxmlyA0 rEoOi4eBJsGXU3kf9idlm2XUmeW01B3tcA== X-Google-Smtp-Source: ABdhPJxNogVXR9khvBK4dPKzDiC3vv63LZ92qyVpSVYnE0mO7T9fZmea5mGGUUES3hSa0RI+3fZqRQ== X-Received: by 2002:a17:90b:164c:: with SMTP id il12mr241908pjb.241.1638287787387; Tue, 30 Nov 2021 07:56:27 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:26 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:55:59 +0900 Message-Id: <20211130155600.2203123-12-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/android/camera_device.h b/src/android/camera_device.h index a945f5de..2083dac1 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -82,7 +83,7 @@ private: Running, }; - void stop(); + void stop() LIBCAMERA_TSA_EXCLUDES(stateMutex_); std::unique_ptr createFrameBuffer(const buffer_handle_t camera3buffer, @@ -94,8 +95,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 +109,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 +120,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 Tue Nov 30 15:56:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14909 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 6E5E0BF415 for ; Tue, 30 Nov 2021 15:56:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1FE6060723; Tue, 30 Nov 2021 16:56:37 +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="EeKYGWW0"; dkim-atps=neutral Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1CB1C6073A for ; Tue, 30 Nov 2021 16:56:31 +0100 (CET) Received: by mail-pl1-x62a.google.com with SMTP id q17so15243812plr.11 for ; Tue, 30 Nov 2021 07:56:31 -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=AD01gBVUs4CQ+fjG7LPawvO1+zYxIXKwRgpkBIL4u8I=; b=EeKYGWW0JxpblE7rBI5ROa8y47uV9a0n1Ud8lhk1xrF2l9SIUOJYbHz2ey5frxTYbA Z1lBp3LSfZ4oyXJrzY4ZE/dsC+r7BGeTtu6fOrSzp8F/ZSQ2heGHxtWPsXj4yv9SkTiD 4qojWk6Dq7TticmsePbfYIj4DtKR733UHnB8w= 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=AD01gBVUs4CQ+fjG7LPawvO1+zYxIXKwRgpkBIL4u8I=; b=JNH4O+4RuIgNHYVK1me+KxMpCiAd9AhP7uRUTxM6C4yJzgVtcV9BaT38hht+YLnpYK liwfSHqOpnAr6Mejkga6CD9zmVKy68/E4BcrHsAFCZhoZMO8ubv+wWh7+xnHeJ7W2JeX 88tOUr0tPoVnCkxZxc1GUvuRQeNc4/+47QXzmanppqpxzFahiw0KKIcF6w2VbrItptLn /cYL1SRLelI+Sx8ruG1Lo2QAgEo80PAM9rax5pZZEJMkhFup6sdPenTcXEjf467OjoZd 3K2a4tD9MgNGsY79orjyTCW5/kSeMozow41od1pT7V5fSOIEbgeSHoZ5OlCpfjtIsP8m Hf8A== X-Gm-Message-State: AOAM5320dIcZ7SON4PkAzp4mur4IGWf0uCAIBVMsZSeVAaUMh1Cn06+i El+CvrcLId0k4+AvQDQp4fIFfYtgWMBFYQ== X-Google-Smtp-Source: ABdhPJzt5S72dL3cWzddfy2WusDnOjwQ1oZ+KaMMDwXRfAKbEcZ/KqTgWnpn+EzxP2dWjdXNoFsb0Q== X-Received: by 2002:a17:90a:e7cc:: with SMTP id kb12mr32513pjb.172.1638287789497; Tue, 30 Nov 2021 07:56:29 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id pc10sm3510283pjb.9.2021.11.30.07.56.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 07:56:28 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Dec 2021 00:56:00 +0900 Message-Id: <20211130155600.2203123-13-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130155600.2203123-1-hiroh@chromium.org> References: <20211130155600.2203123-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/android/camera_request.h b/src/android/camera_request.h index 887dbe86..dfdc3324 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -57,7 +58,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,