{"id":14501,"url":"https://patchwork.libcamera.org/api/patches/14501/?format=json","web_url":"https://patchwork.libcamera.org/patch/14501/","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":"<20211029041424.1430886-3-hiroh@chromium.org>","date":"2021-10-29T04:14:20","name":"[RFC,2/6] libcamera: base: Add mutex classes with thread safety annotations","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"39a087fd31cf2556f11ad134a351091f75f03729","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/14501/mbox/","series":[{"id":2678,"url":"https://patchwork.libcamera.org/api/series/2678/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2678","date":"2021-10-29T04:14:18","name":"Introduce clang thread safety annotations","version":1,"mbox":"https://patchwork.libcamera.org/series/2678/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14501/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14501/checks/","tags":{},"headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":["parsemail@patchwork.libcamera.org","kbingham@ideasonboard.com"],"Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id EFC36BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  9 Nov 2021 17:44:19 +0000 (UTC)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net\n\t[86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 88135DEE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  9 Nov 2021 18:44:19 +0100 (CET)","from perceval.ideasonboard.com\n\tby perceval.ideasonboard.com with LMTP id QKZDOip1e2E4VQAA4E0KoQ\n\t(envelope-from <hiroh@chromium.org>)\n\tfor <kbingham@ideasonboard.com>; Fri, 29 Oct 2021 06:14:34 +0200","from mail-pl1-x631.google.com (mail-pl1-x631.google.com\n\t[IPv6:2607:f8b0:4864:20::631])\tby perceval.ideasonboard.com (Postfix)\n\twith ESMTPS id D95F9893\tfor <kieran.bingham@ideasonboard.com>;\n\tFri, 29 Oct 2021 06:14:34 +0200 (CEST)","by mail-pl1-x631.google.com with SMTP id n11so5988077plf.4 \n\tfor <kieran.bingham@ideasonboard.com>;\n\tThu, 28 Oct 2021 21:14:34 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:fd56:8786:5663:b946]) by smtp.gmail.com with\n\tESMTPSA id 11sm4826714pfl.41.2021.10.28.21.14.31 (version=TLS1_3\n\tcipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 21:14:33\n\t-0700 (PDT)"],"Authentication-Results":"perceval.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"FBDT7iBL\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=EHPkRzs5equ910K/c2+ZUgyZcKmqohSpRMPlVSomN7A=;\n\tb=FBDT7iBLfuHyADTO5TU2Kpdf+HZzKFnsiublcVBQI3UoLHa8XSPP7II9wCOuqA+KoQ\n\tYPFSCcLVju7iIyco9Sz+cu4k5uM6z7zxG5gxjFc2pGIbNsJVgb24nQ/2kuyOT3zlfNPj\n\tFz0eJBB2xyepjnG3Yk8GNG6cIX4F1gGmEvjnI=","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=EHPkRzs5equ910K/c2+ZUgyZcKmqohSpRMPlVSomN7A=;\n\tb=dIP3sC68Rn1SHN8Tmdi3tnjRx6wCpY8v06/CEJGbKigGAsAJD2wqxN1p0wSGCWltdG\n\tCUL1SLIhnVKUY97eSd0UqZaMKx5ditQY809iTLYRV7zDYCkr1NQo0bpcJOKWHpS9OO+J\n\t46i3J/HjpHNFwpgfA5N98tPR/86RZy+z42Oa9qqzQGA6XA1xMJ5gAdfZRSGgFv6OwiRd\n\t6Wm1Zvf3XxiwHrixyzYoN75Ng+6WZvXa8dOVvEx0It7d3sK8rcO/oZYeaDwwRvHqJZMO\n\ttn9GPRa8D74Ws67EZy49kqWEZbfhNK8OS55+35xkgxpQ/k2ux0xAVGVuq9cATVdedq0W\n\t4xkw==","X-Gm-Message-State":"AOAM531p3RUJkUY9eA35w1YJyf0bW/YEUJHFkRXH+OpZqCsNtGkUmFVO\n\tkY97zCI/sesDh4TOmxCMEEBqDA==","X-Google-Smtp-Source":"=?utf-8?q?ABdhPJz/UufzX+4JRY5vY+xBLHQNyMdtWIqXilYE6?=\n\t=?utf-8?q?Hq5iWqXfd8/5/B4c92EJufKO757QcNQuzM6ZQ=3D=3D?=","X-Received":"by 2002:a17:90b:1806:: with SMTP id\n\tlw6mr14147261pjb.222.1635480873396; Thu, 28 Oct 2021 21:14:33 -0700\n\t(PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Cc":"tfiga@chromium.org, laurent.pinchart@ideasonboard.com,\n\tkieran.bingham@ideasonboard.com, Hirokazu Honda <hiroh@chromium.org>","Subject":"[RFC PATCH 2/6] libcamera: base: Add mutex classes with thread\n\tsafety annotations","Date":"Fri, 29 Oct 2021 13:14:20 +0900","Message-Id":"<20211029041424.1430886-3-hiroh@chromium.org>","X-Mailer":"git-send-email 2.33.1.1089.g2158813163f-goog","In-Reply-To":"<20211029041424.1430886-1-hiroh@chromium.org>","References":"<20211029041424.1430886-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-TUID":"eGeTuRKFUMY+","Resent-From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Resent-To":"parsemail@patchwork.libcamera.org"},"content":"Mutex2 and MutexLocker2 are annotated by clang thread safety\nannotations. So we can add annotation to code where the classes\nare used.\nIn the future, they will replace Mutex and MutexLocker.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n include/libcamera/base/meson.build |  1 +\n include/libcamera/base/mutex.h     | 66 ++++++++++++++++++++++++++++++\n include/libcamera/base/thread.h    |  5 +--\n 3 files changed, 68 insertions(+), 4 deletions(-)\n create mode 100644 include/libcamera/base/mutex.h","diff":"diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build\nindex 1a71ce5a..37c4435a 100644\n--- a/include/libcamera/base/meson.build\n+++ b/include/libcamera/base/meson.build\n@@ -13,6 +13,7 @@ libcamera_base_headers = files([\n     'flags.h',\n     'log.h',\n     'message.h',\n+    'mutex.h',\n     'object.h',\n     'private.h',\n     'semaphore.h',\ndiff --git a/include/libcamera/base/mutex.h b/include/libcamera/base/mutex.h\nnew file mode 100644\nindex 00000000..d130988e\n--- /dev/null\n+++ b/include/libcamera/base/mutex.h\n@@ -0,0 +1,66 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * thread.h - Thread support\n+ */\n+#ifndef __LIBCAMERA_BASE_MUTEX_H__\n+#define __LIBCAMERA_BASE_MUTEX_H__\n+\n+#include <mutex>\n+\n+#include <libcamera/base/thread_annotations.h>\n+\n+namespace libcamera {\n+\n+using Mutex = std::mutex;\n+using MutexLocker = std::unique_lock<std::mutex>;\n+\n+class CAPABILITY(\"mutex\") Mutex2 final\n+{\n+public:\n+\tvoid lock() ACQUIRE()\n+\t{\n+\t\tmutex_.lock();\n+\t}\n+\n+\tvoid unlock() RELEASE()\n+\t{\n+\t\tmutex_.unlock();\n+\t}\n+\n+\tstd::mutex &get() { return mutex_; }\n+private:\n+\tstd::mutex mutex_;\n+};\n+\n+class SCOPED_CAPABILITY MutexLocker2 final\n+{\n+public:\n+\tMutexLocker2(Mutex2 &mutex) ACQUIRE(mutex)\n+\t\t: lock_(mutex.get())\n+\t{\n+\t}\n+\n+\t~MutexLocker2() RELEASE()\n+\t{\n+\t}\n+\n+\tvoid lock() ACQUIRE()\n+\t{\n+\t\tlock_.lock();\n+\t}\n+\n+\tvoid unlock() RELEASE()\n+\t{\n+\t\tlock_.unlock();\n+\t}\n+\n+\tstd::unique_lock<std::mutex> &get() { return lock_; }\n+private:\n+\tstd::unique_lock<std::mutex> lock_;\n+};\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_BASE_MUTEX_H__ */\ndiff --git a/include/libcamera/base/thread.h b/include/libcamera/base/thread.h\nindex e0ca0aea..ae630563 100644\n--- a/include/libcamera/base/thread.h\n+++ b/include/libcamera/base/thread.h\n@@ -8,13 +8,13 @@\n #define __LIBCAMERA_BASE_THREAD_H__\n \n #include <memory>\n-#include <mutex>\n #include <sys/types.h>\n #include <thread>\n \n #include <libcamera/base/private.h>\n \n #include <libcamera/base/message.h>\n+#include <libcamera/base/mutex.h>\n #include <libcamera/base/signal.h>\n #include <libcamera/base/utils.h>\n \n@@ -26,9 +26,6 @@ class Object;\n class ThreadData;\n class ThreadMain;\n \n-using Mutex = std::mutex;\n-using MutexLocker = std::unique_lock<std::mutex>;\n-\n class Thread\n {\n public:\n","prefixes":["RFC","2/6"]}