workaround.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2015. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_DETAIL_WORKAROUND_HPP
  11. #define BOOST_INTERPROCESS_DETAIL_WORKAROUND_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #
  16. #if defined(BOOST_HAS_PRAGMA_ONCE)
  17. # pragma once
  18. #endif
  19. #if defined(BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION) && defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)
  20. #error "BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION && BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION can't be defined at the same time"
  21. #endif
  22. //#define BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION
  23. #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
  24. #define BOOST_INTERPROCESS_WINDOWS
  25. #if !defined(BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION) && !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)
  26. #define BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION
  27. #endif
  28. #define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
  29. #else
  30. #include <unistd.h>
  31. //////////////////////////////////////////////////////
  32. //Check for XSI shared memory objects. They are available in nearly all UNIX platforms
  33. //////////////////////////////////////////////////////
  34. #if !defined(__QNXNTO__) && !defined(__ANDROID__) && !defined(__HAIKU__) && !(__VXWORKS__)
  35. #define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
  36. #endif
  37. //////////////////////////////////////////////////////
  38. // From SUSv3/UNIX 98, pthread_mutexattr_settype is mandatory
  39. //////////////////////////////////////////////////////
  40. #if defined(_XOPEN_UNIX) && ((_XOPEN_VERSION + 0) >= 500)
  41. #define BOOST_INTERPROCESS_POSIX_RECURSIVE_MUTEXES
  42. #endif
  43. //////////////////////////////////////////////////////
  44. // _POSIX_THREAD_PROCESS_SHARED (POSIX.1b/POSIX.4)
  45. //////////////////////////////////////////////////////
  46. #if defined(_POSIX_THREAD_PROCESS_SHARED) && ((_POSIX_THREAD_PROCESS_SHARED + 0) > 0)
  47. //Cygwin defines _POSIX_THREAD_PROCESS_SHARED but does not implement it.
  48. #if defined(__CYGWIN__)
  49. #define BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED
  50. #elif defined(__APPLE__)
  51. //The pthreads implementation of darwin stores a pointer to a mutex inside the condition
  52. //structure so real sharing between processes is broken. See:
  53. //https://opensource.apple.com/source/libpthread/libpthread-301.30.1/src/pthread_cond.c.auto.html
  54. //in method pthread_cond_wait
  55. #define BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED
  56. #endif
  57. //If buggy _POSIX_THREAD_PROCESS_SHARED is detected avoid using it
  58. #if defined(BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED)
  59. #undef BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED
  60. #else
  61. #define BOOST_INTERPROCESS_POSIX_PROCESS_SHARED
  62. #endif
  63. #endif
  64. //////////////////////////////////////////////////////
  65. // _POSIX_SHARED_MEMORY_OBJECTS (POSIX.1b/POSIX.4)
  66. //////////////////////////////////////////////////////
  67. #if ( defined(_POSIX_SHARED_MEMORY_OBJECTS) && ((_POSIX_SHARED_MEMORY_OBJECTS + 0) > 0) ) ||\
  68. (defined(__vms) && __CRTL_VER >= 70200000)
  69. #define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
  70. //Some systems have filesystem-based resources, so the
  71. //portable "/shmname" format does not work due to permission issues
  72. //For those systems we need to form a path to a temporary directory:
  73. // hp-ux tru64 vms freebsd
  74. #if defined(__hpux) || defined(__osf__) || defined(__vms) || (defined(__FreeBSD__) && (__FreeBSD__ < 7))
  75. #define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
  76. //Some systems have "jailed" environments where shm usage is restricted at runtime
  77. //and temporary file based shm is possible in those executions.
  78. #elif defined(__FreeBSD__)
  79. #define BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
  80. #endif
  81. #endif
  82. //////////////////////////////////////////////////////
  83. // _POSIX_MAPPED_FILES (POSIX.1b/POSIX.4)
  84. //////////////////////////////////////////////////////
  85. #if defined(_POSIX_MAPPED_FILES) && ((_POSIX_MAPPED_FILES + 0) > 0)
  86. #define BOOST_INTERPROCESS_POSIX_MAPPED_FILES
  87. #endif
  88. //////////////////////////////////////////////////////
  89. // _POSIX_SEMAPHORES (POSIX.1b/POSIX.4)
  90. //////////////////////////////////////////////////////
  91. #if ( defined(_POSIX_SEMAPHORES) && ((_POSIX_SEMAPHORES + 0) > 0) ) ||\
  92. ( defined(__FreeBSD__) && (__FreeBSD__ >= 4)) || \
  93. defined(__APPLE__)
  94. #define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
  95. //MacOsX declares _POSIX_SEMAPHORES but sem_init returns ENOSYS
  96. #if !defined(__APPLE__)
  97. #define BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES
  98. #endif
  99. #if defined(__osf__) || defined(__vms)
  100. #define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
  101. #endif
  102. #endif
  103. //////////////////////////////////////////////////////
  104. // _POSIX_BARRIERS (SUSv3/Unix03)
  105. //////////////////////////////////////////////////////
  106. #if defined(_POSIX_BARRIERS) && ((_POSIX_BARRIERS + 0) >= 200112L)
  107. #define BOOST_INTERPROCESS_POSIX_BARRIERS
  108. #endif
  109. //////////////////////////////////////////////////////
  110. // _POSIX_TIMEOUTS (SUSv3/Unix03)
  111. //////////////////////////////////////////////////////
  112. #if defined(_POSIX_TIMEOUTS) && ((_POSIX_TIMEOUTS + 0L) >= 200112L)
  113. #define BOOST_INTERPROCESS_POSIX_TIMEOUTS
  114. #endif
  115. //////////////////////////////////////////////////////
  116. // Detect BSD derivatives to detect sysctl
  117. //////////////////////////////////////////////////////
  118. #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
  119. #define BOOST_INTERPROCESS_BSD_DERIVATIVE
  120. //Some *BSD systems (OpenBSD & NetBSD) need sys/param.h before sys/sysctl.h, whereas
  121. //others (FreeBSD & Darwin) need sys/types.h
  122. #include <sys/types.h>
  123. #include <sys/param.h>
  124. #include <sys/sysctl.h>
  125. #if defined(CTL_KERN) && defined (KERN_BOOTTIME)
  126. //#define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
  127. #endif
  128. #endif
  129. //////////////////////////////////////////////////////
  130. //64 bit offset
  131. //////////////////////////////////////////////////////
  132. #if (defined (_V6_ILP32_OFFBIG) &&(_V6_ILP32_OFFBIG - 0 > 0)) ||\
  133. (defined (_V6_LP64_OFF64) &&(_V6_LP64_OFF64 - 0 > 0)) ||\
  134. (defined (_V6_LPBIG_OFFBIG) &&(_V6_LPBIG_OFFBIG - 0 > 0)) ||\
  135. (defined (_XBS5_ILP32_OFFBIG)&&(_XBS5_ILP32_OFFBIG - 0 > 0)) ||\
  136. (defined (_XBS5_LP64_OFF64) &&(_XBS5_LP64_OFF64 - 0 > 0)) ||\
  137. (defined (_XBS5_LPBIG_OFFBIG)&&(_XBS5_LPBIG_OFFBIG - 0 > 0)) ||\
  138. (defined (_FILE_OFFSET_BITS) &&(_FILE_OFFSET_BITS - 0 >= 64))||\
  139. (defined (_FILE_OFFSET_BITS) &&(_FILE_OFFSET_BITS - 0 >= 64))
  140. #define BOOST_INTERPROCESS_UNIX_64_BIT_OR_BIGGER_OFF_T
  141. #endif
  142. //////////////////////////////////////////////////////
  143. //posix_fallocate
  144. //////////////////////////////////////////////////////
  145. #if (_XOPEN_SOURCE >= 600 || __POSIX_C_SOURCE >= 200112L)
  146. #define BOOST_INTERPROCESS_POSIX_FALLOCATE
  147. #endif
  148. #endif //!defined(BOOST_INTERPROCESS_WINDOWS)
  149. #if defined(BOOST_INTERPROCESS_WINDOWS) || defined(BOOST_INTERPROCESS_POSIX_MAPPED_FILES)
  150. # define BOOST_INTERPROCESS_MAPPED_FILES
  151. #endif
  152. //Now declare some Boost.Interprocess features depending on the implementation
  153. #if defined(BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES) && !defined(BOOST_INTERPROCESS_POSIX_SEMAPHORES_NO_UNLINK)
  154. #define BOOST_INTERPROCESS_NAMED_MUTEX_USES_POSIX_SEMAPHORES
  155. #define BOOST_INTERPROCESS_NAMED_SEMAPHORE_USES_POSIX_SEMAPHORES
  156. #endif
  157. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  158. #define BOOST_INTERPROCESS_PERFECT_FORWARDING
  159. #endif
  160. // Timeout duration use if BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING is set
  161. #ifndef BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS
  162. #define BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS 10000
  163. #endif
  164. //Other switches
  165. //BOOST_INTERPROCESS_MSG_QUEUE_USES_CIRC_INDEX
  166. //message queue uses a circular queue as index instead of an array (better performance)
  167. //Boost version < 1.52 uses an array, so undef this if you want to communicate
  168. //with processes compiled with those versions.
  169. #define BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  170. //Macros for documentation purposes. For code, expands to the argument
  171. #define BOOST_INTERPROCESS_IMPDEF(TYPE) TYPE
  172. #define BOOST_INTERPROCESS_SEEDOC(TYPE) TYPE
  173. #define BOOST_INTERPROCESS_DOC1ST(TYPE1, TYPE2) TYPE2
  174. #define BOOST_INTERPROCESS_I ,
  175. #define BOOST_INTERPROCESS_DOCIGN(T1) T1
  176. //#define BOOST_INTERPROCESS_DISABLE_FORCEINLINE
  177. #if defined(BOOST_INTERPROCESS_DISABLE_FORCEINLINE)
  178. #define BOOST_INTERPROCESS_FORCEINLINE inline
  179. #elif defined(BOOST_INTERPROCESS_FORCEINLINE_IS_BOOST_FORCELINE)
  180. #define BOOST_INTERPROCESS_FORCEINLINE BOOST_FORCEINLINE
  181. #elif defined(BOOST_MSVC) && defined(_DEBUG)
  182. //"__forceinline" and MSVC seems to have some bugs in debug mode
  183. #define BOOST_INTERPROCESS_FORCEINLINE inline
  184. #elif defined(__GNUC__) && ((__GNUC__ < 4) || (__GNUC__ == 4 && (__GNUC_MINOR__ < 5)))
  185. //Older GCCs have problems with forceinline
  186. #define BOOST_INTERPROCESS_FORCEINLINE inline
  187. #else
  188. #define BOOST_INTERPROCESS_FORCEINLINE BOOST_FORCEINLINE
  189. #endif
  190. #ifdef BOOST_WINDOWS
  191. #define BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES
  192. #ifdef __clang__
  193. #define BOOST_INTERPROCESS_DISABLE_DEPRECATED_WARNING _Pragma("clang diagnostic push") \
  194. _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
  195. #define BOOST_INTERPROCESS_RESTORE_WARNING _Pragma("clang diagnostic pop")
  196. #else // __clang__
  197. #define BOOST_INTERPROCESS_DISABLE_DEPRECATED_WARNING __pragma(warning(push)) \
  198. __pragma(warning(disable : 4996))
  199. #define BOOST_INTERPROCESS_RESTORE_WARNING __pragma(warning(pop))
  200. #endif // __clang__
  201. #endif
  202. #endif //#ifndef BOOST_INTERPROCESS_DETAIL_WORKAROUND_HPP