Jens Axboe | 4fee809 | 2007-03-29 09:33:03 +0200 | [diff] [blame] | 1 | #ifndef FIO_COMPILER_H |
| 2 | #define FIO_COMPILER_H |
| 3 | |
| 4 | #if __GNUC__ >= 4 |
| 5 | #include "compiler-gcc4.h" |
Jens Axboe | 73e07ac | 2007-03-29 09:33:46 +0200 | [diff] [blame] | 6 | #elif __GNUC__ == 3 |
Jens Axboe | 4fee809 | 2007-03-29 09:33:03 +0200 | [diff] [blame] | 7 | #include "compiler-gcc3.h" |
| 8 | #else |
| 9 | #error Compiler too old, need gcc at least gcc 3.x |
| 10 | #endif |
| 11 | |
Jens Axboe | 993cca0 | 2007-03-29 09:35:35 +0200 | [diff] [blame] | 12 | #ifndef __must_check |
| 13 | #define __must_check |
| 14 | #endif |
| 15 | |
Jens Axboe | 7b4203d | 2013-04-17 19:29:37 +0200 | [diff] [blame] | 16 | /* |
| 17 | * Mark unused variables passed to ops functions as unused, to silence gcc |
| 18 | */ |
| 19 | #define fio_unused __attribute__((__unused__)) |
| 20 | #define fio_init __attribute__((constructor)) |
| 21 | #define fio_exit __attribute__((destructor)) |
| 22 | |
Jens Axboe | 225ba9e | 2014-02-26 14:31:15 -0800 | [diff] [blame] | 23 | #define fio_unlikely(x) __builtin_expect(!!(x), 0) |
| 24 | |
Jens Axboe | 6cac1b6 | 2014-07-01 08:46:44 -0600 | [diff] [blame] | 25 | /* |
| 26 | * Check at compile time that something is of a particular type. |
| 27 | * Always evaluates to 1 so you may use it easily in comparisons. |
| 28 | */ |
| 29 | #define typecheck(type,x) \ |
| 30 | ({ type __dummy; \ |
| 31 | typeof(x) __dummy2; \ |
| 32 | (void)(&__dummy == &__dummy2); \ |
| 33 | 1; \ |
| 34 | }) |
| 35 | |
Jens Axboe | 3d225d0 | 2014-10-20 10:51:24 -0600 | [diff] [blame^] | 36 | #ifndef __compiletime_error |
| 37 | #define __compiletime_error(message) |
| 38 | #endif |
| 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 | |
Jens Axboe | 4fee809 | 2007-03-29 09:33:03 +0200 | [diff] [blame] | 58 | #endif |