[{"id":21502,"web_url":"https://patchwork.libcamera.org/comment/21502/","msgid":"<31bec911-2c06-b81c-898a-929e69e78ea0@ideasonboard.com>","date":"2021-12-01T10:28:17","subject":"Re: [libcamera-devel] [PATCH v5 04/12] libcamera: base: Add thread\n\tsafety annotation macros","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Hiro\n\nOn 12/1/21 1:23 PM, Hirokazu Honda wrote:\n> Clang compiler is able to do a thread safety analysis with\n> annotations [1]. This introduces the thread safety annotation\n> macros and also enable the analysis by adding -Wthread-safety\n> if a clang compiler is used.\n>\n> [1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html.\n>\n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\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\n>\n> diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build\n> index 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>   ])\n> diff --git a/include/libcamera/base/thread_annotations.h b/include/libcamera/base/thread_annotations.h\n> new file mode 100644\n> index 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)\n> diff --git a/meson.build b/meson.build\n> index 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>","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 EC0A7BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  1 Dec 2021 10:28:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3E26960720;\n\tWed,  1 Dec 2021 11:28:23 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 092636011D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Dec 2021 11:28:22 +0100 (CET)","from [192.168.1.106] (unknown [103.251.226.170])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D42ED8AE;\n\tWed,  1 Dec 2021 11:28:20 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"BHWDjHJG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638354501;\n\tbh=zAawOVM1xqynjIgNSzYQrvbKbiPuKVyHkvL7OwCjgUQ=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=BHWDjHJGh6f2lCx/ktnjG33U1RFCcoSRTulsBEzpSV1OX0S9OPOh51MOaT+t6s1Yb\n\tWgAQWvUiGtkyxVpW4BSAU4ACu3Tils75PLR6pinPynw4bC7nYJO7Ad9et6a//eSCJN\n\tOSO/7ESUeHuJ7E5hUB3qInF3xcY2Ja0ZpnOG4vws=","To":"Hirokazu Honda <hiroh@chromium.org>, libcamera-devel@lists.libcamera.org","References":"<20211201075348.3121186-1-hiroh@chromium.org>\n\t<20211201075348.3121186-5-hiroh@chromium.org>","From":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<31bec911-2c06-b81c-898a-929e69e78ea0@ideasonboard.com>","Date":"Wed, 1 Dec 2021 15:58:17 +0530","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.10.2","MIME-Version":"1.0","In-Reply-To":"<20211201075348.3121186-5-hiroh@chromium.org>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Transfer-Encoding":"7bit","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH v5 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>"}}]