L4Re - L4 Runtime Environment
compiler.h
Go to the documentation of this file.
1 /*****************************************************************************/
7 /*
8  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9  * Alexander Warg <warg@os.inf.tu-dresden.de>,
10  * Frank Mehnert <fm3@os.inf.tu-dresden.de>,
11  * Jork Löser <jork@os.inf.tu-dresden.de>,
12  * Ronald Aigner <ra3@os.inf.tu-dresden.de>
13  * economic rights: Technische Universität Dresden (Germany)
14  *
15  * This file is part of TUD:OS and distributed under the terms of the
16  * GNU General Public License 2.
17  * Please see the COPYING-GPL-2 file for details.
18  *
19  * As a special exception, you may use this file as part of a free software
20  * library without restriction. Specifically, if other files instantiate
21  * templates or use macros or inline functions from this file, or you compile
22  * this file and link it with other files to produce an executable, this
23  * file does not by itself cause the resulting executable to be covered by
24  * the GNU General Public License. This exception does not however
25  * invalidate any other reasons why the executable file might be covered by
26  * the GNU General Public License.
27  */
28 /*****************************************************************************/
29 #ifndef __L4_COMPILER_H__
30 #define __L4_COMPILER_H__
31 
32 #if !defined(__ASSEMBLY__) && !defined(__ASSEMBLER__)
33 
40 
45 #ifndef L4_INLINE
46 #ifndef __cplusplus
47 # ifdef __OPTIMIZE__
48 # define L4_INLINE_STATIC static __inline__
49 # define L4_INLINE_EXTERN extern __inline__
50 # ifdef __GNUC_STDC_INLINE__
51 # define L4_INLINE L4_INLINE_STATIC
52 # else
53 # define L4_INLINE L4_INLINE_EXTERN
54 # endif
55 # else /* ! __OPTIMIZE__ */
56 # define L4_INLINE static
57 # endif /* ! __OPTIMIZE__ */
58 #else /* __cplusplus */
59 # define L4_INLINE inline
60 #endif /* __cplusplus */
61 #endif /* L4_INLINE */
62 
67 #define L4_ALWAYS_INLINE L4_INLINE __attribute__((__always_inline__))
68 
69 
70 #define L4_DECLARE_CONSTRUCTOR(func, prio) \
71  static inline __attribute__((constructor(prio))) void func ## _ctor_func(void) { func(); }
72 
73 
171 #ifndef __cplusplus
172 # define L4_NOTHROW__A __attribute__((nothrow))
173 # define L4_NOTHROW
174 # define EXTERN_C_BEGIN
175 # define EXTERN_C_END
176 # define EXTERN_C
177 # ifndef __BEGIN_DECLS
178 # define __BEGIN_DECLS
179 # endif
180 # ifndef __END_DECLS
181 # define __END_DECLS
182 # endif
183 # define L4_DEFAULT_PARAM(x)
184 #else /* __cplusplus */
185 # define L4_NOTHROW throw()
186 # define EXTERN_C_BEGIN extern "C" {
187 # define EXTERN_C_END }
188 # define EXTERN_C extern "C"
189 # ifndef __BEGIN_DECLS
190 # define __BEGIN_DECLS extern "C" {
191 # endif
192 # ifndef __END_DECLS
193 # define __END_DECLS }
194 # endif
195 # define L4_DEFAULT_PARAM(x) = x
196 #endif /* __cplusplus */
197 
202 #define L4_NORETURN __attribute__((noreturn))
203 
204 #define L4_PURE __attribute__((pure))
205 
210 #define L4_NOINSTRUMENT __attribute__((no_instrument_function))
211 #ifndef L4_HIDDEN
212 # define L4_HIDDEN __attribute__((visibility("hidden")))
213 #endif
214 #ifndef L4_EXPORT
215 # define L4_EXPORT __attribute__((visibility("default")))
216 #endif
217 #ifndef L4_EXPORT_TYPE
218 # ifdef __cplusplus
219 # define L4_EXPORT_TYPE __attribute__((visibility("default")))
220 # else
221 # define L4_EXPORT_TYPE
222 # endif
223 #endif
224 #define L4_STRONG_ALIAS(name, aliasname) L4__STRONG_ALIAS(name, aliasname)
225 #define L4__STRONG_ALIAS(name, aliasname) \
226  extern __typeof (name) aliasname __attribute__ ((alias (#name)));
227 
228 
229 #endif /* !__ASSEMBLY__ */
230 
231 #include <l4/sys/linkage.h>
232 
233 #define L4_LIKELY(x) __builtin_expect((x),1)
234 #define L4_UNLIKELY(x) __builtin_expect((x),0)
235 
236 /* Make sure that the function is not removed by optimization. Without the
237  * "used" attribute, unreferenced static functions are removed. */
238 #define L4_STICKY(x) __attribute__((used)) x
239 #define L4_DEPRECATED(s) __attribute__((deprecated(s)))
240 
241 #ifndef __GXX_EXPERIMENTAL_CXX0X__
242 #ifndef static_assert
243 #define static_assert(x, y) \
244  do { (void)sizeof(char[-(!(x))]); } while (0)
245 #endif
246 #endif
247 
248 #define L4_stringify_helper(x) #x
249 #define L4_stringify(x) L4_stringify_helper(x)
250 
251 #ifndef __ASSEMBLER__
252 
255 L4_INLINE void l4_barrier(void);
256 
260 L4_INLINE void l4_mb(void);
261 
265 L4_INLINE void l4_wmb(void);
266 
267 
268 /* Implementations */
269 L4_INLINE void l4_barrier(void)
270 {
271  __asm__ __volatile__ ("" : : : "memory");
272 }
273 
274 L4_INLINE void l4_mb(void)
275 {
276  __asm__ __volatile__ ("" : : : "memory");
277 }
278 
279 L4_INLINE void l4_wmb(void)
280 {
281  __asm__ __volatile__ ("" : : : "memory");
282 }
283 #endif
284 
287 #endif /* !__L4_COMPILER_H__ */
void l4_mb(void)
Memory barrier.
Definition: compiler.h:274
void l4_wmb(void)
Write memory barrier.
Definition: compiler.h:279
void l4_barrier(void)
Memory barrier.
Definition: compiler.h:269