Asterisk - The Open Source Telephony Project  GIT-master-1b41629
inline_api.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Kevin P. Fleming <kpfleming@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 #ifndef __ASTERISK_INLINEAPI_H
20 #define __ASTERISK_INLINEAPI_H
21 
22 /*! \file
23  * \brief Inlinable API function macro
24 
25  Small API functions that are candidates for inlining need to be specially
26  declared and defined, to ensure that the 'right thing' always happens.
27  For example:
28  - there must _always_ be a non-inlined version of the function
29  available for modules compiled out of the tree to link to
30  - references to a function that cannot be inlined (for any
31  reason that the compiler deems proper) must devolve into an
32  'extern' reference, instead of 'static', so that multiple
33  copies of the function body are not built in different modules.
34  However, since this doesn't work for clang, we go with 'static'
35  anyway and hope for the best!
36  - when DISABLE_INLINE is defined, inlining should be disabled
37  completely, even if the compiler is configured to support it
38 
39  The AST_INLINE_API macro allows this to happen automatically, when
40  used to define your function. Proper usage is as follows:
41  - define your function one place, in a header file, using the macro
42  to wrap the function (see strings.h or time.h for examples)
43  - choose a module to 'host' the function body for non-inline
44  usages, and in that module _only_, define AST_API_MODULE before
45  including the header file
46  */
47 
48 #if !defined(DISABLE_INLINE)
49 
50 #if !defined(AST_API_MODULE)
51 #if defined(__clang__) || defined(__GNUC_STDC_INLINE__)
52 #define AST_INLINE_API(hdr, body) static hdr; static inline hdr body
53 #else /* if defined(__clang__) */
54 #define AST_INLINE_API(hdr, body) hdr; extern inline hdr body
55 #endif
56 #else /* if !defined(AST_API_MODULE) */
57 #define AST_INLINE_API(hdr, body) hdr; hdr body
58 #endif
59 
60 #else /* defined(DISABLE_INLINE) */
61 
62 #if !defined(AST_API_MODULE)
63 #define AST_INLINE_API(hdr, body) hdr;
64 #else
65 #define AST_INLINE_API(hdr, body) hdr; hdr body
66 #endif
67 
68 #endif
69 
70 #undef AST_API_MODULE
71 
72 #endif /* __ASTERISK_INLINEAPI_H */