{"id":14901,"url":"https://patchwork.libcamera.org/api/1.1/patches/14901/?format=json","web_url":"https://patchwork.libcamera.org/patch/14901/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20211130155600.2203123-5-hiroh@chromium.org>","date":"2021-11-30T15:55:52","name":"[libcamera-devel,v3,04/12] 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/1.1/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14901/mbox/","series":[{"id":2785,"url":"https://patchwork.libcamera.org/api/1.1/series/2785/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2785","date":"2021-11-30T15:55:48","name":"Introduce clang thread safety annotations","version":3,"mbox":"https://patchwork.libcamera.org/series/2785/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14901/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14901/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 55CCAC324F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 15:56:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C451A60720;\n\tTue, 30 Nov 2021 16:56:19 +0100 (CET)","from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com\n\t[IPv6:2607:f8b0:4864:20::102e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3369C6071B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 16:56:16 +0100 (CET)","by mail-pj1-x102e.google.com with SMTP id x7so15717701pjn.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 07:56:16 -0800 (PST)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:203:c90a:5a53:b139:1336])\n\tby smtp.gmail.com with ESMTPSA id\n\tpc10sm3510283pjb.9.2021.11.30.07.56.12\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 30 Nov 2021 07:56:13 -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=\"LK48A4Qd\"; 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=bCrfFSftCVaNJq0QCqjXOGL5JcW2aZUftTC49vcY4y4=;\n\tb=LK48A4QdqaC35VtHXSsgZrmlZYjBukm9Pjbjv5S3daXMXoIaQjfIELHO9nUJf5Z23L\n\tqkCPQMnxXXN54f1jKZcyfgJMdKplD2mT7/BxIllJR2AJMgVoi4ztWFcNUA9AZgSglkka\n\t5T+nhvVa8ndULmlvLlvpMLWz/3C/nTuuU3oUg=","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=bCrfFSftCVaNJq0QCqjXOGL5JcW2aZUftTC49vcY4y4=;\n\tb=gqWBh2wYT2RupnSrkb+XBDIQSDTVU9x5HEzwyggwDCHhb8j/QhPbNtwFT1mWR90y1q\n\tynLJzzxra5Td79aUC668VIp3K0P645wuohrLu2cJF1WqzgG/YVq/iposazA8NCBtZYsw\n\tiRfWXEnRc6NodMkg154iO4qHSSaBPIN48DAXfmgczZwaauBfcQvS/egv65O1hWm/dNQa\n\tQTzwdqrcnUFgO3Ccrbq7HKd4KSv9VYr3doqAv0/9edaMuQx9SNVCwHKvcYqEsrAxfkQs\n\tSkXdlLFjk3RRekf89y/tq4qJBXccCi1nyGApUkoOq1SgBKq299TNvHD9sbTnidfykqoM\n\tFBeQ==","X-Gm-Message-State":"AOAM533grWg9DTJhVggs6n8fmYjok/Hf2hlX+b1edt8+dT6y3S4zQwje\n\tz1S8ODLreMCX+huqtOhHH2hmhTWh03JqMQ==","X-Google-Smtp-Source":"ABdhPJwcVo1BT7bFY+G7KZ9Y0csrcgW1mlNDevssb8q4hr4CJyWLSAOxmLTdArJc1LBKW+I+7D6c/w==","X-Received":"by 2002:a17:90a:2ec8:: with SMTP id\n\th8mr323256pjs.168.1638287774271; \n\tTue, 30 Nov 2021 07:56:14 -0800 (PST)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  1 Dec 2021 00:55:52 +0900","Message-Id":"<20211130155600.2203123-5-hiroh@chromium.org>","X-Mailer":"git-send-email 2.34.0.rc2.393.gf8c9666880-goog","In-Reply-To":"<20211130155600.2203123-1-hiroh@chromium.org>","References":"<20211130155600.2203123-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 04/12] 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 compiler 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>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\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","v3","04/12"]}