{"id":14840,"url":"https://patchwork.libcamera.org/api/patches/14840/?format=json","web_url":"https://patchwork.libcamera.org/patch/14840/","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":"<20211129114453.3186042-5-hiroh@chromium.org>","date":"2021-11-29T11:44:46","name":"[libcamera-devel,v2,04/11] libcamera: base: Add thread safety annotation macros","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"8002765e49fd7a23f7f9a69ae96080e7f2fd6469","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/14840/mbox/","series":[{"id":2770,"url":"https://patchwork.libcamera.org/api/series/2770/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2770","date":"2021-11-29T11:44:42","name":"Introduce clang thread safety annotations","version":2,"mbox":"https://patchwork.libcamera.org/series/2770/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14840/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14840/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 98A3DC324F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Nov 2021 11:45:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3CDDB605B6;\n\tMon, 29 Nov 2021 12:45:11 +0100 (CET)","from mail-pl1-x635.google.com (mail-pl1-x635.google.com\n\t[IPv6:2607:f8b0:4864:20::635])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 51BE660597\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Nov 2021 12:45:08 +0100 (CET)","by mail-pl1-x635.google.com with SMTP id v19so11928121plo.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Nov 2021 03:45:08 -0800 (PST)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:f254:cda9:46e8:17b7])\n\tby smtp.gmail.com with ESMTPSA id\n\thg4sm17951966pjb.1.2021.11.29.03.45.05\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 29 Nov 2021 03:45:06 -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=\"DHRVfr0c\"; 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=d5yT8zNAlqQjYlwlQgZSp7pbadJUD9JTM9ocP49aJHc=;\n\tb=DHRVfr0cdtBoR37g1NrN3hVgThd8Q0aYe6+1RrrDOk4wFzMFQRi08iZxL5rb6mJcx5\n\tttVrX8WOgtXp53DcNFFdxWwX46HQ6eANviQ7GY2f0K60VipWrOFUuwLfP2l6ux5KAZD0\n\tbXp0HldFTWtNIRDiKgSOGTYotvswX6u9o1ohE=","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=d5yT8zNAlqQjYlwlQgZSp7pbadJUD9JTM9ocP49aJHc=;\n\tb=QGzcYh1Hv0zSfiBdEd0mt6gjNAV0bSVVlgI4umEbk3ccdLqGROSuW0OlHv2czLtMKJ\n\t9whMHWXOOTd0RZNxHwu1IE1s2LRwZlHYK/iUfGuFy9yTotONvIk/LJXwnPgq3FGFGWzH\n\t2NJrRXWYvP01/ZGAOVHlAtBfr7hT34xsoZ/l1UYEM/PUc76AONyLe12bMupDEDSV64Eu\n\twguSLM6EYmQWlhm1M3D/MyMhtENBUEwd+DSExBrQQI99tqF7e2F43LSRG60lXuz+uYGP\n\tkYijcVbu7XetDzBDLiTi3ZD+UcnsVDrP+LIsyGXxlLCEBehlGpG0wv6jDbu2U/3g3Udu\n\tlAHQ==","X-Gm-Message-State":"AOAM531DK5G5AgE8X7zCE42uoTjqgiz3pokiQfn7pgVt52QzbGaJMIK8\n\tfjbwf2vxjjqTnHY2wylREWGG9RSk2Pu9SA==","X-Google-Smtp-Source":"ABdhPJxsCTk2N0uzctIEPF1v66/Kk/v1Ba+A6o2GvW00lFRKTiUjDNczwe1AAeoqnpYHpBmkPJDizw==","X-Received":"by 2002:a17:90a:46c9:: with SMTP id\n\tx9mr38261632pjg.183.1638186306617; \n\tMon, 29 Nov 2021 03:45:06 -0800 (PST)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 29 Nov 2021 20:44:46 +0900","Message-Id":"<20211129114453.3186042-5-hiroh@chromium.org>","X-Mailer":"git-send-email 2.34.0.rc2.393.gf8c9666880-goog","In-Reply-To":"<20211129114453.3186042-1-hiroh@chromium.org>","References":"<20211129114453.3186042-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 04/11] libcamera: base: Add thread\n\tsafety annotation macros","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":"Clang complier is able to do a thread safety analysis with\nannotations [1]. This introduces the thread safety annotation\nmacros and also enable the analysis by adding -Wthread-safety\nif a clang compiler is used.\n\n[1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n include/libcamera/base/meson.build          |  1 +\n include/libcamera/base/thread_annotations.h | 80 +++++++++++++++++++++\n meson.build                                 |  1 +\n 3 files changed, 82 insertions(+)\n create mode 100644 include/libcamera/base/thread_annotations.h","diff":"diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build\nindex 525aba9d..1a71ce5a 100644\n--- a/include/libcamera/base/meson.build\n+++ b/include/libcamera/base/meson.build\n@@ -19,6 +19,7 @@ libcamera_base_headers = files([\n     'signal.h',\n     'span.h',\n     'thread.h',\n+    'thread_annotations.h',\n     'timer.h',\n     'utils.h',\n ])\ndiff --git a/include/libcamera/base/thread_annotations.h b/include/libcamera/base/thread_annotations.h\nnew file mode 100644\nindex 00000000..e81929f6\n--- /dev/null\n+++ b/include/libcamera/base/thread_annotations.h\n@@ -0,0 +1,80 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * thread_annotation.h - Macro of Clang thread safety analysis\n+ */\n+\n+#pragma once\n+\n+/*\n+ * Enable thread safety attributes only with clang.\n+ * The attributes can be safely erased when compiling with other compilers.\n+ */\n+#if defined(__clang__) && !defined(SWIG)\n+#define LIBCAMERA_TSA_ATTRIBUTE__(x) __attribute__((x))\n+#else\n+#define LIBCAMERA_TSA_ATTRIBUTE__(x) /* no-op */\n+#endif\n+\n+/* See https://clang.llvm.org/docs/ThreadSafetyAnalysis.html for these usages. */\n+\n+#define LIBCAMERA_TSA_CAPABILITY(x)\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(capability(x))\n+\n+#define LIBCAMERA_TSA_SCOPED_CAPABILITY\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(scoped_lockable)\n+\n+#define LIBCAMERA_TSA_GUARDED_BY(x)\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(guarded_by(x))\n+\n+#define LIBCAMERA_TSA_PT_GUARDED_BY(x)\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(pt_guarded_by(x))\n+\n+#define LIBCAMERA_TSA_ACQUIRED_BEFORE(...)\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(acquired_before(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_ACQUIRED_AFTER(...)\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(acquired_after(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_REQUIRES(...)\t\t\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(requires_capability(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_REQUIRES_SHARED(...)\t\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_ACQUIRE(...)\t\t\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(acquire_capability(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_ACQUIRE_SHARED(...)\t\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_RELEASE(...)\t\t\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(release_capability(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_RELEASE_SHARED(...)\t\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_RELEASE_GENERIC(...)\t\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(release_generic_capability(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_TRY_ACQUIRE(...)\t\t\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_TRY_ACQUIRE_SHARED(...)\t\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_EXCLUDES(...)\t\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(locks_excluded(__VA_ARGS__))\n+\n+#define LIBCAMERA_TSA_ASSERT_CAPABILITY(x)\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(assert_capability(x))\n+\n+#define LIBCAMERA_TSA_ASSERT_SHARED_CAPABILITY(x)\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(assert_shared_capability(x))\n+\n+#define LIBCAMERA_TSA_RETURN_CAPABILITY(x)\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(lock_returned(x))\n+\n+#define LIBCAMERA_TSA_NO_THREAD_SAFETY_ANALYSIS\t\t\t\\\n+\tLIBCAMERA_TSA_ATTRIBUTE__(no_thread_safety_analysis)\ndiff --git a/meson.build b/meson.build\nindex 7892a9e3..7147a108 100644\n--- a/meson.build\n+++ b/meson.build\n@@ -72,6 +72,7 @@ if cc.get_id() == 'clang'\n \n     cpp_arguments += [\n         '-Wextra-semi',\n+        '-Wthread-safety',\n     ]\n endif\n \n","prefixes":["libcamera-devel","v2","04/11"]}