workaround.hpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2012. 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. #include <boost/interprocess/detail/config_begin.hpp>
  13. #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
  14. #define BOOST_INTERPROCESS_WINDOWS
  15. #define BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION
  16. #define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
  17. //Define this to connect with shared memory created with versions < 1.54
  18. //#define BOOST_INTERPROCESS_BOOTSTAMP_IS_LASTBOOTUPTIME
  19. #else
  20. #include <unistd.h>
  21. #if defined(_POSIX_THREAD_PROCESS_SHARED) && ((_POSIX_THREAD_PROCESS_SHARED - 0) > 0)
  22. //Cygwin defines _POSIX_THREAD_PROCESS_SHARED but does not implement it.
  23. #if defined(__CYGWIN__)
  24. #define BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED
  25. //Mac Os X < Lion (10.7) might define _POSIX_THREAD_PROCESS_SHARED but there is no real support.
  26. #elif defined(__APPLE__)
  27. #include "TargetConditionals.h"
  28. //Check we're on Mac OS target
  29. #if defined(TARGET_OS_MAC)
  30. #include "AvailabilityMacros.h"
  31. //If minimum target for this compilation is older than Mac Os Lion, then we are out of luck
  32. #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
  33. #define BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED
  34. #endif
  35. #endif
  36. #endif
  37. //If buggy _POSIX_THREAD_PROCESS_SHARED is detected avoid using it
  38. #if defined(BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED)
  39. #undef BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED
  40. #else
  41. #define BOOST_INTERPROCESS_POSIX_PROCESS_SHARED
  42. #endif
  43. #endif
  44. #if defined(_POSIX_BARRIERS) && ((_POSIX_BARRIERS - 0) > 0)
  45. #define BOOST_INTERPROCESS_POSIX_BARRIERS
  46. #endif
  47. #if defined(_POSIX_SEMAPHORES) && ((_POSIX_SEMAPHORES - 0) > 0)
  48. #define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
  49. #if defined(__CYGWIN__)
  50. #define BOOST_INTERPROCESS_POSIX_SEMAPHORES_NO_UNLINK
  51. #endif
  52. //Some platforms have a limited (name length) named semaphore support
  53. #elif (defined(__FreeBSD__) && (__FreeBSD__ >= 4)) || defined(__APPLE__)
  54. #define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
  55. #endif
  56. #if ((defined _V6_ILP32_OFFBIG) &&(_V6_ILP32_OFFBIG - 0 > 0)) ||\
  57. ((defined _V6_LP64_OFF64) &&(_V6_LP64_OFF64 - 0 > 0)) ||\
  58. ((defined _V6_LPBIG_OFFBIG) &&(_V6_LPBIG_OFFBIG - 0 > 0)) ||\
  59. ((defined _XBS5_ILP32_OFFBIG)&&(_XBS5_ILP32_OFFBIG - 0 > 0)) ||\
  60. ((defined _XBS5_LP64_OFF64) &&(_XBS5_LP64_OFF64 - 0 > 0)) ||\
  61. ((defined _XBS5_LPBIG_OFFBIG)&&(_XBS5_LPBIG_OFFBIG - 0 > 0)) ||\
  62. ((defined _FILE_OFFSET_BITS) &&(_FILE_OFFSET_BITS - 0 >= 64))||\
  63. ((defined _FILE_OFFSET_BITS) &&(_FILE_OFFSET_BITS - 0 >= 64))
  64. #define BOOST_INTERPROCESS_UNIX_64_BIT_OR_BIGGER_OFF_T
  65. #endif
  66. //Check for XSI shared memory objects. They are available in nearly all UNIX platforms
  67. #if !defined(__QNXNTO__)
  68. #define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
  69. #endif
  70. #if defined(_POSIX_SHARED_MEMORY_OBJECTS) && ((_POSIX_SHARED_MEMORY_OBJECTS - 0) > 0)
  71. #define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
  72. #else
  73. //VMS and MACOS don't define it but they have shm_open/close interface
  74. #if defined(__vms)
  75. #if __CRTL_VER >= 70200000
  76. #define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
  77. #endif
  78. //Mac OS has some non-conformant features like names limited to SHM_NAME_MAX
  79. #elif defined (__APPLE__)
  80. //#define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
  81. //#define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS_NO_GROW
  82. #endif
  83. #endif
  84. //Now check if we have only XSI shared memory
  85. #if defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS) &&\
  86. !defined(BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS)
  87. //#define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS_ONLY
  88. #endif
  89. #if defined(_POSIX_TIMEOUTS) && ((_POSIX_TIMEOUTS - 0) > 0)
  90. #define BOOST_INTERPROCESS_POSIX_TIMEOUTS
  91. #endif
  92. #ifdef BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
  93. //Some systems have filesystem-based resources, so the
  94. //portable "/shmname" format does not work due to permission issues
  95. //For those systems we need to form a path to a temporary directory:
  96. // hp-ux tru64 vms freebsd
  97. #if defined(__hpux) || defined(__osf__) || defined(__vms) || (defined(__FreeBSD__) && (__FreeBSD__ < 7))
  98. #define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
  99. //Some systems have "jailed" environments where shm usage is restricted at runtime
  100. //and temporary file file based shm is possible in those executions.
  101. #elif defined(__FreeBSD__)
  102. #define BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
  103. #endif
  104. #endif
  105. #ifdef BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
  106. #if defined(__osf__) || defined(__vms)
  107. #define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
  108. #endif
  109. #endif
  110. #if defined(_POSIX_VERSION) && defined(_XOPEN_VERSION) && \
  111. (((_POSIX_VERSION + 0)>= 200112L || (_XOPEN_VERSION + 0)>= 500))
  112. #define BOOST_INTERPROCESS_POSIX_RECURSIVE_MUTEXES
  113. #endif
  114. #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
  115. #define BOOST_INTERPROCESS_BSD_DERIVATIVE
  116. //Some *BSD systems (OpenBSD & NetBSD) need sys/param.h before sys/sysctl.h, whereas
  117. //others (FreeBSD & Darwin) need sys/types.h
  118. #include <sys/types.h>
  119. #include <sys/param.h>
  120. #include <sys/sysctl.h>
  121. #if defined(CTL_KERN) && defined (KERN_BOOTTIME)
  122. //#define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
  123. #endif
  124. #endif
  125. #endif //!defined(BOOST_INTERPROCESS_WINDOWS)
  126. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  127. #define BOOST_INTERPROCESS_PERFECT_FORWARDING
  128. #endif
  129. //Now declare some Boost.Interprocess features depending on the implementation
  130. #if defined(BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES) && !defined(BOOST_INTERPROCESS_POSIX_SEMAPHORES_NO_UNLINK)
  131. #define BOOST_INTERPROCESS_NAMED_MUTEX_USES_POSIX_SEMAPHORES
  132. #define BOOST_INTERPROCESS_NAMED_SEMAPHORE_USES_POSIX_SEMAPHORES
  133. #endif
  134. // Timeout duration use if BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING is set
  135. #ifndef BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS
  136. #define BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS 10000
  137. #endif
  138. //Other switches
  139. //BOOST_INTERPROCESS_MSG_QUEUE_USES_CIRC_INDEX
  140. //message queue uses a circular queue as index instead of an array (better performance)
  141. //Boost version < 1.52 uses an array, so undef this if you want to communicate
  142. //with processes compiled with those versions.
  143. #define BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  144. //Inline attributes
  145. #if defined(_MSC_VER)
  146. #define BOOST_INTERPROCESS_ALWAYS_INLINE __forceinline
  147. #elif defined (__GNUC__)
  148. #define BOOST_INTERPROCESS_ALWAYS_INLINE __attribute__((__always_inline__))
  149. #else
  150. #define BOOST_INTERPROCESS_ALWAYS_INLINE inline
  151. #endif
  152. #if defined(_MSC_VER)
  153. #define BOOST_INTERPROCESS_NEVER_INLINE __declspec(noinline)
  154. #elif defined (__GNUC__)
  155. #define BOOST_INTERPROCESS_NEVER_INLINE __attribute__((__noinline__))
  156. #endif
  157. #if defined(BOOST_NO_CXX11_NOEXCEPT)
  158. #if defined(BOOST_MSVC)
  159. #define BOOST_INTERPROCESS_NOEXCEPT throw()
  160. #else
  161. #define BOOST_INTERPROCESS_NOEXCEPT
  162. #endif
  163. #define BOOST_INTERPROCESS_NOEXCEPT_IF(x)
  164. #else
  165. #define BOOST_INTERPROCESS_NOEXCEPT noexcept
  166. #define BOOST_INTERPROCESS_NOEXCEPT_IF(x) noexcept(x)
  167. #endif
  168. #include <boost/interprocess/detail/config_end.hpp>
  169. #endif //#ifndef BOOST_INTERPROCESS_DETAIL_WORKAROUND_HPP