ce19c74764de7c82c5c8dbb06e2ddd214027c5f8
[urcu.git] / urcu / compiler.h
1 #ifndef _URCU_COMPILER_H
2 #define _URCU_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 #include <stddef.h> /* for offsetof */
22
23 #define likely(x) __builtin_expect(!!(x), 1)
24 #define unlikely(x) __builtin_expect(!!(x), 0)
25
26 #define barrier() asm volatile("" : : : "memory")
27
28 /*
29 * Instruct the compiler to perform only a single access to a variable
30 * (prohibits merging and refetching). The compiler is also forbidden to reorder
31 * successive instances of ACCESS_ONCE(), but only when the compiler is aware of
32 * particular ordering. Compiler ordering can be ensured, for example, by
33 * putting two ACCESS_ONCE() in separate C statements.
34 *
35 * This macro does absolutely -nothing- to prevent the CPU from reordering,
36 * merging, or refetching absolutely anything at any time. Its main intended
37 * use is to mediate communication between process-level code and irq/NMI
38 * handlers, all running on the same CPU.
39 */
40 #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
41
42 #ifndef max
43 #define max(a,b) ((a)>(b)?(a):(b))
44 #endif
45
46 #ifndef min
47 #define min(a,b) ((a)<(b)?(a):(b))
48 #endif
49
50 #if defined(__SIZEOF_LONG__)
51 #define BITS_PER_LONG (__SIZEOF_LONG__ * 8)
52 #elif defined(_LP64)
53 #define BITS_PER_LONG 64
54 #else
55 #define BITS_PER_LONG 32
56 #endif
57
58 #endif /* _URCU_COMPILER_H */
This page took 0.039789 seconds and 3 git commands to generate.