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