lib: add internal object pool API and use it; adapt plugins/tests
[babeltrace.git] / include / babeltrace / babeltrace-internal.h
1 #ifndef _BABELTRACE_INTERNAL_H
2 #define _BABELTRACE_INTERNAL_H
3
4 /*
5 * babeltrace/babeltrace-internal.h
6 *
7 * Copyright 2012 - 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 #include <stdio.h>
28 #include <glib.h>
29 #include <stdint.h>
30 #include <stdlib.h>
31 #include <errno.h>
32 #include <babeltrace/compat/string-internal.h>
33 #include <babeltrace/types.h>
34
35 #define PERROR_BUFLEN 200
36
37 #ifndef likely
38 # ifdef __GNUC__
39 # define likely(x) __builtin_expect(!!(x), 1)
40 # else
41 # define likely(x) (!!(x))
42 # endif
43 #endif
44
45 #ifndef unlikely
46 # ifdef __GNUC__
47 # define unlikely(x) __builtin_expect(!!(x), 0)
48 # else
49 # define unlikely(x) (!!(x))
50 # endif
51 #endif
52
53 #ifndef min
54 #define min(a, b) (((a) < (b)) ? (a) : (b))
55 #endif
56
57 #ifndef max
58 #define max(a, b) (((a) > (b)) ? (a) : (b))
59 #endif
60
61 #ifndef max_t
62 #define max_t(type, a, b) \
63 ((type) (a) > (type) (b) ? (type) (a) : (type) (b))
64 #endif
65
66 /*
67 * Memory allocation zeroed
68 */
69 #define zmalloc(x) calloc(1, x)
70
71 /*
72 * BT_HIDDEN: set the hidden attribute for internal functions
73 * On Windows, symbols are local unless explicitly exported,
74 * see https://gcc.gnu.org/wiki/Visibility
75 */
76 #if defined(_WIN32) || defined(__CYGWIN__)
77 #define BT_HIDDEN
78 #else
79 #define BT_HIDDEN __attribute__((visibility("hidden")))
80 #endif
81
82 #ifndef __STRINGIFY
83 #define __STRINGIFY(x) #x
84 #endif
85
86 #define TOSTRING(x) __STRINGIFY(x)
87
88 #define BT_UNUSED __attribute__((unused))
89
90 #endif
This page took 0.030145 seconds and 4 git commands to generate.