stdatomic.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_STDATOMIC_H
  10. #define _LIBCPP_STDATOMIC_H
  11. /*
  12. stdatomic.h synopsis
  13. template<class T>
  14. using std-atomic = std::atomic<T>; // exposition only
  15. #define _Atomic(T) std-atomic<T>
  16. #define ATOMIC_BOOL_LOCK_FREE see below
  17. #define ATOMIC_CHAR_LOCK_FREE see below
  18. #define ATOMIC_CHAR16_T_LOCK_FREE see below
  19. #define ATOMIC_CHAR32_T_LOCK_FREE see below
  20. #define ATOMIC_WCHAR_T_LOCK_FREE see below
  21. #define ATOMIC_SHORT_LOCK_FREE see below
  22. #define ATOMIC_INT_LOCK_FREE see below
  23. #define ATOMIC_LONG_LOCK_FREE see below
  24. #define ATOMIC_LLONG_LOCK_FREE see below
  25. #define ATOMIC_POINTER_LOCK_FREE see below
  26. using std::memory_order // see below
  27. using std::memory_order_relaxed // see below
  28. using std::memory_order_consume // see below
  29. using std::memory_order_acquire // see below
  30. using std::memory_order_release // see below
  31. using std::memory_order_acq_rel // see below
  32. using std::memory_order_seq_cst // see below
  33. using std::atomic_flag // see below
  34. using std::atomic_bool // see below
  35. using std::atomic_char // see below
  36. using std::atomic_schar // see below
  37. using std::atomic_uchar // see below
  38. using std::atomic_short // see below
  39. using std::atomic_ushort // see below
  40. using std::atomic_int // see below
  41. using std::atomic_uint // see below
  42. using std::atomic_long // see below
  43. using std::atomic_ulong // see below
  44. using std::atomic_llong // see below
  45. using std::atomic_ullong // see below
  46. using std::atomic_char8_t // see below
  47. using std::atomic_char16_t // see below
  48. using std::atomic_char32_t // see below
  49. using std::atomic_wchar_t // see below
  50. using std::atomic_int8_t // see below
  51. using std::atomic_uint8_t // see below
  52. using std::atomic_int16_t // see below
  53. using std::atomic_uint16_t // see below
  54. using std::atomic_int32_t // see below
  55. using std::atomic_uint32_t // see below
  56. using std::atomic_int64_t // see below
  57. using std::atomic_uint64_t // see below
  58. using std::atomic_int_least8_t // see below
  59. using std::atomic_uint_least8_t // see below
  60. using std::atomic_int_least16_t // see below
  61. using std::atomic_uint_least16_t // see below
  62. using std::atomic_int_least32_t // see below
  63. using std::atomic_uint_least32_t // see below
  64. using std::atomic_int_least64_t // see below
  65. using std::atomic_uint_least64_t // see below
  66. using std::atomic_int_fast8_t // see below
  67. using std::atomic_uint_fast8_t // see below
  68. using std::atomic_int_fast16_t // see below
  69. using std::atomic_uint_fast16_t // see below
  70. using std::atomic_int_fast32_t // see below
  71. using std::atomic_uint_fast32_t // see below
  72. using std::atomic_int_fast64_t // see below
  73. using std::atomic_uint_fast64_t // see below
  74. using std::atomic_intptr_t // see below
  75. using std::atomic_uintptr_t // see below
  76. using std::atomic_size_t // see below
  77. using std::atomic_ptrdiff_t // see below
  78. using std::atomic_intmax_t // see below
  79. using std::atomic_uintmax_t // see below
  80. using std::atomic_is_lock_free // see below
  81. using std::atomic_load // see below
  82. using std::atomic_load_explicit // see below
  83. using std::atomic_store // see below
  84. using std::atomic_store_explicit // see below
  85. using std::atomic_exchange // see below
  86. using std::atomic_exchange_explicit // see below
  87. using std::atomic_compare_exchange_strong // see below
  88. using std::atomic_compare_exchange_strong_explicit // see below
  89. using std::atomic_compare_exchange_weak // see below
  90. using std::atomic_compare_exchange_weak_explicit // see below
  91. using std::atomic_fetch_add // see below
  92. using std::atomic_fetch_add_explicit // see below
  93. using std::atomic_fetch_sub // see below
  94. using std::atomic_fetch_sub_explicit // see below
  95. using std::atomic_fetch_or // see below
  96. using std::atomic_fetch_or_explicit // see below
  97. using std::atomic_fetch_and // see below
  98. using std::atomic_fetch_and_explicit // see below
  99. using std::atomic_flag_test_and_set // see below
  100. using std::atomic_flag_test_and_set_explicit // see below
  101. using std::atomic_flag_clear // see below
  102. using std::atomic_flag_clear_explicit // see below
  103. using std::atomic_thread_fence // see below
  104. using std::atomic_signal_fence // see below
  105. */
  106. #include <__config>
  107. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  108. # pragma GCC system_header
  109. #endif
  110. #if _LIBCPP_STD_VER > 20
  111. #include <atomic>
  112. #include <version>
  113. #ifdef _Atomic
  114. # undef _Atomic
  115. #endif
  116. #define _Atomic(_Tp) ::std::atomic<_Tp>
  117. using std::memory_order _LIBCPP_USING_IF_EXISTS;
  118. using std::memory_order_relaxed _LIBCPP_USING_IF_EXISTS;
  119. using std::memory_order_consume _LIBCPP_USING_IF_EXISTS;
  120. using std::memory_order_acquire _LIBCPP_USING_IF_EXISTS;
  121. using std::memory_order_release _LIBCPP_USING_IF_EXISTS;
  122. using std::memory_order_acq_rel _LIBCPP_USING_IF_EXISTS;
  123. using std::memory_order_seq_cst _LIBCPP_USING_IF_EXISTS;
  124. using std::atomic_flag _LIBCPP_USING_IF_EXISTS;
  125. using std::atomic_bool _LIBCPP_USING_IF_EXISTS;
  126. using std::atomic_char _LIBCPP_USING_IF_EXISTS;
  127. using std::atomic_schar _LIBCPP_USING_IF_EXISTS;
  128. using std::atomic_uchar _LIBCPP_USING_IF_EXISTS;
  129. using std::atomic_short _LIBCPP_USING_IF_EXISTS;
  130. using std::atomic_ushort _LIBCPP_USING_IF_EXISTS;
  131. using std::atomic_int _LIBCPP_USING_IF_EXISTS;
  132. using std::atomic_uint _LIBCPP_USING_IF_EXISTS;
  133. using std::atomic_long _LIBCPP_USING_IF_EXISTS;
  134. using std::atomic_ulong _LIBCPP_USING_IF_EXISTS;
  135. using std::atomic_llong _LIBCPP_USING_IF_EXISTS;
  136. using std::atomic_ullong _LIBCPP_USING_IF_EXISTS;
  137. using std::atomic_char8_t _LIBCPP_USING_IF_EXISTS;
  138. using std::atomic_char16_t _LIBCPP_USING_IF_EXISTS;
  139. using std::atomic_char32_t _LIBCPP_USING_IF_EXISTS;
  140. using std::atomic_wchar_t _LIBCPP_USING_IF_EXISTS;
  141. using std::atomic_int8_t _LIBCPP_USING_IF_EXISTS;
  142. using std::atomic_uint8_t _LIBCPP_USING_IF_EXISTS;
  143. using std::atomic_int16_t _LIBCPP_USING_IF_EXISTS;
  144. using std::atomic_uint16_t _LIBCPP_USING_IF_EXISTS;
  145. using std::atomic_int32_t _LIBCPP_USING_IF_EXISTS;
  146. using std::atomic_uint32_t _LIBCPP_USING_IF_EXISTS;
  147. using std::atomic_int64_t _LIBCPP_USING_IF_EXISTS;
  148. using std::atomic_uint64_t _LIBCPP_USING_IF_EXISTS;
  149. using std::atomic_int_least8_t _LIBCPP_USING_IF_EXISTS;
  150. using std::atomic_uint_least8_t _LIBCPP_USING_IF_EXISTS;
  151. using std::atomic_int_least16_t _LIBCPP_USING_IF_EXISTS;
  152. using std::atomic_uint_least16_t _LIBCPP_USING_IF_EXISTS;
  153. using std::atomic_int_least32_t _LIBCPP_USING_IF_EXISTS;
  154. using std::atomic_uint_least32_t _LIBCPP_USING_IF_EXISTS;
  155. using std::atomic_int_least64_t _LIBCPP_USING_IF_EXISTS;
  156. using std::atomic_uint_least64_t _LIBCPP_USING_IF_EXISTS;
  157. using std::atomic_int_fast8_t _LIBCPP_USING_IF_EXISTS;
  158. using std::atomic_uint_fast8_t _LIBCPP_USING_IF_EXISTS;
  159. using std::atomic_int_fast16_t _LIBCPP_USING_IF_EXISTS;
  160. using std::atomic_uint_fast16_t _LIBCPP_USING_IF_EXISTS;
  161. using std::atomic_int_fast32_t _LIBCPP_USING_IF_EXISTS;
  162. using std::atomic_uint_fast32_t _LIBCPP_USING_IF_EXISTS;
  163. using std::atomic_int_fast64_t _LIBCPP_USING_IF_EXISTS;
  164. using std::atomic_uint_fast64_t _LIBCPP_USING_IF_EXISTS;
  165. using std::atomic_intptr_t _LIBCPP_USING_IF_EXISTS;
  166. using std::atomic_uintptr_t _LIBCPP_USING_IF_EXISTS;
  167. using std::atomic_size_t _LIBCPP_USING_IF_EXISTS;
  168. using std::atomic_ptrdiff_t _LIBCPP_USING_IF_EXISTS;
  169. using std::atomic_intmax_t _LIBCPP_USING_IF_EXISTS;
  170. using std::atomic_uintmax_t _LIBCPP_USING_IF_EXISTS;
  171. using std::atomic_compare_exchange_strong _LIBCPP_USING_IF_EXISTS;
  172. using std::atomic_compare_exchange_strong_explicit _LIBCPP_USING_IF_EXISTS;
  173. using std::atomic_compare_exchange_weak _LIBCPP_USING_IF_EXISTS;
  174. using std::atomic_compare_exchange_weak_explicit _LIBCPP_USING_IF_EXISTS;
  175. using std::atomic_exchange _LIBCPP_USING_IF_EXISTS;
  176. using std::atomic_exchange_explicit _LIBCPP_USING_IF_EXISTS;
  177. using std::atomic_fetch_add _LIBCPP_USING_IF_EXISTS;
  178. using std::atomic_fetch_add_explicit _LIBCPP_USING_IF_EXISTS;
  179. using std::atomic_fetch_and _LIBCPP_USING_IF_EXISTS;
  180. using std::atomic_fetch_and_explicit _LIBCPP_USING_IF_EXISTS;
  181. using std::atomic_fetch_or _LIBCPP_USING_IF_EXISTS;
  182. using std::atomic_fetch_or_explicit _LIBCPP_USING_IF_EXISTS;
  183. using std::atomic_fetch_sub _LIBCPP_USING_IF_EXISTS;
  184. using std::atomic_fetch_sub_explicit _LIBCPP_USING_IF_EXISTS;
  185. using std::atomic_flag_clear _LIBCPP_USING_IF_EXISTS;
  186. using std::atomic_flag_clear_explicit _LIBCPP_USING_IF_EXISTS;
  187. using std::atomic_flag_test_and_set _LIBCPP_USING_IF_EXISTS;
  188. using std::atomic_flag_test_and_set_explicit _LIBCPP_USING_IF_EXISTS;
  189. using std::atomic_is_lock_free _LIBCPP_USING_IF_EXISTS;
  190. using std::atomic_load _LIBCPP_USING_IF_EXISTS;
  191. using std::atomic_load_explicit _LIBCPP_USING_IF_EXISTS;
  192. using std::atomic_store _LIBCPP_USING_IF_EXISTS;
  193. using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
  194. using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
  195. using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
  196. #elif defined(_LIBCPP_COMPILER_CLANG_BASED)
  197. // Before C++23, we include the next <stdatomic.h> on the path to avoid hijacking
  198. // the header. We do this because Clang has historically shipped a <stdatomic.h>
  199. // header that would be available in all Standard modes, and we don't want to
  200. // break that use case.
  201. # if __has_include_next(<stdatomic.h>)
  202. # include_next <stdatomic.h>
  203. # endif
  204. #endif // _LIBCPP_STD_VER > 20
  205. #endif // _LIBCPP_STDATOMIC_H