1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 #define SIDE_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
17 * Compound literals with static storage are needed by SIDE
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
24 * static struct mystruct *var = LTTNG_UST_COMPOUND_LITERAL(struct mystruct, { 1, 2, 3 });
26 #define SIDE_COMPOUND_LITERAL(type, ...) (type[]) { __VA_ARGS__ }
28 #define side_likely(x) __builtin_expect(!!(x), 1)
29 #define side_unlikely(x) __builtin_expect(!!(x), 0)
31 #define SIDE_PARAM(...) __VA_ARGS__
33 /* Select arg1 in list of arguments. */
34 #define SIDE_PARAM_SELECT_ARG1(_arg0, _arg1, ...) _arg1
37 * Use the default parameter if no additional arguments are provided,
38 .* else use the following arguments. Use inside macros to implement
39 * optional last macro argument.
41 #define SIDE_PARAM_DEFAULT(_default, ...) \
42 SIDE_PARAM_SELECT_ARG1(dummy, ##__VA_ARGS__, _default)
45 * side_container_of - Get the address of an object containing a field.
47 * @ptr: pointer to the field.
48 * @type: type of the object.
49 * @member: name of the field within the object.
51 #define side_container_of(ptr, type, member) \
54 const __typeof__(((type *) NULL)->member) * __ptr = (ptr); \
55 (type *)((char *)__ptr - offsetof(type, member)); \
58 #define side_struct_field_sizeof(_struct, _field) \
59 sizeof(((_struct * )NULL)->_field)
61 #if defined(__SIZEOF_LONG__)
62 #define SIDE_BITS_PER_LONG (__SIZEOF_LONG__ * 8)
64 #define SIDE_BITS_PER_LONG 64
66 #define SIDE_BITS_PER_LONG 32
69 #define SIDE_PACKED __attribute__((packed))
71 #endif /* _SIDE_MACROS_H */
This page took 0.03069 seconds and 4 git commands to generate.