config.hxx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // Copyright (C) 2009-2017, Vaclav Haisman. All rights reserved.
  2. //
  3. // Redistribution and use in source and binary forms, with or without modifica-
  4. // tion, are permitted provided that the following conditions are met:
  5. //
  6. // 1. Redistributions of source code must retain the above copyright notice,
  7. // this list of conditions and the following disclaimer.
  8. //
  9. // 2. Redistributions in binary form must reproduce the above copyright notice,
  10. // this list of conditions and the following disclaimer in the documentation
  11. // and/or other materials provided with the distribution.
  12. //
  13. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  14. // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  15. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16. // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  17. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  18. // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  19. // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. #ifndef LOG4CPLUS_CONFIG_HXX
  24. #define LOG4CPLUS_CONFIG_HXX
  25. #if defined (_WIN32)
  26. # include <log4cplus/config/win32.h>
  27. #elif (defined(__MWERKS__) && defined(__MACOS__))
  28. # include <log4cplus/config/macosx.h>
  29. #else
  30. # include <log4cplus/config/defines.hxx>
  31. #endif
  32. # if ! defined (LOG4CPLUS_WORKING_LOCALE) \
  33. && ! defined (LOG4CPLUS_WORKING_C_LOCALE) \
  34. && ! defined (LOG4CPLUS_WITH_ICONV)
  35. # define LOG4CPLUS_POOR_MANS_CHCONV
  36. #endif
  37. #ifndef LOG4CPLUS_DECLSPEC_EXPORT
  38. #define LOG4CPLUS_DECLSPEC_EXPORT /* empty */
  39. #endif
  40. #ifndef LOG4CPLUS_DECLSPEC_IMPORT
  41. #define LOG4CPLUS_DECLSPEC_IMPORT /* empty */
  42. #endif
  43. #ifndef LOG4CPLUS_DECLSPEC_PRIVATE
  44. #define LOG4CPLUS_DECLSPEC_PRIVATE /* empty */
  45. #endif
  46. #define LOG4CPLUS_PRIVATE LOG4CPLUS_DECLSPEC_PRIVATE
  47. #if !defined(_WIN32)
  48. # define LOG4CPLUS_USE_BSD_SOCKETS
  49. # if !defined(LOG4CPLUS_SINGLE_THREADED)
  50. # define LOG4CPLUS_USE_PTHREADS
  51. # endif
  52. # if defined (INSIDE_LOG4CPLUS)
  53. # define LOG4CPLUS_EXPORT LOG4CPLUS_DECLSPEC_EXPORT
  54. # else
  55. # define LOG4CPLUS_EXPORT LOG4CPLUS_DECLSPEC_IMPORT
  56. # endif // defined (INSIDE_LOG4CPLUS)
  57. #endif // !_WIN32
  58. #if defined (LOG4CPLUS_INLINES_ARE_EXPORTED) \
  59. && defined (LOG4CPLUS_BUILD_DLL)
  60. # define LOG4CPLUS_INLINE_EXPORT inline
  61. #else
  62. # define LOG4CPLUS_INLINE_EXPORT
  63. #endif
  64. #if defined (UNICODE)
  65. # if defined (_MSC_VER) && _MSC_VER >= 1400
  66. # define LOG4CPLUS_FSTREAM_ACCEPTS_WCHAR_T
  67. # endif
  68. # if defined (_MSC_VER) && _MSC_VER >= 1600
  69. # define LOG4CPLUS_HAVE_CODECVT_UTF8_FACET
  70. # define LOG4CPLUS_HAVE_CODECVT_UTF16_FACET
  71. # endif
  72. #endif
  73. // C++11 stuff
  74. #if ! defined (__has_feature)
  75. //! __has_feature(X) is Clangs way for testing features.
  76. //! Define it to 0 if it does not exist.
  77. # define __has_feature(X) 0
  78. #endif
  79. #if __has_feature (cxx_noexcept) \
  80. || (defined (__GNUC__) \
  81. && (__GNUC__ > 4 \
  82. || __GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \
  83. || (defined (_MSC_VER) && _MSC_VER >= 1900)
  84. # define LOG4CPLUS_NOEXCEPT noexcept
  85. # define LOG4CPLUS_NOEXCEPT_FALSE noexcept(false)
  86. #else
  87. # define LOG4CPLUS_NOEXCEPT /* empty */
  88. # define LOG4CPLUS_NOEXCEPT_FALSE /* empty */
  89. #endif
  90. #if ! defined (UNICODE) && defined (__GNUC__) && __GNUC__ >= 3
  91. # define LOG4CPLUS_FORMAT_ATTRIBUTE(archetype, format_index, first_arg_index) \
  92. __attribute__ ((format (archetype, format_index, first_arg_index)))
  93. #else
  94. # define LOG4CPLUS_FORMAT_ATTRIBUTE(archetype, fmt_index, first_arg_index) \
  95. /* empty */
  96. #endif
  97. #if defined (__GNUC__) \
  98. && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) \
  99. && ! defined (__INTEL_COMPILER) \
  100. && ! defined (__CUDACC__)
  101. # define LOG4CPLUS_CALLER_FILE() __builtin_FILE ()
  102. # define LOG4CPLUS_CALLER_LINE() __builtin_LINE ()
  103. # define LOG4CPLUS_CALLER_FUNCTION() __builtin_FUNCTION ()
  104. #else
  105. # define LOG4CPLUS_CALLER_FILE() (nullptr)
  106. # define LOG4CPLUS_CALLER_LINE() (-1)
  107. # define LOG4CPLUS_CALLER_FUNCTION() (nullptr)
  108. #endif
  109. #if defined (__GNUC__) && __GNUC__ >= 3
  110. # define LOG4CPLUS_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
  111. # define LOG4CPLUS_ATTRIBUTE_PURE __attribute__ ((__pure__))
  112. # define LOG4CPLUS_ATTRIBUTE_DEPRECATED __attribute__ ((__deprecated__))
  113. # define LOG4CPLUS_BUILTIN_EXPECT(exp, c) __builtin_expect ((exp), (c))
  114. #else
  115. # if ! defined (LOG4CPLUS_ATTRIBUTE_NORETURN)
  116. # define LOG4CPLUS_ATTRIBUTE_NORETURN /* empty */
  117. # endif
  118. # define LOG4CPLUS_ATTRIBUTE_PURE /* empty */
  119. # define LOG4CPLUS_ATTRIBUTE_DEPRECATED /* empty */
  120. # define LOG4CPLUS_BUILTIN_EXPECT(exp, c) (exp)
  121. #endif
  122. #define LOG4CPLUS_LIKELY(cond) LOG4CPLUS_BUILTIN_EXPECT(!! (cond), 1)
  123. #define LOG4CPLUS_UNLIKELY(cond) LOG4CPLUS_BUILTIN_EXPECT(!! (cond), 0)
  124. #if defined (_MSC_VER) \
  125. || (defined (__BORLANDC__) && __BORLANDC__ >= 0x0650) \
  126. || (defined (__COMO__) && __COMO_VERSION__ >= 400) /* ??? */ \
  127. || (defined (__DMC__) && __DMC__ >= 0x700) /* ??? */ \
  128. || (defined (__clang__) && __clang_major__ >= 3) \
  129. || (defined (__GNUC__) && (__GNUC__ >= 4 \
  130. || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)))
  131. # define LOG4CPLUS_HAVE_PRAGMA_ONCE
  132. # pragma once
  133. #endif
  134. #if defined (LOG4CPLUS_HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR_PRIORITY)
  135. # define LOG4CPLUS_CONSTRUCTOR_FUNC(prio) \
  136. __attribute__ ((__constructor__ ((prio))))
  137. #elif defined (LOG4CPLUS_HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR)
  138. # define LOG4CPLUS_CONSTRUCTOR_FUNC(prio) \
  139. __attribute__ ((__constructor__))
  140. #else
  141. # define LOG4CPLUS_CONSTRUCTOR_FUNC(prio) /* empty */
  142. #endif
  143. #if defined (LOG4CPLUS_HAVE_VAR_ATTRIBUTE_INIT_PRIORITY)
  144. # define LOG4CPLUS_INIT_PRIORITY(prio) \
  145. __attribute__ ((__init_priority__ ((prio))))
  146. #else
  147. # define LOG4CPLUS_INIT_PRIORITY(prio) /* empty */
  148. #endif
  149. #define LOG4CPLUS_INIT_PRIORITY_BASE (65535 / 2)
  150. #include <log4cplus/helpers/thread-config.h>
  151. #if defined (LOG4CPLUS_SINGLE_THREADED)
  152. #define LOG4CPLUS_THREADED(x)
  153. #else
  154. #define LOG4CPLUS_THREADED(x) x
  155. #endif
  156. #if defined(__cplusplus)
  157. #include <cstddef>
  158. namespace log4cplus
  159. {
  160. //! Per thread cleanup function. Users should call this function before
  161. //! a thread ends its execution. It frees resources allocated in thread local
  162. //! storage. It is important only for multi-threaded static library builds
  163. //! of log4cplus and user threads. In all other cases the clean up is provided
  164. //! automatically by other means.
  165. LOG4CPLUS_EXPORT void threadCleanup ();
  166. //! Initializes log4cplus.
  167. //!
  168. //! \note using `log4cplus::Initializer` is preferred
  169. LOG4CPLUS_EXPORT void initialize ();
  170. //! Deinitializes log4cplus.
  171. //!
  172. //! \note using `log4cplus::Initializer` is preferred
  173. LOG4CPLUS_EXPORT void deinitialize ();
  174. //! Set thread pool size.
  175. LOG4CPLUS_EXPORT void setThreadPoolSize (std::size_t pool_size);
  176. //! Set behaviour on full thread pool queue. Default is to block.
  177. LOG4CPLUS_EXPORT void setThreadPoolBlockOnFull (bool block);
  178. //! Set thread pool queue size limit.
  179. LOG4CPLUS_EXPORT void setThreadPoolQueueSizeLimit (std::size_t queue_size_limit);
  180. } // namespace log4cplus
  181. #endif
  182. #endif // LOG4CPLUS_CONFIG_HXX