Circular linked-list implementation
[libside.git] / include / side / macros.h
CommitLineData
f611d0c3
MD
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/* Helper macros */
10
11#define SIDE_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
12
13/*
14 * Compound literals with static storage are needed by SIDE
15 * instrumentation.
16 * Compound literals are part of the C99 and C11 standards, but not
17 * part of the C++ standards. They are supported by most C++ compilers
18 * though.
19 *
20 * Example use:
21 * static struct mystruct *var = LTTNG_UST_COMPOUND_LITERAL(struct mystruct, { 1, 2, 3 });
22 */
23#define SIDE_COMPOUND_LITERAL(type, ...) (type[]) { __VA_ARGS__ }
24
25#define side_likely(x) __builtin_expect(!!(x), 1)
26#define side_unlikely(x) __builtin_expect(!!(x), 0)
27
28#define SIDE_PARAM(...) __VA_ARGS__
29
b59abc69
MD
30/*
31 * side_container_of - Get the address of an object containing a field.
32 *
33 * @ptr: pointer to the field.
34 * @type: type of the object.
35 * @member: name of the field within the object.
36 */
37#define side_container_of(ptr, type, member) \
38 __extension__ \
39 ({ \
40 const __typeof__(((type *) NULL)->member) * __ptr = (ptr); \
41 (type *)((char *)__ptr - offsetof(type, member)); \
42 })
43
f611d0c3 44#endif /* _SIDE_MACROS_H */
This page took 0.042556 seconds and 4 git commands to generate.