From patchwork Fri Dec 3 19:55:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 15023 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 96295BDB13 for ; Fri, 3 Dec 2021 19:55:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3A3D660866; Fri, 3 Dec 2021 20:55:50 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="a5BcjTT0"; 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 1F1F8607DE for ; Fri, 3 Dec 2021 20:55:49 +0100 (CET) Received: by mail-pg1-x536.google.com with SMTP id f125so4176105pgc.0 for ; Fri, 03 Dec 2021 11:55:49 -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=7c0ztD8/1SOOARKz2G/PkduZhMSeGknto+y9CzbjGq4=; b=a5BcjTT0teZ26Cq4X622BcL5yOg9xIeXR0f6NWIgZLAW9NfhcvGqXeKNN2Gw9hsPCm IrKuG/AAX0lWS4EAjS92lfgPvUX1CAL0H9wfWc9/9CF1qBmrX9KB75cMqoR1pFj8jfQk buG0zdIdng7wQR1Q+Ubnhd/8LyXv4WM/pWy3U= 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=7c0ztD8/1SOOARKz2G/PkduZhMSeGknto+y9CzbjGq4=; b=iFbTEGUXzY84wOEY+jEWEKH/2b2n6nONF8U8yJ3nMeDgWK/94G6QYNm9GeWD8smU/F 4A4etzy7Zk7qIJBHxJBEW5Y1wTowWxaXFDuotdNeoOiWCIIFwoqoP78QITuu/MkvymF2 d8tullwYC0ooIRa4BZuixKKccqws6y+1fUUkTyVWvYH0gbMmk3sx8XSbkpadSMJKfPk2 UHjfzgvK1pkjSsJybLlw2da+YmmRv7m8ZfMIb+zMyoz8h+iHXVJgFfzx7HtxCpa0oa1e Ml6d2lka3LJ6thAKjq/R1eLS3k1gEKCxiv/8snaG2KLLkAJrwYKARsu+0py5xKsSWZEL 8K1g== X-Gm-Message-State: AOAM532frhVWlgJZyikPcw5J1AdBSXaKE1bUieYk3OuQAWZ+8HFVi5vL TC2PM7FkLlSbt6SIzi2lFzqZKvMaJ0diqQ== X-Google-Smtp-Source: ABdhPJzc+yrWxOrdJ8wu/7z4pXKpTXM4h+jDu1dByTLktjr2NJeisoOdCCaHHE7s0XaqEYmUcfRjLw== X-Received: by 2002:a63:60c:: with SMTP id 12mr5979341pgg.125.1638561347309; Fri, 03 Dec 2021 11:55:47 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cd78:3a5f:d792:6177]) by smtp.gmail.com with ESMTPSA id t3sm4265891pfj.207.2021.12.03.11.55.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 11:55:46 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Dec 2021 04:55:33 +0900 Message-Id: <20211203195539.1574621-2-hiroh@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203195539.1574621-1-hiroh@chromium.org> References: <20211203195539.1574621-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/7] ipa: raspberrypi: Use libcamera Mutex class 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 std::mutex, std::unique_lock and std::condition_variable in src/ipa/raspberrypi with libcamera Mutex, MutexLocker and ConditionVariable, respectively. Signed-off-by: Hirokazu Honda --- src/ipa/raspberrypi/controller/metadata.hpp | 28 +++++++++++-------- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 12 ++++---- src/ipa/raspberrypi/controller/rpi/alsc.hpp | 10 +++---- src/ipa/raspberrypi/controller/rpi/awb.cpp | 10 +++---- src/ipa/raspberrypi/controller/rpi/awb.hpp | 10 +++---- .../raspberrypi/controller/rpi/contrast.cpp | 4 +-- .../raspberrypi/controller/rpi/contrast.hpp | 4 +-- src/ipa/raspberrypi/controller/rpi/lux.cpp | 4 +-- src/ipa/raspberrypi/controller/rpi/lux.hpp | 5 ++-- 9 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp index 51e576cf..ff2e1ae3 100644 --- a/src/ipa/raspberrypi/controller/metadata.hpp +++ b/src/ipa/raspberrypi/controller/metadata.hpp @@ -10,9 +10,10 @@ #include #include -#include #include +#include + namespace RPiController { class Metadata @@ -22,13 +23,13 @@ public: Metadata(Metadata const &other) { - std::scoped_lock other_lock(other.mutex_); + libcamera::MutexLocker other_lock(other.mutex_); data_ = other.data_; } Metadata(Metadata &&other) { - std::scoped_lock other_lock(other.mutex_); + libcamera::MutexLocker other_lock(other.mutex_); data_ = std::move(other.data_); other.data_.clear(); } @@ -36,14 +37,14 @@ public: template void Set(std::string const &tag, T const &value) { - std::scoped_lock lock(mutex_); + libcamera::MutexLocker lock(mutex_); data_[tag] = value; } template int Get(std::string const &tag, T &value) const { - std::scoped_lock lock(mutex_); + libcamera::MutexLocker lock(mutex_); auto it = data_.find(tag); if (it == data_.end()) return -1; @@ -53,20 +54,22 @@ public: void Clear() { - std::scoped_lock lock(mutex_); + libcamera::MutexLocker lock(mutex_); data_.clear(); } Metadata &operator=(Metadata const &other) { - std::scoped_lock lock(mutex_, other.mutex_); + libcamera::MutexLocker lock(mutex_); + libcamera::MutexLocker other_lock(other.mutex_); data_ = other.data_; return *this; } Metadata &operator=(Metadata &&other) { - std::scoped_lock lock(mutex_, other.mutex_); + libcamera::MutexLocker lock(mutex_); + libcamera::MutexLocker other_lock(other.mutex_); data_ = std::move(other.data_); other.data_.clear(); return *this; @@ -74,7 +77,8 @@ public: void Merge(Metadata &other) { - std::scoped_lock lock(mutex_, other.mutex_); + libcamera::MutexLocker lock(mutex_); + libcamera::MutexLocker other_lock(other.mutex_); data_.merge(other.data_); } @@ -99,11 +103,11 @@ public: // Note: use of (lowercase) lock and unlock means you can create scoped // locks with the standard lock classes. // e.g. std::lock_guard lock(metadata) - void lock() { mutex_.lock(); } - void unlock() { mutex_.unlock(); } + void lock() LIBCAMERA_TSA_ACQUIRE(mutex_) { mutex_.lock(); } + void unlock() LIBCAMERA_TSA_RELEASE(mutex_) { mutex_.unlock(); } private: - mutable std::mutex mutex_; + mutable libcamera::Mutex mutex_; std::map data_; }; diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp index be3d1ae4..97a05a30 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -35,7 +35,7 @@ Alsc::Alsc(Controller *controller) Alsc::~Alsc() { { - std::lock_guard lock(mutex_); + MutexLocker lock(mutex_); async_abort_ = true; } async_signal_.notify_one(); @@ -179,7 +179,7 @@ void Alsc::waitForAysncThread() { if (async_started_) { async_started_ = false; - std::unique_lock lock(mutex_); + MutexLocker lock(mutex_); sync_signal_.wait(lock, [&] { return async_finished_; }); @@ -314,7 +314,7 @@ void Alsc::restartAsync(StatisticsPtr &stats, Metadata *image_metadata) frame_phase_ = 0; async_started_ = true; { - std::lock_guard lock(mutex_); + MutexLocker lock(mutex_); async_start_ = true; } async_signal_.notify_one(); @@ -332,7 +332,7 @@ void Alsc::Prepare(Metadata *image_metadata) LOG(RPiAlsc, Debug) << "frame_count " << frame_count_ << " speed " << speed; { - std::unique_lock lock(mutex_); + MutexLocker lock(mutex_); if (async_started_ && async_finished_) fetchAsyncResults(); } @@ -370,7 +370,7 @@ void Alsc::asyncFunc() { while (true) { { - std::unique_lock lock(mutex_); + MutexLocker lock(mutex_); async_signal_.wait(lock, [&] { return async_start_ || async_abort_; }); @@ -380,7 +380,7 @@ void Alsc::asyncFunc() } doAlsc(); { - std::lock_guard lock(mutex_); + MutexLocker lock(mutex_); async_finished_ = true; } sync_signal_.notify_one(); diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.hpp b/src/ipa/raspberrypi/controller/rpi/alsc.hpp index 9616b99e..3f9d6837 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.hpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.hpp @@ -6,10 +6,10 @@ */ #pragma once -#include -#include #include +#include + #include "../algorithm.hpp" #include "../alsc_status.h" @@ -63,11 +63,11 @@ private: double luminance_table_[ALSC_CELLS_X * ALSC_CELLS_Y]; std::thread async_thread_; void asyncFunc(); // asynchronous thread function - std::mutex mutex_; + libcamera::Mutex mutex_; // condvar for async thread to wait on - std::condition_variable async_signal_; + libcamera::ConditionVariable async_signal_; // condvar for synchronous thread to wait on - std::condition_variable sync_signal_; + libcamera::ConditionVariable sync_signal_; // for sync thread to check if async thread finished (requires mutex) bool async_finished_; // for async thread to check if it's been told to run (requires mutex) diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index 5cfd33a3..b4e45abf 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -132,7 +132,7 @@ Awb::Awb(Controller *controller) Awb::~Awb() { { - std::lock_guard lock(mutex_); + MutexLocker lock(mutex_); async_abort_ = true; } async_signal_.notify_one(); @@ -252,7 +252,7 @@ void Awb::restartAsync(StatisticsPtr &stats, double lux) sizeof(async_results_.mode) - 1); async_results_.mode[len] = '\0'; { - std::lock_guard lock(mutex_); + MutexLocker lock(mutex_); async_start_ = true; } async_signal_.notify_one(); @@ -268,7 +268,7 @@ void Awb::Prepare(Metadata *image_metadata) LOG(RPiAwb, Debug) << "frame_count " << frame_count_ << " speed " << speed; { - std::unique_lock lock(mutex_); + MutexLocker lock(mutex_); if (async_started_ && async_finished_) fetchAsyncResults(); } @@ -317,7 +317,7 @@ void Awb::asyncFunc() { while (true) { { - std::unique_lock lock(mutex_); + MutexLocker lock(mutex_); async_signal_.wait(lock, [&] { return async_start_ || async_abort_; }); @@ -327,7 +327,7 @@ void Awb::asyncFunc() } doAwb(); { - std::lock_guard lock(mutex_); + MutexLocker lock(mutex_); async_finished_ = true; } sync_signal_.notify_one(); diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp b/src/ipa/raspberrypi/controller/rpi/awb.hpp index 8af1f27c..30f39c4a 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.hpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.hpp @@ -6,10 +6,10 @@ */ #pragma once -#include -#include #include +#include + #include "../awb_algorithm.hpp" #include "../pwl.hpp" #include "../awb_status.h" @@ -108,11 +108,11 @@ private: AwbConfig config_; std::thread async_thread_; void asyncFunc(); // asynchronous thread function - std::mutex mutex_; + libcamera::Mutex mutex_; // condvar for async thread to wait on - std::condition_variable async_signal_; + libcamera::ConditionVariable async_signal_; // condvar for synchronous thread to wait on - std::condition_variable sync_signal_; + libcamera::ConditionVariable sync_signal_; // for sync thread to check if async thread finished (requires mutex) bool async_finished_; // for async thread to check if it's been told to run (requires mutex) diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp index ae55aad5..6726b4e3 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp @@ -88,7 +88,7 @@ void Contrast::Initialise() void Contrast::Prepare(Metadata *image_metadata) { - std::unique_lock lock(mutex_); + MutexLocker lock(mutex_); image_metadata->Set("contrast.status", status_); } @@ -172,7 +172,7 @@ void Contrast::Process(StatisticsPtr &stats, ContrastStatus status; fill_in_status(status, brightness_, contrast_, gamma_curve); { - std::unique_lock lock(mutex_); + MutexLocker lock(mutex_); status_ = status; } } diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.hpp b/src/ipa/raspberrypi/controller/rpi/contrast.hpp index 85624539..b74e06ab 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.hpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.hpp @@ -6,7 +6,7 @@ */ #pragma once -#include +#include #include "../contrast_algorithm.hpp" #include "../pwl.hpp" @@ -44,7 +44,7 @@ private: double brightness_; double contrast_; ContrastStatus status_; - std::mutex mutex_; + libcamera::Mutex mutex_; }; } // namespace RPiController diff --git a/src/ipa/raspberrypi/controller/rpi/lux.cpp b/src/ipa/raspberrypi/controller/rpi/lux.cpp index f77e9140..7198f64b 100644 --- a/src/ipa/raspberrypi/controller/rpi/lux.cpp +++ b/src/ipa/raspberrypi/controller/rpi/lux.cpp @@ -54,7 +54,7 @@ void Lux::SetCurrentAperture(double aperture) void Lux::Prepare(Metadata *image_metadata) { - std::unique_lock lock(mutex_); + MutexLocker lock(mutex_); image_metadata->Set("lux.status", status_); } @@ -88,7 +88,7 @@ void Lux::Process(StatisticsPtr &stats, Metadata *image_metadata) status.aperture = current_aperture; LOG(RPiLux, Debug) << ": estimated lux " << estimated_lux; { - std::unique_lock lock(mutex_); + MutexLocker lock(mutex_); status_ = status; } // Overwrite the metadata here as well, so that downstream diff --git a/src/ipa/raspberrypi/controller/rpi/lux.hpp b/src/ipa/raspberrypi/controller/rpi/lux.hpp index 3ebd35d1..caa018da 100644 --- a/src/ipa/raspberrypi/controller/rpi/lux.hpp +++ b/src/ipa/raspberrypi/controller/rpi/lux.hpp @@ -6,8 +6,7 @@ */ #pragma once -#include - +#include #include #include "../lux_status.h" @@ -37,7 +36,7 @@ private: double reference_lux_; double current_aperture_; LuxStatus status_; - std::mutex mutex_; + libcamera::Mutex mutex_; }; } // namespace RPiController From patchwork Fri Dec 3 19:55:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 15024 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 47C50BDB13 for ; Fri, 3 Dec 2021 19:55:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F2ECC6084B; Fri, 3 Dec 2021 20:55:52 +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="Di9J04HU"; 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 A98856084B for ; Fri, 3 Dec 2021 20:55:50 +0100 (CET) Received: by mail-pg1-x52b.google.com with SMTP id k4so4088355pgb.8 for ; Fri, 03 Dec 2021 11:55:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RO9Q2ZQfZqnHQ5NMyWgaNj8q6JB0rVcfDQk63o9NYHk=; b=Di9J04HUAGfLV61wyyM1pKTbiI9S0vZHHapGYcgCPPlgFjykZJg8P+GSP0e31mLsfC SUkNb2SdFN9i2M9izfftBST+Z5rGlbbthKjcsGr4RCS0dBQIuKanrEIe/bM7PDWM2X/Z 3DBAlEQDW2KA8Y6GtY5eGo5sfTGkokmYGyqng= 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=RO9Q2ZQfZqnHQ5NMyWgaNj8q6JB0rVcfDQk63o9NYHk=; b=c7hZgvD9vNmB1rcwnoE/zgUNxDJx+2BSLbIPEb2KQlhfJIEfm7F71nSA8G5AbSBUTv cAXiEqFSqu13lD5QtvguWoQLJXa+LfjSWhCnvivFC+LF0ES7oPWt3StNlcar1jjUMA/p M3c2nLanKrKmqtk6eOAqBtWTLL3kTE4XWlCB0TAwTIENVgjpn1Og0Lgm1N10P3d8rGdS TUz6BbVrg7Mhd6y9gWJJMXvtH7DLS4XHIyQV2E+1sZVEquJIsPk68lDa7d8MNGNgoC5O IDzkqVoHp2QvrDIQpPx/MEdtdVz5qv4o9NleEJ71JKF9binpayhIyzqk0HZTq+RQmuod 9lqA== X-Gm-Message-State: AOAM532TvYl9QOC7PXUDr2cFcQbVt7Af8DmYM2/npWzJFFaMF9/Z+rrO 18VuJjmMUfq3F76m/LAPdhB6zSm4OAo7cA== X-Google-Smtp-Source: ABdhPJwgW0cNFlneVTKcmeT81A5vUv7OolqwmqIc0HxfNy4ya0LRN62YuVcfv5EUsw1y3YxgwROdmw== X-Received: by 2002:a63:490c:: with SMTP id w12mr6252535pga.398.1638561348880; Fri, 03 Dec 2021 11:55:48 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cd78:3a5f:d792:6177]) by smtp.gmail.com with ESMTPSA id t3sm4265891pfj.207.2021.12.03.11.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 11:55:48 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Dec 2021 04:55:34 +0900 Message-Id: <20211203195539.1574621-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203195539.1574621-1-hiroh@chromium.org> References: <20211203195539.1574621-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/7] ipa: raspberrypi: alsc: Apply clang thread 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 annotates member functions and variables of Alsc by clang thread safety annotations. Signed-off-by: Hirokazu Honda --- src/ipa/raspberrypi/controller/rpi/alsc.cpp | 4 ++-- src/ipa/raspberrypi/controller/rpi/alsc.hpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp index 97a05a30..8f954106 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp @@ -180,7 +180,7 @@ void Alsc::waitForAysncThread() if (async_started_) { async_started_ = false; MutexLocker lock(mutex_); - sync_signal_.wait(lock, [&] { + sync_signal_.wait(lock, [&]() LIBCAMERA_TSA_REQUIRES(mutex_) { return async_finished_; }); async_finished_ = false; @@ -371,7 +371,7 @@ void Alsc::asyncFunc() while (true) { { MutexLocker lock(mutex_); - async_signal_.wait(lock, [&] { + async_signal_.wait(lock, [&]() LIBCAMERA_TSA_REQUIRES(mutex_) { return async_start_ || async_abort_; }); async_start_ = false; diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.hpp b/src/ipa/raspberrypi/controller/rpi/alsc.hpp index 3f9d6837..f1f2aa0d 100644 --- a/src/ipa/raspberrypi/controller/rpi/alsc.hpp +++ b/src/ipa/raspberrypi/controller/rpi/alsc.hpp @@ -69,11 +69,11 @@ private: // condvar for synchronous thread to wait on libcamera::ConditionVariable sync_signal_; // for sync thread to check if async thread finished (requires mutex) - bool async_finished_; + bool async_finished_ LIBCAMERA_TSA_GUARDED_BY(mutex_); // for async thread to check if it's been told to run (requires mutex) - bool async_start_; + bool async_start_ LIBCAMERA_TSA_GUARDED_BY(mutex_); // for async thread to check if it's been told to quit (requires mutex) - bool async_abort_; + bool async_abort_ LIBCAMERA_TSA_GUARDED_BY(mutex_); // The following are only for the synchronous thread to use: // for sync thread to note its has asked async thread to run @@ -91,7 +91,7 @@ private: // thread can set/reset them if the async thread is known to be idle: void restartAsync(StatisticsPtr &stats, Metadata *image_metadata); // copy out the results from the async thread so that it can be restarted - void fetchAsyncResults(); + void fetchAsyncResults() LIBCAMERA_TSA_REQUIRES(mutex_); double ct_; bcm2835_isp_stats_region statistics_[ALSC_CELLS_Y * ALSC_CELLS_X]; double async_results_[3][ALSC_CELLS_Y][ALSC_CELLS_X]; From patchwork Fri Dec 3 19:55:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 15025 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 096AAC3250 for ; Fri, 3 Dec 2021 19:55:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A768760822; Fri, 3 Dec 2021 20:55:53 +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="KKVmjxnK"; 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 1F1FB6084A for ; Fri, 3 Dec 2021 20:55:52 +0100 (CET) Received: by mail-pg1-x52b.google.com with SMTP id f125so4176229pgc.0 for ; Fri, 03 Dec 2021 11:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=whlrVtDSaOPOhU9NB9oN0LR43VRxqEnviBCM+Ekagoo=; b=KKVmjxnKvMb71EWA9M+P+TjtX5nDqB2ttT+DTMV7sXwiDHTa/0huKz4daRbJfgwTE3 Io6vzxeodHsvcecj42Nmi3yBK5DABi1hbdD/MFQ1I2RJRlo9v105ZjrP9rJn0/rtiUOQ EtrTgHFH7v3TULr2CZ/kUf2blAVzNms6nASlg= 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=whlrVtDSaOPOhU9NB9oN0LR43VRxqEnviBCM+Ekagoo=; b=QBq1P2cYJ8raQACPlo0pWWzBT3BM5UgXReNYRZlKBXya5FIQZTKaHjRcQeCFRNs0CX EFpDFDFbmmVZwhH0BlCbbh/Er8mglsMHUQ7CXUgTWC05dcViPDDUjhT3s3UV8lLJABbL Ucj5G+1kCDg8k6hC+tOdN/kL4iIkhDDO8yCPtros+iU2lSnAoZ2YQhEyTjy4fOqbUSHX WAO2cuBJb8q29jnCsvLbqcdquDspCoiyMzaqf+LLPCwqNC9joKnMRco/RGTShfz+nxO+ sAE6PEKk+FLGv0sp4SM7p7QKdxLlohfiBLuh/WolpVby2LIAkk0NJkoMRFh9KXi8xkTm psvA== X-Gm-Message-State: AOAM533HCSZm7a7xL8DvDnhkINRMs9JXvRgG+gZOEqD4yVdz9lzQJtu2 027ZmR6a1EgVHWxu/zsZr78nOk56jb8q1A== X-Google-Smtp-Source: ABdhPJywWFpHimxRyk3QqrEwt2+XuGWSHfoalPY1iUF3bgYJUHq+YaWvEzFwpFbPQue2lEuCw77MgA== X-Received: by 2002:a05:6a00:1945:b0:44c:a955:35ea with SMTP id s5-20020a056a00194500b0044ca95535eamr20891648pfk.85.1638561350481; Fri, 03 Dec 2021 11:55:50 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cd78:3a5f:d792:6177]) by smtp.gmail.com with ESMTPSA id t3sm4265891pfj.207.2021.12.03.11.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 11:55:50 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Dec 2021 04:55:35 +0900 Message-Id: <20211203195539.1574621-4-hiroh@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203195539.1574621-1-hiroh@chromium.org> References: <20211203195539.1574621-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/7] ipa: raspberrypi: awb: Apply clang thread 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 annotates member functions and variables of Awb by clang thread safety annotations. Signed-off-by: Hirokazu Honda --- src/ipa/raspberrypi/controller/rpi/awb.cpp | 2 +- src/ipa/raspberrypi/controller/rpi/awb.hpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index b4e45abf..ac253d6b 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -318,7 +318,7 @@ void Awb::asyncFunc() while (true) { { MutexLocker lock(mutex_); - async_signal_.wait(lock, [&] { + async_signal_.wait(lock, [&]() LIBCAMERA_TSA_REQUIRES(mutex_) { return async_start_ || async_abort_; }); async_start_ = false; diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp b/src/ipa/raspberrypi/controller/rpi/awb.hpp index 30f39c4a..413e0439 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.hpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.hpp @@ -114,11 +114,11 @@ private: // condvar for synchronous thread to wait on libcamera::ConditionVariable sync_signal_; // for sync thread to check if async thread finished (requires mutex) - bool async_finished_; + bool async_finished_ LIBCAMERA_TSA_GUARDED_BY(mutex_); // for async thread to check if it's been told to run (requires mutex) - bool async_start_; + bool async_start_ LIBCAMERA_TSA_GUARDED_BY(mutex_); // for async thread to check if it's been told to quit (requires mutex) - bool async_abort_; + bool async_abort_ LIBCAMERA_TSA_GUARDED_BY(mutex_); // The following are only for the synchronous thread to use: // for sync thread to note its has asked async thread to run @@ -133,7 +133,7 @@ private: // thread can set/reset them if the async thread is known to be idle: void restartAsync(StatisticsPtr &stats, double lux); // copy out the results from the async thread so that it can be restarted - void fetchAsyncResults(); + void fetchAsyncResults() LIBCAMERA_TSA_REQUIRES(mutex_); StatisticsPtr statistics_; AwbMode *mode_; double lux_; From patchwork Fri Dec 3 19:55:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 15026 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 E1717C3251 for ; Fri, 3 Dec 2021 19:55:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 362BB60862; Fri, 3 Dec 2021 20:55:55 +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="dhGJ8cFa"; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BD2746084A for ; Fri, 3 Dec 2021 20:55:53 +0100 (CET) Received: by mail-pl1-x629.google.com with SMTP id u17so2823095plg.9 for ; Fri, 03 Dec 2021 11:55:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lsc3g63mrM05MWhhAddTRLejLH9PImlNw/DUff7hN4s=; b=dhGJ8cFakBdzzgePQYtplyKCXK0kHbKUtgk7TwQ1BfmNLYmsRPbKHPVJ4nATOMOi4J at2yV8L6b/9oz1FM8DF7kEGcS1VZElmeciSKC8X4lhSGNN/IFjaKJ9M4Xr2Wj/MsZxDT Yk/DbMJKqeGKrP+IA4IKwSdCwb85+qtARdEGw= 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=Lsc3g63mrM05MWhhAddTRLejLH9PImlNw/DUff7hN4s=; b=SkhVU0N3PNgUGLDf0ca8sUYXSXwFgqo4OlKwTI//Vh2cGMr9LBQaMIbc51uhlyEFJl vTvuPQLy+6Z8hNDqn7Ob02CQkYibZQTJB1Cj7B5ykqPbm5QWGEsxguBn7+LoQ4U4ZQbG LOMd15RMIkjwHilXXko92eMEcWm39DqE3HPi/7BtPLzvo7WE71gSoCLutobLa8Nj0R2G K0VVJMKgurF53rZ63XU6sSmNFp5rla3uo9ASXTOUiPR+RP3G6/aNwicQr1iUF22D+653 W2JCGNddhc4+LOAzsS/xJLtoHWFsr7CjAEp9MBlQRg3QaeOgCIn6fUSicSHGADvkGuno VnzA== X-Gm-Message-State: AOAM533T7EDmrVOyTnVBqiYBiBn6qIGVZ9LcrSyIwhFs3oBkIumI4SWZ HTxYS7yLTUffTWOBCjyvPAaJsKcplgkDFg== X-Google-Smtp-Source: ABdhPJwxJcQIXk4I98l+qRzxgxIyUbqwuIdAKLTZUAPLRi7dHYMNWO13DzNoFgzJuplgGbj8tRgbAg== X-Received: by 2002:a17:90b:2504:: with SMTP id ns4mr16065464pjb.175.1638561352058; Fri, 03 Dec 2021 11:55:52 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cd78:3a5f:d792:6177]) by smtp.gmail.com with ESMTPSA id t3sm4265891pfj.207.2021.12.03.11.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 11:55:51 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Dec 2021 04:55:36 +0900 Message-Id: <20211203195539.1574621-5-hiroh@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203195539.1574621-1-hiroh@chromium.org> References: <20211203195539.1574621-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/7] ipa: raspberrypi: lux: Apply clang thread 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 annotates member variable of Lux by clang thread safety annotations. Signed-off-by: Hirokazu Honda --- src/ipa/raspberrypi/controller/rpi/lux.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipa/raspberrypi/controller/rpi/lux.hpp b/src/ipa/raspberrypi/controller/rpi/lux.hpp index caa018da..04b82c4d 100644 --- a/src/ipa/raspberrypi/controller/rpi/lux.hpp +++ b/src/ipa/raspberrypi/controller/rpi/lux.hpp @@ -35,7 +35,7 @@ private: double reference_Y_; // out of 65536 double reference_lux_; double current_aperture_; - LuxStatus status_; + LuxStatus status_ LIBCAMERA_TSA_GUARDED_BY(mutex_); libcamera::Mutex mutex_; }; From patchwork Fri Dec 3 19:55: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: 15027 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 DBAB4BDB13 for ; Fri, 3 Dec 2021 19:55:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8DBCA6084A; Fri, 3 Dec 2021 20:55:56 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="gDgFNetY"; dkim-atps=neutral Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A33260872 for ; Fri, 3 Dec 2021 20:55:55 +0100 (CET) Received: by mail-pf1-x431.google.com with SMTP id o4so3816094pfp.13 for ; Fri, 03 Dec 2021 11:55:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OApDSpAVIwnWpGVH4gzTtwnVfskfBHadlfdPlNwphF8=; b=gDgFNetYNWjOObkkyh1LJggT46hGDvdQLM0dE01PXpq6e3Z0jrDm18Kxzv88r/WkVh enaDlS0Oj9is65WoblO3oavUx5eHUi/97LDK6GF4Riv90DEhKETA2Q6ahtsxWfmZEY+O Tzh43St9z9JcadBjw5W0wkd9mBk2J7gT/lj/M= 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=OApDSpAVIwnWpGVH4gzTtwnVfskfBHadlfdPlNwphF8=; b=R4XsFZQcGL0e48zSK1/f7YP3nIy+ltMyfmYrHfoyzvi65NL+JoFBOJLrvDHZs+reF/ KPPlPr9W4dwpw+Mfk/EG6EcVgrJuAbKIMCGvHMtwW0RYEuvTPgpDsBhEGeAMcWtdbmGL +nuPUPlY50ddtiBHT9BY7w9THwV8Uj5ayfvdpEbkM4xl29Q3zCffglhRcTh7JAPvDVmH O2jcfPlgPhzsRIrQ09GKZ/rz5vzRoBvbbXYVmHqTbvMa6sCL7VXA5TZovK3XW8hTmcOH tW71jjJ/N55RuVkiMVBziBXTt1IGlpq4cDtCOzfp3eDmObb26Sq/ezJDZz2060d2iMCe Mj6g== X-Gm-Message-State: AOAM533oRAhEZD3rLwD9EInZ+up/Xi/EE7YVG/+rhFtFb9Fld/LmMjxp 7VJWV5rA4NLEqN/ksz/sYwt7apGhAkthKQ== X-Google-Smtp-Source: ABdhPJyTYtWZWmIiMXNmpfvgwUgH7D+3jauq3jq0nOZN069OPd2RDWdp7jJf4M7SoYuPTcvHBVb8DQ== X-Received: by 2002:a63:5906:: with SMTP id n6mr5936883pgb.563.1638561353637; Fri, 03 Dec 2021 11:55:53 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cd78:3a5f:d792:6177]) by smtp.gmail.com with ESMTPSA id t3sm4265891pfj.207.2021.12.03.11.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 11:55:53 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Dec 2021 04:55:37 +0900 Message-Id: <20211203195539.1574621-6-hiroh@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203195539.1574621-1-hiroh@chromium.org> References: <20211203195539.1574621-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/7] ipa: raspberrypi: Contrast: Protect status_ access in Initialise() 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 bug that status_ is accessed without acquiring mutex_ in Contrast::Initialise(). Signed-off-by: Hirokazu Honda --- src/ipa/raspberrypi/controller/rpi/contrast.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp index 6726b4e3..be61353a 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp @@ -83,6 +83,7 @@ void Contrast::Initialise() { // Fill in some default values as Prepare will run before Process gets // called. + MutexLocker locker(mutex_); fill_in_status(status_, brightness_, contrast_, config_.gamma_curve); } From patchwork Fri Dec 3 19:55: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: 15028 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 4BE2DC3250 for ; Fri, 3 Dec 2021 19:55:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0657A60839; Fri, 3 Dec 2021 20:55: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="jrm5ii5u"; dkim-atps=neutral Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1697160725 for ; Fri, 3 Dec 2021 20:55:57 +0100 (CET) Received: by mail-pf1-x42b.google.com with SMTP id 8so3858958pfo.4 for ; Fri, 03 Dec 2021 11:55: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=tJkhOA5WSO7+mLX2TViwx3P8ZdhCcSweweK0r5dpP3I=; b=jrm5ii5uTiyUDWsHa6DRnNvS/Mw3IFOEv0dlL0a6f74NtBWbsralbSlu4LyMX50W1t ps4EQvPOzrfqEXDe3XHolQKG4AEZLzkoRdcm5HiyELgRrQUa3mIxQDxpJlFvXa6KqjL4 6RHzRR+U5NzeKGur+KnwjzBdpp6vfX+XdexlI= 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=tJkhOA5WSO7+mLX2TViwx3P8ZdhCcSweweK0r5dpP3I=; b=YlsMsyksu5IUC6w5BRN6wznmwq0kFPBxzhRgMf2vWdN2Pb8IZSZR/SPseXXcuTh4kV rQWw3uRJtEoHJtzOaaik76kMWSfXEuHT7J4I7b9qBt2fqiGCWyE6ApEFaW0xZDZIRf6R J4DKtAn7EDzEeTiR3407rJgqEHa/At02RYdLnSRrSHcwDiS5c7nFJD46ai3S7mgEWvQy Vmkv9qaRKP5QYPKT0ddQSVd/3pBJpypQBm8zBXWptUvTQp0lQ30Wf1khSsORmLFKnLhX HC3DOu91ttgRRooxpjEZMU5p3P8dIQIWpbYc7TkfOMyeIp3bsVUzMCkyC7QBcZ88RoaE D4Iw== X-Gm-Message-State: AOAM530UWrVBOFrpif/PVRrWUjswBhIs64CAKRQbuNPfcMPT5mCkxzTW 4XeuCMORXjYjY58xt4Vha1axdSgDPbQYyA== X-Google-Smtp-Source: ABdhPJz0sYYMASG6BAjp8cKw7v5oyaRNtxYrGTar0hW9+40bhp9rlyKI6Afb2+6eVdnbS7/IhDAfbQ== X-Received: by 2002:a05:6a00:13a4:b0:49f:add2:3c83 with SMTP id t36-20020a056a0013a400b0049fadd23c83mr20683226pfg.28.1638561355283; Fri, 03 Dec 2021 11:55:55 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cd78:3a5f:d792:6177]) by smtp.gmail.com with ESMTPSA id t3sm4265891pfj.207.2021.12.03.11.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 11:55:54 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Dec 2021 04:55:38 +0900 Message-Id: <20211203195539.1574621-7-hiroh@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203195539.1574621-1-hiroh@chromium.org> References: <20211203195539.1574621-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/7] ipa: raspberrypi: contrast: Apply clang thread 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 annotates member variable of Contrast by clang thread safety annotations. Signed-off-by: Hirokazu Honda --- src/ipa/raspberrypi/controller/rpi/contrast.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.hpp b/src/ipa/raspberrypi/controller/rpi/contrast.hpp index b74e06ab..7eb675ff 100644 --- a/src/ipa/raspberrypi/controller/rpi/contrast.hpp +++ b/src/ipa/raspberrypi/controller/rpi/contrast.hpp @@ -43,7 +43,7 @@ private: ContrastConfig config_; double brightness_; double contrast_; - ContrastStatus status_; + ContrastStatus status_ LIBCAMERA_TSA_GUARDED_BY(mutex_); libcamera::Mutex mutex_; }; From patchwork Fri Dec 3 19:55: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: 15029 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 A2C7CBDB13 for ; Fri, 3 Dec 2021 19:56:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 59FB26084A; Fri, 3 Dec 2021 20:56:00 +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="ocLvvMZA"; dkim-atps=neutral Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E1B4607DE for ; Fri, 3 Dec 2021 20:55:58 +0100 (CET) Received: by mail-pg1-x532.google.com with SMTP id m15so4080771pgu.11 for ; Fri, 03 Dec 2021 11:55:58 -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=ghAeGg8cM3/5PK0Jss5JhV2ixIi408VmPvgJ1SVYROA=; b=ocLvvMZAgXXjFD1GhR4asgIUMyulS82ldyptdahxuh/MwM7BjQRZVAEW7VDd7k3Iqi dMdlEtg9VBxY2MaTeJBZD4JzlpgmfOHJH56PrVQNZ4rvt7hQOTIc4IQxdm8oEL8WPxXK oW0B+xuo894QkcR/igOll9wdT/jrRYx9BKkgU= 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=ghAeGg8cM3/5PK0Jss5JhV2ixIi408VmPvgJ1SVYROA=; b=jxFTBs4r3eOYyof7Ux2+3a1ZPjy9uft5bt6owna3/IpkwzP5QnmK47liTYY156CcB+ c+UwxrVpVz7ySJbn3dthtV1tkobePFVVFbalMcJumbdEOJcYdFmE3YjJmkFhB0u4DpZl F+9Lfpvq830iHmVWkXuUqGeozW9kMCV6n5RDc5CJjTbWFBFyKJqiQYLMljFdVPepwYry 87nopFUVxZdzM97n+XG0LyPR/LFjSrtdXARMxjstXUyHfQlmDJzVU5D9fNPGJ1XX/066 6F3YevEr2PB0WiK25QLJAV1eEnlbfMI+eEylEVMCAtFFLtzqzTmu6DZIe2KwyE4wAXhI wquA== X-Gm-Message-State: AOAM5320HL2yq62/qlHJaYvcApMeJyLv8KnwV3FmoFua/qVjA1ZKaudm cwUEw4CO3ZK/1w7thdYloxyU52wfTgnThA== X-Google-Smtp-Source: ABdhPJzifGFsJsoUIrT+UnWZdLpjhc/QUae0zzSQ0758kooSF041NWtVEOA3GJ0vBy9KL2RLK0bMYg== X-Received: by 2002:a63:1b02:: with SMTP id b2mr5961242pgb.263.1638561356863; Fri, 03 Dec 2021 11:55:56 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:cd78:3a5f:d792:6177]) by smtp.gmail.com with ESMTPSA id t3sm4265891pfj.207.2021.12.03.11.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 11:55:56 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Dec 2021 04:55:39 +0900 Message-Id: <20211203195539.1574621-8-hiroh@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211203195539.1574621-1-hiroh@chromium.org> References: <20211203195539.1574621-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 7/7] ipa: raspberrypi: metadata: Apply clang thread safety annotation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This annotates member variable and functions of Metadata by clang thread safety annotations. Metadata has lock and unlock functions so that it can be used by std::unique_lock. I replace them by a function of returning Mutex reference. It eases to annotate clang thread safety annotations. Signed-off-by: Hirokazu Honda --- src/ipa/raspberrypi/controller/metadata.hpp | 22 ++++++++++++--------- src/ipa/raspberrypi/controller/rpi/agc.cpp | 3 ++- src/ipa/raspberrypi/controller/rpi/ccm.cpp | 3 ++- src/ipa/raspberrypi/raspberrypi.cpp | 4 ++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp index ff2e1ae3..65dad8fb 100644 --- a/src/ipa/raspberrypi/controller/metadata.hpp +++ b/src/ipa/raspberrypi/controller/metadata.hpp @@ -36,6 +36,7 @@ public: template void Set(std::string const &tag, T const &value) + LIBCAMERA_TSA_EXCLUDES(mutex_) { libcamera::MutexLocker lock(mutex_); data_[tag] = value; @@ -43,6 +44,7 @@ public: template int Get(std::string const &tag, T &value) const + LIBCAMERA_TSA_EXCLUDES(mutex_) { libcamera::MutexLocker lock(mutex_); auto it = data_.find(tag); @@ -52,13 +54,14 @@ public: return 0; } - void Clear() + void Clear() LIBCAMERA_TSA_EXCLUDES(mutex_) { libcamera::MutexLocker lock(mutex_); data_.clear(); } Metadata &operator=(Metadata const &other) + LIBCAMERA_TSA_EXCLUDES(mutex_, other.mutex_) { libcamera::MutexLocker lock(mutex_); libcamera::MutexLocker other_lock(other.mutex_); @@ -67,6 +70,7 @@ public: } Metadata &operator=(Metadata &&other) + LIBCAMERA_TSA_EXCLUDES(mutex_, other.mutex_) { libcamera::MutexLocker lock(mutex_); libcamera::MutexLocker other_lock(other.mutex_); @@ -75,7 +79,7 @@ public: return *this; } - void Merge(Metadata &other) + void Merge(Metadata &other) LIBCAMERA_TSA_EXCLUDES(mutex_, other.mutex_) { libcamera::MutexLocker lock(mutex_); libcamera::MutexLocker other_lock(other.mutex_); @@ -83,7 +87,7 @@ public: } template - T *GetLocked(std::string const &tag) + T *GetLocked(std::string const &tag) LIBCAMERA_TSA_REQUIRES(mutex_) { // This allows in-place access to the Metadata contents, // for which you should be holding the lock. @@ -95,20 +99,20 @@ public: template void SetLocked(std::string const &tag, T const &value) + LIBCAMERA_TSA_REQUIRES(mutex_) { // Use this only if you're holding the lock yourself. data_[tag] = value; } - // Note: use of (lowercase) lock and unlock means you can create scoped - // locks with the standard lock classes. - // e.g. std::lock_guard lock(metadata) - void lock() LIBCAMERA_TSA_ACQUIRE(mutex_) { mutex_.lock(); } - void unlock() LIBCAMERA_TSA_RELEASE(mutex_) { mutex_.unlock(); } + libcamera::Mutex &mutex() LIBCAMERA_TSA_RETURN_CAPABILITY(mutex_) + { + return mutex_; + } private: mutable libcamera::Mutex mutex_; - std::map data_; + std::map data_ LIBCAMERA_TSA_GUARDED_BY(mutex_); }; } // namespace RPiController diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index f6a9cb0a..870909af 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -485,7 +485,8 @@ void Agc::housekeepConfig() void Agc::fetchCurrentExposure(Metadata *image_metadata) { - std::unique_lock lock(*image_metadata); + MutexLocker locker(image_metadata->mutex()); + DeviceStatus *device_status = image_metadata->GetLocked("device.status"); if (!device_status) diff --git a/src/ipa/raspberrypi/controller/rpi/ccm.cpp b/src/ipa/raspberrypi/controller/rpi/ccm.cpp index 821a4c7c..989b15dd 100644 --- a/src/ipa/raspberrypi/controller/rpi/ccm.cpp +++ b/src/ipa/raspberrypi/controller/rpi/ccm.cpp @@ -85,6 +85,7 @@ void Ccm::Initialise() {} template static bool get_locked(Metadata *metadata, std::string const &tag, T &value) + LIBCAMERA_TSA_REQUIRES(metadata->mutex()) { T *ptr = metadata->GetLocked(tag); if (ptr == nullptr) @@ -128,7 +129,7 @@ void Ccm::Prepare(Metadata *image_metadata) lux.lux = 400; // in case no metadata { // grab mutex just once to get everything - std::lock_guard lock(*image_metadata); + MutexLocker locker(image_metadata->mutex()); awb_ok = get_locked(image_metadata, "awb.status", awb); lux_ok = get_locked(image_metadata, "lux.status", lux); } diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp index fed82e22..b8d22dec 100644 --- a/src/ipa/raspberrypi/raspberrypi.cpp +++ b/src/ipa/raspberrypi/raspberrypi.cpp @@ -465,7 +465,7 @@ void IPARPi::signalIspPrepare(const ipa::RPi::ISPConfig &data) void IPARPi::reportMetadata() { - std::unique_lock lock(rpiMetadata_); + MutexLocker locker(rpiMetadata_.mutex()); /* * Certain information about the current frame and how it will be @@ -977,7 +977,7 @@ void IPARPi::prepareISP(const ipa::RPi::ISPConfig &data) controller_.Prepare(&rpiMetadata_); /* Lock the metadata buffer to avoid constant locks/unlocks. */ - std::unique_lock lock(rpiMetadata_); + MutexLocker locker(rpiMetadata_.mutex()); AwbStatus *awbStatus = rpiMetadata_.GetLocked("awb.status"); if (awbStatus)