Use 64-bit masks
[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
11 /* Helper macros */
12
13 #define SIDE_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
14
15 /*
16 * Compound literals with static storage are needed by SIDE
17 * instrumentation.
18 * Compound literals are part of the C99 and C11 standards, but not
19 * part of the C++ standards. They are supported by most C++ compilers
20 * though.
21 *
22 * Example use:
23 * static struct mystruct *var = LTTNG_UST_COMPOUND_LITERAL(struct mystruct, { 1, 2, 3 });
24 */
25 #define SIDE_COMPOUND_LITERAL(type, ...) (type[]) { __VA_ARGS__ }
26
27 #define side_likely(x) __builtin_expect(!!(x), 1)
28 #define side_unlikely(x) __builtin_expect(!!(x), 0)
29
30 #define SIDE_PARAM(...) __VA_ARGS__
31
32 /*
33 * side_container_of - Get the address of an object containing a field.
34 *
35 * @ptr: pointer to the field.
36 * @type: type of the object.
37 * @member: name of the field within the object.
38 */
39 #define side_container_of(ptr, type, member) \
40 __extension__ \
41 ({ \
42 const __typeof__(((type *) NULL)->member) * __ptr = (ptr); \
43 (type *)((char *)__ptr - offsetof(type, member)); \
44 })
45
46 #if defined(__SIZEOF_LONG__)
47 #define SIDE_BITS_PER_LONG (__SIZEOF_LONG__ * 8)
48 #elif defined(_LP64)
49 #define SIDE_BITS_PER_LONG 64
50 #else
51 #define SIDE_BITS_PER_LONG 32
52 #endif
53
54 #endif /* _SIDE_MACROS_H */
This page took 0.036044 seconds and 5 git commands to generate.