[{"id":21395,"web_url":"https://patchwork.libcamera.org/comment/21395/","msgid":"<YaWjqH/2usOxjNjI@pendragon.ideasonboard.com>","date":"2021-11-30T04:08:08","subject":"Re: [libcamera-devel] [PATCH v2 04/11] libcamera: base: Add thread\n\tsafety annotation macros","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Hiro,\n\nThank you for the patch.\n\nOn Mon, Nov 29, 2021 at 08:44:46PM +0900, Hirokazu Honda wrote:\n> Clang complier is able to do a thread safety analysis with\n\ns/complier/compiler/\n\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\nReviewed-by: Laurent Pinchart <laurent.pinchart@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 00280BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 04:08:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC254605B4;\n\tTue, 30 Nov 2021 05:08:34 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 29FD7604FC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 30 Nov 2021 05:08:33 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A47688F0;\n\tTue, 30 Nov 2021 05:08:32 +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=\"l5D1O+h/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638245312;\n\tbh=NWVLfK5HyprJ0EMBx2FwXSxL6jPqY/Gw6pQQeHBFdwo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=l5D1O+h/5dWi2TSmxw0+0+spnAHMc7bXe+OIAiVsCIyfFNnR238FDnXV2vlf54hNO\n\tiNA2yqtPrVP1UkiU5/8md3CQ67f7q8QgNh439dUK3lj9pcyFVun64NuigtWSStw0MO\n\tzcAA8Z8qLiQwNFycvGx0+1PvaWD1tWSA33aLLhzs=","Date":"Tue, 30 Nov 2021 06:08:08 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Hirokazu Honda <hiroh@chromium.org>","Message-ID":"<YaWjqH/2usOxjNjI@pendragon.ideasonboard.com>","References":"<20211129114453.3186042-1-hiroh@chromium.org>\n\t<20211129114453.3186042-5-hiroh@chromium.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211129114453.3186042-5-hiroh@chromium.org>","Subject":"Re: [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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]