Fix: Lock FD tracker across fork
[lttng-ust.git] / include / lttng / bug.h
1 #ifndef _LTTNG_BUG_H
2 #define _LTTNG_BUG_H
3
4 /*
5 * lttng/bug.h
6 *
7 * (C) Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28 #include <urcu/compiler.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31
32 #define LTTNG_BUG_ON(condition) \
33 do { \
34 if (caa_unlikely(condition)) { \
35 fprintf(stderr, \
36 "LTTng BUG in file %s, line %d.\n", \
37 __FILE__, __LINE__); \
38 exit(EXIT_FAILURE); \
39 } \
40 } while (0)
41
42 #define LTTNG_BUILD_BUG_ON(condition) \
43 ((void) sizeof(char[-!!(condition)]))
44
45 /**
46 * LTTNG_BUILD_RUNTIME_BUG_ON - check condition at build (if constant) or runtime
47 * @condition: the condition which should be false.
48 *
49 * If the condition is a constant and true, the compiler will generate a build
50 * error. If the condition is not constant, a BUG will be triggered at runtime
51 * if the condition is ever true. If the condition is constant and false, no
52 * code is emitted.
53 */
54 #define LTTNG_BUILD_RUNTIME_BUG_ON(condition) \
55 do { \
56 if (__builtin_constant_p(condition)) \
57 LTTNG_BUILD_BUG_ON(condition); \
58 else \
59 LTTNG_BUG_ON(condition); \
60 } while (0)
61
62 #endif
This page took 0.053986 seconds and 4 git commands to generate.