1 #ifndef _URCU_COMPILER_H
2 #define _URCU_COMPILER_H
7 * Compiler definitions.
9 * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
22 #include <stddef.h> /* for offsetof */
24 #define caa_likely(x) __builtin_expect(!!(x), 1)
25 #define caa_unlikely(x) __builtin_expect(!!(x), 0)
27 #define cmm_barrier() __asm__ __volatile__ ("" : : : "memory")
30 * Instruct the compiler to perform only a single access to a variable
31 * (prohibits merging and refetching). The compiler is also forbidden to reorder
32 * successive instances of CMM_ACCESS_ONCE(), but only when the compiler is aware of
33 * particular ordering. Compiler ordering can be ensured, for example, by
34 * putting two CMM_ACCESS_ONCE() in separate C statements.
36 * This macro does absolutely -nothing- to prevent the CPU from reordering,
37 * merging, or refetching absolutely anything at any time. Its main intended
38 * use is to mediate communication between process-level code and irq/NMI
39 * handlers, all running on the same CPU.
41 #define CMM_ACCESS_ONCE(x) (*(__volatile__ __typeof__(x) *)&(x))
44 #define caa_max(a,b) ((a)>(b)?(a):(b))
48 #define caa_min(a,b) ((a)<(b)?(a):(b))
51 #if defined(__SIZEOF_LONG__)
52 #define CAA_BITS_PER_LONG (__SIZEOF_LONG__ * 8)
54 #define CAA_BITS_PER_LONG 64
56 #define CAA_BITS_PER_LONG 32
60 * caa_container_of - Get the address of an object containing a field.
62 * @ptr: pointer to the field.
63 * @type: type of the object.
64 * @member: name of the field within the object.
66 #define caa_container_of(ptr, type, member) \
69 const __typeof__(((type *) NULL)->member) * __ptr = (ptr); \
70 (type *)((char *)__ptr - offsetof(type, member)); \
73 #define CAA_BUILD_BUG_ON_ZERO(cond) (sizeof(struct { int:-!!(cond); }))
74 #define CAA_BUILD_BUG_ON(cond) ((void)CAA_BUILD_BUG_ON_ZERO(cond))
77 * __rcu is an annotation that documents RCU pointer accesses that need
78 * to be protected by a read-side critical section. Eventually, a static
79 * checker will be able to use this annotation to detect incorrect RCU
85 #define URCU_FORCE_CAST(type, arg) (reinterpret_cast<type>(arg))
87 #define URCU_FORCE_CAST(type, arg) ((type) (arg))
90 #define caa_is_signed_type(type) ((type) -1 < (type) 0)
93 * Cast to unsigned long, sign-extending if @v is signed.
94 * Note: casting to a larger type or to same type size keeps the sign of
95 * the expression being cast (see C99 6.3.1.3).
97 #define caa_cast_long_keep_sign(v) ((unsigned long) (v))
99 #if defined (__GNUC__) \
100 && ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5) \
102 #define CDS_DEPRECATED(msg) \
103 __attribute__((deprecated(msg)))
105 #define CDS_DEPRECATED(msg) \
106 __attribute__((deprecated))
109 #define CAA_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
112 * Don't allow compiling with buggy compiler.
114 * URCU_GCC_VERSION is used to blacklist specific GCC versions with known
115 * bugs, clang also defines these macros to an equivalent GCC version it
116 * claims to support, so exclude it.
119 #if defined(__GNUC__) && !defined(__clang__)
120 # define URCU_GCC_VERSION (__GNUC__ * 10000 \
121 + __GNUC_MINOR__ * 100 \
122 + __GNUC_PATCHLEVEL__)
125 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58854
128 # if URCU_GCC_VERSION >= 40800 && URCU_GCC_VERSION <= 40802
129 # error Your gcc version produces clobbered frame accesses
134 #endif /* _URCU_COMPILER_H */
This page took 0.03315 seconds and 5 git commands to generate.