engine: hangup while dialing
[transsip-mirror.git] / src / built-in.h
blob3994e1ceda64a4147b6767063acccecdfa431a50
1 /*
2 * transsip - the telephony network
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2011, 2012 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 BUILT_IN_H
10 #define BUILT_IN_H
12 #ifndef __aligned_16
13 # define __aligned_16 __attribute__((aligned(16)))
14 #endif
16 #ifndef likely
17 # define likely(x) __builtin_expect(!!(x), 1)
18 #endif
20 #ifndef unlikely
21 # define unlikely(x) __builtin_expect(!!(x), 0)
22 #endif
24 #ifndef __extension__
25 # define __extension__
26 #endif
28 #ifndef __deprecated
29 # define __deprecated /* unimplemented */
30 #endif
32 #ifndef __read_mostly
33 # define __read_mostly __attribute__((__section__(".data.read_mostly")))
34 #endif
36 #ifndef __always_inline
37 # define __always_inline inline
38 #endif
40 #ifndef __hidden
41 # define __hidden __attribute__((visibility("hidden")))
42 #endif
44 /* From Linux */
45 #ifndef array_size
46 # define array_size(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
47 #endif
49 #ifndef __must_be_array
50 # define __must_be_array(x) \
51 build_bug_on_zero(__builtin_types_compatible_p(typeof(x), typeof(&x[0])))
52 #endif
54 #ifndef max
55 # define max(a, b) \
56 ({ \
57 typeof (a) _a = (a); \
58 typeof (b) _b = (b); \
59 _a > _b ? _a : _b; \
61 #endif
63 #ifndef min
64 # define min(a, b) \
65 ({ \
66 typeof (a) _a = (a); \
67 typeof (b) _b = (b); \
68 _a < _b ? _a : _b; \
70 #endif
72 #define anon(return_type, body_and_args) \
73 ({ \
74 return_type __fn__ body_and_args \
75 __fn__; \
79 * Example usage:
81 * qsort(&argv[1], argc - 1, sizeof(argv[1]),
82 * anon(int, (const void * a, const void * b) {
83 * return strcmp(*(char * const *) a, *(char * const *) b);
84 * }));
87 #ifndef bug
88 # define bug() __builtin_trap()
89 #endif
91 #ifndef build_bug_on_zero
92 # define build_bug_on_zero(e) (sizeof(char[1 - 2 * !!(e)]) - 1)
93 #endif
95 #endif /* BUILT_IN_H */