inline_api.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef __ASTERISK_INLINEAPI_H
  19. #define __ASTERISK_INLINEAPI_H
  20. /*! \file
  21. * \brief Inlinable API function macro
  22. Small API functions that are candidates for inlining need to be specially
  23. declared and defined, to ensure that the 'right thing' always happens.
  24. For example:
  25. - there must _always_ be a non-inlined version of the function
  26. available for modules compiled out of the tree to link to
  27. - references to a function that cannot be inlined (for any
  28. reason that the compiler deems proper) must devolve into an
  29. 'extern' reference, instead of 'static', so that multiple
  30. copies of the function body are not built in different modules.
  31. However, since this doesn't work for clang, we go with 'static'
  32. anyway and hope for the best!
  33. - when LOW_MEMORY is defined, inlining should be disabled
  34. completely, even if the compiler is configured to support it
  35. The AST_INLINE_API macro allows this to happen automatically, when
  36. used to define your function. Proper usage is as follows:
  37. - define your function one place, in a header file, using the macro
  38. to wrap the function (see strings.h or time.h for examples)
  39. - choose a module to 'host' the function body for non-inline
  40. usages, and in that module _only_, define AST_API_MODULE before
  41. including the header file
  42. */
  43. #if !defined(LOW_MEMORY) && !defined(DISABLE_INLINE)
  44. #if !defined(AST_API_MODULE)
  45. #if defined(__clang__) || defined(__GNUC_STDC_INLINE__)
  46. #define AST_INLINE_API(hdr, body) static hdr; static inline hdr body
  47. #else /* if defined(__clang__) */
  48. #define AST_INLINE_API(hdr, body) hdr; extern inline hdr body
  49. #endif
  50. #else /* if !defined(AST_API_MODULE) */
  51. #define AST_INLINE_API(hdr, body) hdr; hdr body
  52. #endif
  53. #else /* defined(LOW_MEMORY) */
  54. #if !defined(AST_API_MODULE)
  55. #define AST_INLINE_API(hdr, body) hdr;
  56. #else
  57. #define AST_INLINE_API(hdr, body) hdr; hdr body
  58. #endif
  59. #endif
  60. #undef AST_API_MODULE
  61. #endif /* __ASTERISK_INLINEAPI_H */