Added write_or_die routines, make it compile again
[transsip-mirror.git] / src / compiler.h
blobc0a02e8198e1978adebf4c1665891c54371a6631
1 /*
2 * transsip - the telephony network
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
7 */
9 #ifndef COMPILER_H
10 #define COMPILER_H
12 #ifndef __aligned_16
13 # define __aligned_16 __attribute__((aligned(16)))
14 #endif
15 #ifndef likely
16 # define likely(x) __builtin_expect(!!(x), 1)
17 #endif
18 #ifndef unlikely
19 # define unlikely(x) __builtin_expect(!!(x), 0)
20 #endif
21 #ifndef __deprecated
22 # define __deprecated /* unimplemented */
23 #endif
24 #ifndef unreachable
25 # define unreachable() do { } while (1)
26 #endif
27 #ifndef barrier
28 # define barrier() __sync_synchronize()
29 #endif
30 #ifndef bug
31 # define bug() __builtin_trap()
32 #endif
33 #ifndef mark_unreachable
34 # define mark_unreachable() __builtin_unreachable()
35 #endif
36 #ifndef is_type
37 # define is_type(x, type) __builtin_types_compatible_p(typeof(x), (type))
38 #endif
39 #ifndef same_type
40 # define same_type(x, y) __builtin_types_compatible_p(typeof(x), typeof(y))
41 #endif
42 #ifndef __read_mostly
43 # define __read_mostly __attribute__((__section__(".data.read_mostly")))
44 #endif
45 #ifndef __must_check
46 # define __must_check /* unimplemented */
47 #endif
48 #ifndef __used
49 # define __used /* unimplemented */
50 #endif
51 #ifndef __maybe_unused
52 # define __maybe_unused /* unimplemented */
53 #endif
54 #ifndef __always_unused
55 # define __always_unused /* unimplemented */
56 #endif
57 #ifndef noinline
58 # define noinline __attribute__((noinline))
59 #endif
60 #ifndef __always_inline
61 # define __always_inline inline
62 #endif
64 * Protected visibility is like default visibility except that it indicates
65 * that references within the defining module will bind to the definition
66 * in that module. That is, the declared entity cannot be overridden by
67 * another module.
69 #ifndef __protected
70 # define __protected __attribute__((visibility("protected")))
71 #endif
73 * Hidden visibility indicates that the entity declared will have a new form
74 * of linkage, which we'll call "hidden linkage". Two declarations of an
75 * object with hidden linkage refer to the same object if they are in the
76 * same shared object.
78 #ifndef __hidden
79 # define __hidden __attribute__((visibility("hidden")))
80 #endif
82 * Internal visibility is like hidden visibility, but with additional
83 * processor specific semantics. Unless otherwise specified by the psABI,
84 * GCC defines internal visibility to mean that a function is never called
85 * from another module. Compare this with hidden functions which, while they
86 * cannot be referenced directly by other modules, can be referenced
87 * indirectly via function pointers. By indicating that a function cannot be
88 * called from outside the module, GCC may for instance omit the load of a
89 * PIC register since it is known that the calling function loaded the
90 * correct value.
92 #ifndef __internal
93 # define __internal __attribute__((visibility("internal")))
94 #endif
95 #ifndef max
96 # define max(a, b) \
97 ({ \
98 typeof (a) _a = (a); \
99 typeof (b) _b = (b); \
100 _a > _b ? _a : _b; \
102 #endif
103 #ifndef min
104 # define min(a, b) \
105 ({ \
106 typeof (a) _a = (a); \
107 typeof (b) _b = (b); \
108 _a < _b ? _a : _b; \
110 #endif
111 #ifndef offsetof
112 # define offsetof(type, member) ((size_t) &((type *) 0)->member)
113 #endif
115 * Casts a member of a structure out to the containing structure.
117 #ifndef container_of
118 # define container_of(ptr, type, member) \
119 ({ \
120 const typeof(((type *) 0)->member) * __mptr = (ptr); \
121 (type *) ((char *) __mptr - offsetof(type, member)); \
123 #endif
125 #endif /* COMPILER_H */