Add missing rcu_cmpxchg_pointer define
[urcu.git] / compiler.h
1 #ifndef _COMPILER_H
2 #define _COMPILER_H
3
4 /*
5 * compiler.h
6 *
7 * Compiler definitions.
8 *
9 * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
10 *
11 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
12 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
13 *
14 * Permission is hereby granted to use or copy this program
15 * for any purpose, provided the above notices are retained on all copies.
16 * Permission to modify the code and to distribute modified code is granted,
17 * provided the above notices are retained, and a notice that the code was
18 * modified is included with the above copyright notice.
19 */
20
21 #define likely(x) __builtin_expect(!!(x), 1)
22 #define unlikely(x) __builtin_expect(!!(x), 0)
23
24 #define barrier() asm volatile("" : : : "memory");
25
26 /*
27 * Instruct the compiler to perform only a single access to a variable
28 * (prohibits merging and refetching). The compiler is also forbidden to reorder
29 * successive instances of ACCESS_ONCE(), but only when the compiler is aware of
30 * particular ordering. Compiler ordering can be ensured, for example, by
31 * putting two ACCESS_ONCE() in separate C statements.
32 *
33 * This macro does absolutely -nothing- to prevent the CPU from reordering,
34 * merging, or refetching absolutely anything at any time. Its main intended
35 * use is to mediate communication between process-level code and irq/NMI
36 * handlers, all running on the same CPU.
37 */
38 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&x)
39
40 #if (__GNUC__ == 4)
41 #define __compiler_offsetof(a, b) __builtin_offsetof(a, b)
42 #endif
43
44 #ifdef __compiler_offsetof
45 #define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER)
46 #else
47 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
48 #endif
49
50 #endif /* _COMPILER_H */
This page took 0.032997 seconds and 4 git commands to generate.