Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
has_builtin_atomic.hpp
Go to the documentation of this file.
1
// Copyright 2024, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
#
ifndef
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PLATFORM_QUERIES_HAS_BUILTIN_ATOMIC_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PLATFORM_QUERIES_HAS_BUILTIN_ATOMIC_HPP_
7
8
// IWYU pragma: private, include "arene/base/compiler_support/platform_queries.hpp"
9
// IWYU pragma: friend "arene/base/compiler_support/platform_queries/.*"
10
11
// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
12
#
include
"arene/base/compiler_support/platform_queries/compiler_info.hpp"
// IWYU pragma: keep
13
#
include
"arene/base/compiler_support/platform_queries/has_builtin.hpp"
14
#
include
"arene/base/compiler_support/preprocessor.hpp"
15
// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
16
17
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
18
// parasoft-begin-suppress AUTOSAR-A16_0_1-d-2 "Conditional defines permitted by A16-0-1 Permit #2"
19
// parasoft-begin-suppress AUTOSAR-A16_0_1-a-2 "Conditional defines permitted by A16-0-1 Permit #2"
20
21
/// @def ARENE_HAS_BUILTIN_ATOMIC
22
/// @brief A platform support query for testing if compiler atomic intrinsics are defined.
23
///
24
/// Usage:
25
/// @code{c++}
26
/// #if ARENE_IS_ON(ARENE_HAS_BUILTIN_ATOMIC)
27
/// @endcode
28
///
29
/// The value of this query is determined as follows, in order of precedence:
30
/// 1. If __atomic_add_fetch, __atomic_fetch_add, etc. intrinsics are available, it is @c ARENE_ON_BY_DEFAULT
31
/// 2. Otherwise, it is @c ARENE_OFF_BY_DEFAULT
32
33
#
ifndef
ARENE_HAS_BUILTIN_ATOMIC_I_
34
// Check for atomic intrinsics availability
35
// parasoft-begin-suppress AUTOSAR-M16_0_7-a-2 "False positive: not used as a macro"
36
#
if
ARENE_HAS_BUILTIN
(
__atomic_add_fetch
)
&&
ARENE_HAS_BUILTIN
(
__atomic_fetch_add
)
&&
37
ARENE_HAS_BUILTIN
(
__atomic_sub_fetch
)
&&
ARENE_HAS_BUILTIN
(
__atomic_fetch_sub
)
&&
38
ARENE_HAS_BUILTIN
(
__atomic_load_n
)
39
// parasoft-end-suppress AUTOSAR-M16_0_7-a-2
40
#
define
ARENE_HAS_BUILTIN_ATOMIC_I_
ARENE_ON_BY_DEFAULT
41
#
elif
ARENE_IS_ON
(
ARENE_COMPILER_GCC
)
&&
__GNUC__
>=
8
42
// The __atomic() intrinsics exist in GCC (at least) 8 and later,
43
// but the __has_builtin query was not added until GCC 10 and so we
44
// may have returned a false negative when probing for the builtin above.
45
#
define
ARENE_HAS_BUILTIN_ATOMIC_I_
ARENE_ON_BY_DEFAULT
46
#
else
47
#
define
ARENE_HAS_BUILTIN_ATOMIC_I_
ARENE_OFF_BY_DEFAULT
48
#
endif
49
#
endif
50
51
#
ifdef
ARENE_DOC_GENERATION_RUNNING
// make this appear when running doxygen, as it won't otherwise.
52
#
ifndef
ARENE_HAS_BUILTIN_ATOMIC
53
#
define
ARENE_HAS_BUILTIN_ATOMIC
54
#
endif
55
#
endif
56
57
// NOLINTEND(cppcoreguidelines-macro-usage)
58
// parasoft-end-suppress AUTOSAR-A16_0_1-d-2
59
// parasoft-end-suppress AUTOSAR-A16_0_1-a-2
60
61
#
endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_COMPILER_SUPPORT_PLATFORM_QUERIES_HAS_BUILTIN_ATOMIC_HPP_
arene
base
compiler_support
platform_queries
has_builtin_atomic.hpp
Generated by
1.13.2