2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Takes a pointer x and transform it so we can use it to access members
26 * without a function call. Here an example:
28 * #define GET_SIZE(x) LTTNG_REF(x)->size
30 * struct { int size; } s;
32 * printf("size : %d\n", GET_SIZE(&s));
34 * For this example we can't use something like this for compatibility purpose
35 * since this will fail:
37 * #define GET_SIZE(x) x->size;
39 * This is mostly use for the compatibility layer of lttng-tools. See
40 * poll/epoll for a good example. Since x can be on the stack or allocated
41 * memory using malloc(), we must use generic accessors for compat in order to
42 * *not* use a function to access members and not the variable name.
44 #define LTTNG_REF(x) ((typeof(*x) *)(x))
47 * Memory allocation zeroed
49 #define zmalloc(x) calloc(1, x)
52 #define ARRAY_SIZE(array) (sizeof(array) / (sizeof((array)[0])))
56 #define max(a, b) ((a) > (b) ? (a) : (b))
60 #define max_t(type, a, b) ((type) max(a, b))
64 #define min(a, b) ((a) < (b) ? (a) : (b))
68 #define LTTNG_PACKED __attribute__((__packed__))
72 #define LTTNG_HIDDEN __attribute__((visibility("hidden")))
75 #endif /* _MACROS_H */
This page took 0.03191 seconds and 4 git commands to generate.