Revert "Rename "libside" to "libtgif""
[libside.git] / include / side / macros.h
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 */
5
6 #ifndef _SIDE_MACROS_H
7 #define _SIDE_MACROS_H
8
9 #include <stddef.h>
10 #include <limits.h>
11
12 /* Helper macros */
13
14 #define SIDE_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
15
16 /*
17 * Compound literals with static storage are needed by SIDE
18 * instrumentation.
19 * Compound literals are part of the C99 and C11 standards, but not
20 * part of the C++ standards. They are supported by most C++ compilers
21 * though.
22 *
23 * Example use:
24 * static struct mystruct *var = LTTNG_UST_COMPOUND_LITERAL(struct mystruct, { 1, 2, 3 });
25 */
26 #define SIDE_COMPOUND_LITERAL(type, ...) (type[]) { __VA_ARGS__ }
27
28 #define side_likely(x) __builtin_expect(!!(x), 1)
29 #define side_unlikely(x) __builtin_expect(!!(x), 0)
30
31 #define SIDE_PARAM(...) __VA_ARGS__
32
33 /*
34 * side_container_of - Get the address of an object containing a field.
35 *
36 * @ptr: pointer to the field.
37 * @type: type of the object.
38 * @member: name of the field within the object.
39 */
40 #define side_container_of(ptr, type, member) \
41 __extension__ \
42 ({ \
43 const __typeof__(((type *) NULL)->member) * __ptr = (ptr); \
44 (type *)((char *)__ptr - offsetof(type, member)); \
45 })
46
47 #define side_struct_field_sizeof(_struct, _field) \
48 sizeof(((_struct * )NULL)->_field)
49
50 #if defined(__SIZEOF_LONG__)
51 #define SIDE_BITS_PER_LONG (__SIZEOF_LONG__ * 8)
52 #elif defined(_LP64)
53 #define SIDE_BITS_PER_LONG 64
54 #else
55 #define SIDE_BITS_PER_LONG 32
56 #endif
57
58 #define SIDE_PACKED __attribute__((packed))
59
60 #endif /* _SIDE_MACROS_H */
This page took 0.029599 seconds and 4 git commands to generate.