You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
7.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: unixstl/synch/util/features.h
  3. *
  4. * Purpose: Discrimination of synchronisation features.
  5. *
  6. * Created: 23rd October 1997
  7. * Updated: 4th April 2010
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 1997-2010, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file unixstl/synch/util/features.h
  40. *
  41. * \brief [C++ only] Discrimination of synchronisation features
  42. * (\ref group__library__synch "Synchronisation" Library).
  43. */
  44. #ifndef UNIXSTL_INCL_UNIXSTL_SYNCH_UTIL_H_FEATURES
  45. #define UNIXSTL_INCL_UNIXSTL_SYNCH_UTIL_H_FEATURES
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define UNIXSTL_VER_UNIXSTL_SYNCH_UTIL_H_FEATURES_MAJOR 1
  48. # define UNIXSTL_VER_UNIXSTL_SYNCH_UTIL_H_FEATURES_MINOR 1
  49. # define UNIXSTL_VER_UNIXSTL_SYNCH_UTIL_H_FEATURES_REVISION 2
  50. # define UNIXSTL_VER_UNIXSTL_SYNCH_UTIL_H_FEATURES_EDIT 7
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Includes
  54. */
  55. #ifndef UNIXSTL_INCL_UNIXSTL_H_UNIXSTL
  56. # include <unixstl/unixstl.h>
  57. #endif /* !UNIXSTL_INCL_UNIXSTL_H_UNIXSTL */
  58. #ifndef STLSOFT_INCL_H_UNISTD
  59. # define STLSOFT_INCL_H_UNISTD
  60. # include <unistd.h> /* Required for definition of _POSIX_THREADS on some impls. */
  61. #endif /* !STLSOFT_INCL_H_UNISTD */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Features
  64. *
  65. * 1. UNIXSTL_HAS_ATOMIC_INTEGER_OPERATIONS
  66. * 2. UNIXSTL_USING_PTHREADS
  67. */
  68. /* 1. UNIXSTL_HAS_ATOMIC_INTEGER_OPERATIONS */
  69. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  70. /** \def UNIXSTL_HAS_ATOMIC_INTEGER_OPERATIONS
  71. *
  72. * \brief If defined, indicates that the operating system supports atomic
  73. * integer operations, and that they're safe for use outside the kernel.
  74. *
  75. * Atomic integer operations are assumed on the following "UNIX" platforms:
  76. *
  77. * - Mac OS-X (via OSMemoryBarrier(), etc; &lt;libkern/OSAtomic.h>)
  78. * - Win32 (via InterlockedIncrement(), etc; &lt;windows.h>)
  79. *
  80. * or:
  81. *
  82. * - the symbol UNIXSTL_FORCE_ATOMIC_INTEGER_OPERATIONS is defined. In
  83. * this case, you must also define UNIXSTL_FORCED_ATOMIC_INT_T (as the
  84. * atomic integer type, e.g. int) and
  85. * UNIXSTL_FORCED_ATOMIC_INTEGER_IMPLEMENTATIONS (as the file to be
  86. * included _inside_ the unixstl namespace in
  87. * unixstl/synch/atomic_functions.h)
  88. */
  89. # define UNIXSTL_HAS_ATOMIC_INTEGER_OPERATIONS
  90. #else /* ? STLSOFT_DOCUMENTATION_SKIP_SECTION */
  91. # ifdef UNIXSTL_HAS_ATOMIC_INTEGER_OPERATIONS
  92. # undef UNIXSTL_HAS_ATOMIC_INTEGER_OPERATIONS
  93. # endif /* UNIXSTL_HAS_ATOMIC_INTEGER_OPERATIONS */
  94. # ifdef UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_GCC_BUILTINS
  95. # undef UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_GCC_BUILTINS
  96. # endif /* UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_GCC_BUILTINS */
  97. # ifdef UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_MACOSX
  98. # undef UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_MACOSX
  99. # endif /* UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_MACOSX */
  100. # ifdef UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_WINDOWS_INTERLOCKED
  101. # undef UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_WINDOWS_INTERLOCKED
  102. # endif /* UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_WINDOWS_INTERLOCKED */
  103. # if \
  104. defined(UNIXSTL_FORCE_ATOMIC_INTEGER_OPERATIONS)
  105. # define UNIXSTL_HAS_ATOMIC_INTEGER_OPERATIONS
  106. # elif \
  107. ( defined(_WIN32) || \
  108. defined(_WIN64)) && \
  109. !defined(UNIXSTL_NO_ATOMIC_INTEGER_OPERATIONS_ON_WINDOWS)
  110. # define UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_WINDOWS_INTERLOCKED
  111. # define UNIXSTL_HAS_ATOMIC_INTEGER_OPERATIONS
  112. # elif \
  113. defined(UNIXSTL_OS_IS_MACOSX)
  114. # define UNIXSTL_ATOMIC_INTEGER_OPERATIONS_VIA_MACOSX
  115. # define UNIXSTL_HAS_ATOMIC_INTEGER_OPERATIONS
  116. # endif
  117. #endif /* STLSOFT_DOCUMENTATION_SKIP_SECTION */
  118. /* 1. UNIXSTL_USING_PTHREADS */
  119. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  120. /** \def UNIXSTL_USING_PTHREADS
  121. *
  122. * \brief If defined, indicates that PThreads is selected.
  123. *
  124. * PThreads is selected if:
  125. *
  126. * - _POSIX_THREADS is defined and _REENTRANT is defined, or
  127. * - UNIXSTL_FORCE_PTHREADS is defined, which causes &lt;pthread.h> to be
  128. * included, and the symbol _REENTRANT (and _POSIX_THREADS on Windows)
  129. * to be defined if they are not already.
  130. */
  131. # define UNIXSTL_USING_PTHREADS
  132. #else /* ? STLSOFT_DOCUMENTATION_SKIP_SECTION */
  133. # ifdef UNIXSTL_USING_PTHREADS
  134. # undef UNIXSTL_USING_PTHREADS
  135. # endif /* UNIXSTL_USING_PTHREADS */
  136. # if defined(UNIXSTL_FORCE_PTHREADS)
  137. # if defined(_STLSOFT_FORCE_ANY_COMPILER) && \
  138. ( defined(_WIN32) || \
  139. defined(_WIN64))
  140. /* Emulating UNIX on Win32 */
  141. # if !defined(__MT__) && \
  142. !defined(_MT)
  143. # error Cannot force PThreads on Windows unless multi-threaded compilation is enabled
  144. # else /* ? MT */
  145. # ifndef _POSIX_THREADS
  146. # define _POSIX_THREADS
  147. # endif /* !_POSIX_THREADS */
  148. # ifndef _REENTRANT
  149. # define _REENTRANT
  150. # endif /* !_REENTRANT */
  151. # endif /* MT */
  152. # else /* ? compiler / OS */
  153. # ifndef _POSIX_THREADS
  154. # error Cannot force PThreads on a system on which _POSIX_THREADS is not defined
  155. # endif /* !_POSIX_THREADS */
  156. # ifndef _REENTRANT
  157. # define _REENTRANT
  158. # endif /* !_REENTRANT */
  159. # endif /* compiler / OS */
  160. # endif /* UNIXSTL_FORCE_PTHREADS */
  161. # if defined(_REENTRANT)
  162. # define UNIXSTL_USING_PTHREADS
  163. # endif /* _REENTRANT */
  164. #endif /* STLSOFT_DOCUMENTATION_SKIP_SECTION */
  165. /* ////////////////////////////////////////////////////////////////////// */
  166. #endif /* !UNIXSTL_INCL_UNIXSTL_SYNCH_UTIL_H_FEATURES */
  167. /* ///////////////////////////// end of file //////////////////////////// */