5b994076f47c913b28d636ae6e7262261befe103
1 // SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: LGPL-2.1-or-later
5 #ifndef _URCU_COMPILER_H
6 #define _URCU_COMPILER_H
9 * Compiler definitions.
12 #include <stddef.h> /* for offsetof */
14 #if defined __cplusplus
15 # include <type_traits> /* for std::remove_cv */
18 #define caa_likely(x) __builtin_expect(!!(x), 1)
19 #define caa_unlikely(x) __builtin_expect(!!(x), 0)
21 #define cmm_barrier() __asm__ __volatile__ ("" : : : "memory")
24 * Instruct the compiler to perform only a single access to a variable
25 * (prohibits merging and refetching). The compiler is also forbidden to reorder
26 * successive instances of CMM_ACCESS_ONCE(), but only when the compiler is aware of
27 * particular ordering. Compiler ordering can be ensured, for example, by
28 * putting two CMM_ACCESS_ONCE() in separate C statements.
30 * This macro does absolutely -nothing- to prevent the CPU from reordering,
31 * merging, or refetching absolutely anything at any time. Its main intended
32 * use is to mediate communication between process-level code and irq/NMI
33 * handlers, all running on the same CPU.
35 #define CMM_ACCESS_ONCE(x) (*(__volatile__ __typeof__(x) *)&(x))
38 #define caa_max(a,b) ((a)>(b)?(a):(b))
42 #define caa_min(a,b) ((a)<(b)?(a):(b))
45 #if defined(__SIZEOF_LONG__)
46 #define CAA_BITS_PER_LONG (__SIZEOF_LONG__ * 8)
48 #define CAA_BITS_PER_LONG 64
50 #define CAA_BITS_PER_LONG 32
54 * caa_container_of - Get the address of an object containing a field.
56 * @ptr: pointer to the field.
57 * @type: type of the object.
58 * @member: name of the field within the object.
60 #define caa_container_of(ptr, type, member) \
63 const __typeof__(((type *) NULL)->member) * __ptr = (ptr); \
64 (type *)((char *)__ptr - offsetof(type, member)); \
68 * caa_container_of_check_null - Get the address of an object containing a field.
70 * @ptr: pointer to the field.
71 * @type: type of the object.
72 * @member: name of the field within the object.
74 * Return the address of the object containing the field. Return NULL if
77 #define caa_container_of_check_null(ptr, type, member) \
80 const __typeof__(((type *) NULL)->member) * __ptr = (ptr); \
81 (__ptr) ? (type *)((char *)__ptr - offsetof(type, member)) : NULL; \
84 #define CAA_BUILD_BUG_ON_ZERO(cond) (sizeof(struct { int:-!!(cond); }))
85 #define CAA_BUILD_BUG_ON(cond) ((void)CAA_BUILD_BUG_ON_ZERO(cond))
88 * __rcu is an annotation that documents RCU pointer accesses that need
89 * to be protected by a read-side critical section. Eventually, a static
90 * checker will be able to use this annotation to detect incorrect RCU
96 #define URCU_FORCE_CAST(_type, arg) (reinterpret_cast<std::remove_cv<_type>::type>(arg))
98 #define URCU_FORCE_CAST(type, arg) ((type) (arg))
101 #define caa_is_signed_type(type) ((type) -1 < (type) 0)
104 * Cast to unsigned long, sign-extending if @v is signed.
105 * Note: casting to a larger type or to same type size keeps the sign of
106 * the expression being cast (see C99 6.3.1.3).
108 #define caa_cast_long_keep_sign(v) ((unsigned long) (v))
110 #if defined (__GNUC__) \
111 && ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5) \
113 #define CDS_DEPRECATED(msg) \
114 __attribute__((deprecated(msg)))
116 #define CDS_DEPRECATED(msg) \
117 __attribute__((deprecated))
120 #define CAA_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
123 * URCU_GCC_VERSION is used to blacklist specific GCC versions with known
124 * bugs, clang also defines these macros to an equivalent GCC version it
125 * claims to support, so exclude it.
127 #if defined(__GNUC__) && !defined(__clang__)
128 # define URCU_GCC_VERSION (__GNUC__ * 10000 \
129 + __GNUC_MINOR__ * 100 \
130 + __GNUC_PATCHLEVEL__)
133 #endif /* _URCU_COMPILER_H */
This page took 0.041237 seconds and 4 git commands to generate.