summaryrefslogtreecommitdiff
path: root/lib/bt/esp_ble_mesh/common/include/mesh/compiler.h
blob: c73e8dfbc06cffb4cf95e72c6ea80cef8e403d91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * SPDX-FileCopyrightText: 2010-2014,2017 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef _BLE_MESH_COMPILER_H_
#define _BLE_MESH_COMPILER_H_

#ifdef __cplusplus
extern "C" {
#endif

#define ___in_section(a, b, c)

#define __in_section(a, b, c) ___in_section(a, b, c)

#define __in_section_unique(seg) ___in_section(seg, __FILE__, __COUNTER__)

#ifndef __packed
#define __packed        __attribute__((__packed__))
#endif

#ifndef __aligned
#define __aligned(x)    __attribute__((__aligned__(x)))
#endif

#ifndef __used
#define __used          __attribute__((__used__))
#endif

#ifndef ARG_UNUSED
#define ARG_UNUSED(x)   (void)(x)
#endif

#ifndef popcount
#define popcount(x)     __builtin_popcount(x)
#endif

#ifndef ALWAYS_INLINE
#define ALWAYS_INLINE inline __attribute__((always_inline))
#endif


/*
 * This is meant to be used in conjunction with __in_section() and similar
 * where scattered structure instances are concatened together by the linker
 * and walked by the code at run time just like a contiguous array of such
 * structures.
 *
 * Assemblers and linkers may insert alignment padding by default whose
 * size is larger than the natural alignment for those structures when
 * gathering various section segments together, messing up the array walk.
 * To prevent this, we need to provide an explicit alignment not to rely
 * on the default that might just work by luck.
 *
 * Alignment statements in  linker scripts are not sufficient as
 * the assembler may add padding by itself to each segment when switching
 * between sections within the same file even if it merges many such segments
 * into a single section in the end.
 */
#ifndef Z_DECL_ALIGN
#define Z_DECL_ALIGN(type) __aligned(__alignof(type)) type
#endif

/*
 * Convenience helper combining __in_section() and Z_DECL_ALIGN().
 * The section name is the struct type prepended with an underscore.
 * The subsection is "static" and the subsubsection is the variable name.
 */
#ifndef Z_STRUCT_SECTION_ITERABLE
#define Z_STRUCT_SECTION_ITERABLE(struct_type, name) \
        Z_DECL_ALIGN(struct struct_type) name
#endif

#ifdef __cplusplus
}
#endif

#endif /* _BLE_MESH_COMPILER_H_ */