Fix: Allocate stream hash table in respective threads
[lttng-tools.git] / src / common / macros.h
CommitLineData
990570ed
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
d14d33bf
AM
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.
990570ed
DG
8 *
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
d14d33bf 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
990570ed
DG
12 * more details.
13 *
d14d33bf
AM
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.
990570ed
DG
17 */
18
19#ifndef _MACROS_H
20#define _MACROS_H
21
22#include <stdlib.h>
23
24/*
25 * Takes a pointer x and transform it so we can use it to access members
26 * without a function call. Here an example:
27 *
28 * #define GET_SIZE(x) LTTNG_REF(x)->size
29 *
30 * struct { int size; } s;
31 *
32 * printf("size : %d\n", GET_SIZE(&s));
33 *
34 * For this example we can't use something like this for compatibility purpose
35 * since this will fail:
36 *
37 * #define GET_SIZE(x) x->size;
38 *
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.
43 */
44#define LTTNG_REF(x) ((typeof(*x) *)(x))
45
46/*
47 * Memory allocation zeroed
48 */
49#define zmalloc(x) calloc(1, x)
50
51#ifndef ARRAY_SIZE
52#define ARRAY_SIZE(array) (sizeof(array) / (sizeof((array)[0])))
53#endif
54
cf3f19ae
SM
55#ifndef max
56#define max(a, b) ((a) > (b) ? (a) : (b))
57#endif
58
59#ifndef min
60#define min(a, b) ((a) < (b) ? (a) : (b))
61#endif
62
990570ed 63#endif /* _MACROS_H */
This page took 0.032547 seconds and 4 git commands to generate.