{"id":15029,"url":"https://patchwork.libcamera.org/api/patches/15029/?format=json","web_url":"https://patchwork.libcamera.org/patch/15029/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211203195539.1574621-8-hiroh@chromium.org>","date":"2021-12-03T19:55:39","name":"[libcamera-devel,7/7] ipa: raspberrypi: metadata: Apply clang thread safety annotation","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"2e1b5dfa150f579990438b304e66c455ca6f3651","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15029/mbox/","series":[{"id":2814,"url":"https://patchwork.libcamera.org/api/series/2814/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2814","date":"2021-12-03T19:55:32","name":"Apply clang thread safety annotations to raspberrypi","version":1,"mbox":"https://patchwork.libcamera.org/series/2814/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15029/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15029/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A2C7CBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Dec 2021 19:56:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 59FB26084A;\n\tFri,  3 Dec 2021 20:56:00 +0100 (CET)","from mail-pg1-x532.google.com (mail-pg1-x532.google.com\n\t[IPv6:2607:f8b0:4864:20::532])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E1B4607DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Dec 2021 20:55:58 +0100 (CET)","by mail-pg1-x532.google.com with SMTP id m15so4080771pgu.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 03 Dec 2021 11:55:58 -0800 (PST)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:cd78:3a5f:d792:6177])\n\tby smtp.gmail.com with ESMTPSA id\n\tt3sm4265891pfj.207.2021.12.03.11.55.55\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 03 Dec 2021 11:55:56 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"ocLvvMZA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=ghAeGg8cM3/5PK0Jss5JhV2ixIi408VmPvgJ1SVYROA=;\n\tb=ocLvvMZAgXXjFD1GhR4asgIUMyulS82ldyptdahxuh/MwM7BjQRZVAEW7VDd7k3Iqi\n\tdMdlEtg9VBxY2MaTeJBZD4JzlpgmfOHJH56PrVQNZ4rvt7hQOTIc4IQxdm8oEL8WPxXK\n\toW0B+xuo894QkcR/igOll9wdT/jrRYx9BKkgU=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=ghAeGg8cM3/5PK0Jss5JhV2ixIi408VmPvgJ1SVYROA=;\n\tb=jxFTBs4r3eOYyof7Ux2+3a1ZPjy9uft5bt6owna3/IpkwzP5QnmK47liTYY156CcB+\n\tc+UwxrVpVz7ySJbn3dthtV1tkobePFVVFbalMcJumbdEOJcYdFmE3YjJmkFhB0u4DpZl\n\tF+9Lfpvq830iHmVWkXuUqGeozW9kMCV6n5RDc5CJjTbWFBFyKJqiQYLMljFdVPepwYry\n\t87nopFUVxZdzM97n+XG0LyPR/LFjSrtdXARMxjstXUyHfQlmDJzVU5D9fNPGJ1XX/066\n\t6F3YevEr2PB0WiK25QLJAV1eEnlbfMI+eEylEVMCAtFFLtzqzTmu6DZIe2KwyE4wAXhI\n\twquA==","X-Gm-Message-State":"AOAM5320HL2yq62/qlHJaYvcApMeJyLv8KnwV3FmoFua/qVjA1ZKaudm\n\tcwUEw4CO3ZK/1w7thdYloxyU52wfTgnThA==","X-Google-Smtp-Source":"ABdhPJzifGFsJsoUIrT+UnWZdLpjhc/QUae0zzSQ0758kooSF041NWtVEOA3GJ0vBy9KL2RLK0bMYg==","X-Received":"by 2002:a63:1b02:: with SMTP id b2mr5961242pgb.263.1638561356863;\n\tFri, 03 Dec 2021 11:55:56 -0800 (PST)","From":"Hirokazu Honda <hiroh@chromium.org>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 7/7] ipa: raspberrypi: metadata: Apply\n\tclang thread safety annotation","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"This annotates member variable and functions of Metadata by clang\nthread safety annotations. Metadata has lock and unlock functions\nso that it can be used by std::unique_lock. I replace them by a\nfunction of returning Mutex reference. It eases to annotate clang\nthread safety annotations.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/ipa/raspberrypi/controller/metadata.hpp | 22 ++++++++++++---------\n src/ipa/raspberrypi/controller/rpi/agc.cpp  |  3 ++-\n src/ipa/raspberrypi/controller/rpi/ccm.cpp  |  3 ++-\n src/ipa/raspberrypi/raspberrypi.cpp         |  4 ++--\n 4 files changed, 19 insertions(+), 13 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/controller/metadata.hpp b/src/ipa/raspberrypi/controller/metadata.hpp\nindex ff2e1ae3..65dad8fb 100644\n--- a/src/ipa/raspberrypi/controller/metadata.hpp\n+++ b/src/ipa/raspberrypi/controller/metadata.hpp\n@@ -36,6 +36,7 @@ public:\n \n \ttemplate<typename T>\n \tvoid Set(std::string const &tag, T const &value)\n+\t\tLIBCAMERA_TSA_EXCLUDES(mutex_)\n \t{\n \t\tlibcamera::MutexLocker lock(mutex_);\n \t\tdata_[tag] = value;\n@@ -43,6 +44,7 @@ public:\n \n \ttemplate<typename T>\n \tint Get(std::string const &tag, T &value) const\n+\t\tLIBCAMERA_TSA_EXCLUDES(mutex_)\n \t{\n \t\tlibcamera::MutexLocker lock(mutex_);\n \t\tauto it = data_.find(tag);\n@@ -52,13 +54,14 @@ public:\n \t\treturn 0;\n \t}\n \n-\tvoid Clear()\n+\tvoid Clear() LIBCAMERA_TSA_EXCLUDES(mutex_)\n \t{\n \t\tlibcamera::MutexLocker lock(mutex_);\n \t\tdata_.clear();\n \t}\n \n \tMetadata &operator=(Metadata const &other)\n+\t\tLIBCAMERA_TSA_EXCLUDES(mutex_, other.mutex_)\n \t{\n \t\tlibcamera::MutexLocker lock(mutex_);\n \t\tlibcamera::MutexLocker other_lock(other.mutex_);\n@@ -67,6 +70,7 @@ public:\n \t}\n \n \tMetadata &operator=(Metadata &&other)\n+\t\tLIBCAMERA_TSA_EXCLUDES(mutex_, other.mutex_)\n \t{\n \t\tlibcamera::MutexLocker lock(mutex_);\n \t\tlibcamera::MutexLocker other_lock(other.mutex_);\n@@ -75,7 +79,7 @@ public:\n \t\treturn *this;\n \t}\n \n-\tvoid Merge(Metadata &other)\n+\tvoid Merge(Metadata &other) LIBCAMERA_TSA_EXCLUDES(mutex_, other.mutex_)\n \t{\n \t\tlibcamera::MutexLocker lock(mutex_);\n \t\tlibcamera::MutexLocker other_lock(other.mutex_);\n@@ -83,7 +87,7 @@ public:\n \t}\n \n \ttemplate<typename T>\n-\tT *GetLocked(std::string const &tag)\n+\tT *GetLocked(std::string const &tag) LIBCAMERA_TSA_REQUIRES(mutex_)\n \t{\n \t\t// This allows in-place access to the Metadata contents,\n \t\t// for which you should be holding the lock.\n@@ -95,20 +99,20 @@ public:\n \n \ttemplate<typename T>\n \tvoid SetLocked(std::string const &tag, T const &value)\n+\t\tLIBCAMERA_TSA_REQUIRES(mutex_)\n \t{\n \t\t// Use this only if you're holding the lock yourself.\n \t\tdata_[tag] = value;\n \t}\n \n-\t// Note: use of (lowercase) lock and unlock means you can create scoped\n-\t// locks with the standard lock classes.\n-\t// e.g. std::lock_guard<RPiController::Metadata> lock(metadata)\n-\tvoid lock() LIBCAMERA_TSA_ACQUIRE(mutex_) { mutex_.lock(); }\n-\tvoid unlock() LIBCAMERA_TSA_RELEASE(mutex_) { mutex_.unlock(); }\n+\tlibcamera::Mutex &mutex() LIBCAMERA_TSA_RETURN_CAPABILITY(mutex_)\n+\t{\n+\t\treturn mutex_;\n+\t}\n \n private:\n \tmutable libcamera::Mutex mutex_;\n-\tstd::map<std::string, std::any> data_;\n+\tstd::map<std::string, std::any> data_ LIBCAMERA_TSA_GUARDED_BY(mutex_);\n };\n \n } // namespace RPiController\ndiff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex f6a9cb0a..870909af 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -485,7 +485,8 @@ void Agc::housekeepConfig()\n \n void Agc::fetchCurrentExposure(Metadata *image_metadata)\n {\n-\tstd::unique_lock<Metadata> lock(*image_metadata);\n+\tMutexLocker locker(image_metadata->mutex());\n+\n \tDeviceStatus *device_status =\n \t\timage_metadata->GetLocked<DeviceStatus>(\"device.status\");\n \tif (!device_status)\ndiff --git a/src/ipa/raspberrypi/controller/rpi/ccm.cpp b/src/ipa/raspberrypi/controller/rpi/ccm.cpp\nindex 821a4c7c..989b15dd 100644\n--- a/src/ipa/raspberrypi/controller/rpi/ccm.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/ccm.cpp\n@@ -85,6 +85,7 @@ void Ccm::Initialise() {}\n \n template<typename T>\n static bool get_locked(Metadata *metadata, std::string const &tag, T &value)\n+\tLIBCAMERA_TSA_REQUIRES(metadata->mutex())\n {\n \tT *ptr = metadata->GetLocked<T>(tag);\n \tif (ptr == nullptr)\n@@ -128,7 +129,7 @@ void Ccm::Prepare(Metadata *image_metadata)\n \tlux.lux = 400; // in case no metadata\n \t{\n \t\t// grab mutex just once to get everything\n-\t\tstd::lock_guard<Metadata> lock(*image_metadata);\n+\t\tMutexLocker locker(image_metadata->mutex());\n \t\tawb_ok = get_locked(image_metadata, \"awb.status\", awb);\n \t\tlux_ok = get_locked(image_metadata, \"lux.status\", lux);\n \t}\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex fed82e22..b8d22dec 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -465,7 +465,7 @@ void IPARPi::signalIspPrepare(const ipa::RPi::ISPConfig &data)\n \n void IPARPi::reportMetadata()\n {\n-\tstd::unique_lock<RPiController::Metadata> lock(rpiMetadata_);\n+\tMutexLocker locker(rpiMetadata_.mutex());\n \n \t/*\n \t * Certain information about the current frame and how it will be\n@@ -977,7 +977,7 @@ void IPARPi::prepareISP(const ipa::RPi::ISPConfig &data)\n \tcontroller_.Prepare(&rpiMetadata_);\n \n \t/* Lock the metadata buffer to avoid constant locks/unlocks. */\n-\tstd::unique_lock<RPiController::Metadata> lock(rpiMetadata_);\n+\tMutexLocker locker(rpiMetadata_.mutex());\n \n \tAwbStatus *awbStatus = rpiMetadata_.GetLocked<AwbStatus>(\"awb.status\");\n \tif (awbStatus)\n","prefixes":["libcamera-devel","7/7"]}