Disallow offload IO mode for engines marked with FIO_NO_OFFLOAD
[fio.git] / compiler / compiler.h
CommitLineData
4fee8096
JA
1#ifndef FIO_COMPILER_H
2#define FIO_COMPILER_H
3
0e7e0725
BVA
4#define __must_check __attribute__((warn_unused_result))
5
6#define __compiletime_warning(message) __attribute__((warning(message)))
7#define __compiletime_error(message) __attribute__((error(message)))
993cca04 8
7b4203d7
JA
9/*
10 * Mark unused variables passed to ops functions as unused, to silence gcc
11 */
12#define fio_unused __attribute__((__unused__))
13#define fio_init __attribute__((constructor))
14#define fio_exit __attribute__((destructor))
15
225ba9e3
JA
16#define fio_unlikely(x) __builtin_expect(!!(x), 0)
17
ff8039b7
JA
18/*
19 * Check at compile time that something is of a particular type.
20 * Always evaluates to 1 so you may use it easily in comparisons.
21 */
22#define typecheck(type,x) \
23({ type __dummy; \
3376ecf4 24 __typeof__(x) __dummy2; \
ff8039b7
JA
25 (void)(&__dummy == &__dummy2); \
26 1; \
27})
28
5018f79f
AH
29
30#if defined(CONFIG_STATIC_ASSERT)
31#define compiletime_assert(condition, msg) _Static_assert(condition, msg)
32
484817a9
JA
33#elif !defined(CONFIG_DISABLE_OPTIMIZATIONS)
34
029716a2
JA
35#ifndef __compiletime_error
36#define __compiletime_error(message)
37#endif
484817a9 38
029716a2
JA
39#ifndef __compiletime_error_fallback
40#define __compiletime_error_fallback(condition) do { } while (0)
41#endif
42
43#define __compiletime_assert(condition, msg, prefix, suffix) \
44 do { \
45 int __cond = !(condition); \
46 extern void prefix ## suffix(void) __compiletime_error(msg); \
47 if (__cond) \
48 prefix ## suffix(); \
49 __compiletime_error_fallback(__cond); \
50 } while (0)
51
52#define _compiletime_assert(condition, msg, prefix, suffix) \
53 __compiletime_assert(condition, msg, prefix, suffix)
54
55#define compiletime_assert(condition, msg) \
56 _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
57
484817a9
JA
58#else
59
60#define compiletime_assert(condition, msg) do { } while (0)
61
4fee8096 62#endif
5018f79f 63
c26438ad
JA
64#ifdef FIO_INTERNAL
65#define ARRAY_SIZE(x) (sizeof((x)) / (sizeof((x)[0])))
3376ecf4 66#define FIELD_SIZE(s, f) (sizeof(((__typeof__(s))0)->f))
c26438ad
JA
67#endif
68
db83b0ab
JA
69#ifndef __has_attribute
70#define __GCC4_has_attribute___fallthrough__ 0
71#endif
72
73#if __has_attribute(__fallthrough__)
74#define fallthrough __attribute__((__fallthrough__))
75#else
76#define fallthrough do {} while (0) /* fallthrough */
77#endif
78
5018f79f 79#endif