atomic.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef _LIBCPP___ATOMIC_ATOMIC_H
  9. #define _LIBCPP___ATOMIC_ATOMIC_H
  10. #include <__atomic/atomic_base.h>
  11. #include <__atomic/check_memory_order.h>
  12. #include <__atomic/cxx_atomic_impl.h>
  13. #include <__atomic/memory_order.h>
  14. #include <__config>
  15. #include <__memory/addressof.h>
  16. #include <__type_traits/is_function.h>
  17. #include <__type_traits/is_same.h>
  18. #include <__type_traits/remove_pointer.h>
  19. #include <cstddef>
  20. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  21. # pragma GCC system_header
  22. #endif
  23. _LIBCPP_BEGIN_NAMESPACE_STD
  24. template <class _Tp>
  25. struct atomic
  26. : public __atomic_base<_Tp>
  27. {
  28. using __base = __atomic_base<_Tp>;
  29. using value_type = _Tp;
  30. using difference_type = value_type;
  31. #if _LIBCPP_STD_VER >= 20
  32. _LIBCPP_HIDE_FROM_ABI
  33. atomic() = default;
  34. #else
  35. _LIBCPP_HIDE_FROM_ABI
  36. atomic() _NOEXCEPT = default;
  37. #endif
  38. _LIBCPP_HIDE_FROM_ABI
  39. _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
  40. _LIBCPP_HIDE_FROM_ABI
  41. _Tp operator=(_Tp __d) volatile _NOEXCEPT
  42. {__base::store(__d); return __d;}
  43. _LIBCPP_HIDE_FROM_ABI
  44. _Tp operator=(_Tp __d) _NOEXCEPT
  45. {__base::store(__d); return __d;}
  46. atomic& operator=(const atomic&) = delete;
  47. atomic& operator=(const atomic&) volatile = delete;
  48. };
  49. // atomic<T*>
  50. template <class _Tp>
  51. struct atomic<_Tp*>
  52. : public __atomic_base<_Tp*>
  53. {
  54. using __base = __atomic_base<_Tp*>;
  55. using value_type = _Tp*;
  56. using difference_type = ptrdiff_t;
  57. _LIBCPP_HIDE_FROM_ABI
  58. atomic() _NOEXCEPT = default;
  59. _LIBCPP_HIDE_FROM_ABI
  60. _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
  61. _LIBCPP_HIDE_FROM_ABI
  62. _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
  63. {__base::store(__d); return __d;}
  64. _LIBCPP_HIDE_FROM_ABI
  65. _Tp* operator=(_Tp* __d) _NOEXCEPT
  66. {__base::store(__d); return __d;}
  67. _LIBCPP_HIDE_FROM_ABI
  68. _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
  69. // __atomic_fetch_add accepts function pointers, guard against them.
  70. static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed");
  71. return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m);
  72. }
  73. _LIBCPP_HIDE_FROM_ABI
  74. _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
  75. // __atomic_fetch_add accepts function pointers, guard against them.
  76. static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed");
  77. return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m);
  78. }
  79. _LIBCPP_HIDE_FROM_ABI
  80. _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT {
  81. // __atomic_fetch_add accepts function pointers, guard against them.
  82. static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed");
  83. return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m);
  84. }
  85. _LIBCPP_HIDE_FROM_ABI
  86. _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT {
  87. // __atomic_fetch_add accepts function pointers, guard against them.
  88. static_assert(!is_function<__remove_pointer_t<_Tp> >::value, "Pointer to function isn't allowed");
  89. return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m);
  90. }
  91. _LIBCPP_HIDE_FROM_ABI
  92. _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
  93. _LIBCPP_HIDE_FROM_ABI
  94. _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);}
  95. _LIBCPP_HIDE_FROM_ABI
  96. _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);}
  97. _LIBCPP_HIDE_FROM_ABI
  98. _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);}
  99. _LIBCPP_HIDE_FROM_ABI
  100. _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;}
  101. _LIBCPP_HIDE_FROM_ABI
  102. _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;}
  103. _LIBCPP_HIDE_FROM_ABI
  104. _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
  105. _LIBCPP_HIDE_FROM_ABI
  106. _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
  107. _LIBCPP_HIDE_FROM_ABI
  108. _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
  109. _LIBCPP_HIDE_FROM_ABI
  110. _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;}
  111. _LIBCPP_HIDE_FROM_ABI
  112. _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
  113. _LIBCPP_HIDE_FROM_ABI
  114. _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
  115. atomic& operator=(const atomic&) = delete;
  116. atomic& operator=(const atomic&) volatile = delete;
  117. };
  118. // atomic_is_lock_free
  119. template <class _Tp>
  120. _LIBCPP_HIDE_FROM_ABI
  121. bool
  122. atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
  123. {
  124. return __o->is_lock_free();
  125. }
  126. template <class _Tp>
  127. _LIBCPP_HIDE_FROM_ABI
  128. bool
  129. atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
  130. {
  131. return __o->is_lock_free();
  132. }
  133. // atomic_init
  134. template <class _Tp>
  135. _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI
  136. void
  137. atomic_init(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
  138. {
  139. std::__cxx_atomic_init(std::addressof(__o->__a_), __d);
  140. }
  141. template <class _Tp>
  142. _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI
  143. void
  144. atomic_init(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
  145. {
  146. std::__cxx_atomic_init(std::addressof(__o->__a_), __d);
  147. }
  148. // atomic_store
  149. template <class _Tp>
  150. _LIBCPP_HIDE_FROM_ABI
  151. void
  152. atomic_store(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
  153. {
  154. __o->store(__d);
  155. }
  156. template <class _Tp>
  157. _LIBCPP_HIDE_FROM_ABI
  158. void
  159. atomic_store(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
  160. {
  161. __o->store(__d);
  162. }
  163. // atomic_store_explicit
  164. template <class _Tp>
  165. _LIBCPP_HIDE_FROM_ABI
  166. void
  167. atomic_store_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
  168. _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
  169. {
  170. __o->store(__d, __m);
  171. }
  172. template <class _Tp>
  173. _LIBCPP_HIDE_FROM_ABI
  174. void
  175. atomic_store_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
  176. _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
  177. {
  178. __o->store(__d, __m);
  179. }
  180. // atomic_load
  181. template <class _Tp>
  182. _LIBCPP_HIDE_FROM_ABI
  183. _Tp
  184. atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
  185. {
  186. return __o->load();
  187. }
  188. template <class _Tp>
  189. _LIBCPP_HIDE_FROM_ABI
  190. _Tp
  191. atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
  192. {
  193. return __o->load();
  194. }
  195. // atomic_load_explicit
  196. template <class _Tp>
  197. _LIBCPP_HIDE_FROM_ABI
  198. _Tp
  199. atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
  200. _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
  201. {
  202. return __o->load(__m);
  203. }
  204. template <class _Tp>
  205. _LIBCPP_HIDE_FROM_ABI
  206. _Tp
  207. atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
  208. _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
  209. {
  210. return __o->load(__m);
  211. }
  212. // atomic_exchange
  213. template <class _Tp>
  214. _LIBCPP_HIDE_FROM_ABI
  215. _Tp
  216. atomic_exchange(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
  217. {
  218. return __o->exchange(__d);
  219. }
  220. template <class _Tp>
  221. _LIBCPP_HIDE_FROM_ABI
  222. _Tp
  223. atomic_exchange(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
  224. {
  225. return __o->exchange(__d);
  226. }
  227. // atomic_exchange_explicit
  228. template <class _Tp>
  229. _LIBCPP_HIDE_FROM_ABI
  230. _Tp
  231. atomic_exchange_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
  232. {
  233. return __o->exchange(__d, __m);
  234. }
  235. template <class _Tp>
  236. _LIBCPP_HIDE_FROM_ABI
  237. _Tp
  238. atomic_exchange_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
  239. {
  240. return __o->exchange(__d, __m);
  241. }
  242. // atomic_compare_exchange_weak
  243. template <class _Tp>
  244. _LIBCPP_HIDE_FROM_ABI
  245. bool
  246. atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
  247. {
  248. return __o->compare_exchange_weak(*__e, __d);
  249. }
  250. template <class _Tp>
  251. _LIBCPP_HIDE_FROM_ABI
  252. bool
  253. atomic_compare_exchange_weak(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
  254. {
  255. return __o->compare_exchange_weak(*__e, __d);
  256. }
  257. // atomic_compare_exchange_strong
  258. template <class _Tp>
  259. _LIBCPP_HIDE_FROM_ABI
  260. bool
  261. atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
  262. {
  263. return __o->compare_exchange_strong(*__e, __d);
  264. }
  265. template <class _Tp>
  266. _LIBCPP_HIDE_FROM_ABI
  267. bool
  268. atomic_compare_exchange_strong(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
  269. {
  270. return __o->compare_exchange_strong(*__e, __d);
  271. }
  272. // atomic_compare_exchange_weak_explicit
  273. template <class _Tp>
  274. _LIBCPP_HIDE_FROM_ABI
  275. bool
  276. atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e,
  277. typename atomic<_Tp>::value_type __d,
  278. memory_order __s, memory_order __f) _NOEXCEPT
  279. _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
  280. {
  281. return __o->compare_exchange_weak(*__e, __d, __s, __f);
  282. }
  283. template <class _Tp>
  284. _LIBCPP_HIDE_FROM_ABI
  285. bool
  286. atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d,
  287. memory_order __s, memory_order __f) _NOEXCEPT
  288. _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
  289. {
  290. return __o->compare_exchange_weak(*__e, __d, __s, __f);
  291. }
  292. // atomic_compare_exchange_strong_explicit
  293. template <class _Tp>
  294. _LIBCPP_HIDE_FROM_ABI
  295. bool
  296. atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
  297. typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d,
  298. memory_order __s, memory_order __f) _NOEXCEPT
  299. _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
  300. {
  301. return __o->compare_exchange_strong(*__e, __d, __s, __f);
  302. }
  303. template <class _Tp>
  304. _LIBCPP_HIDE_FROM_ABI
  305. bool
  306. atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e,
  307. typename atomic<_Tp>::value_type __d,
  308. memory_order __s, memory_order __f) _NOEXCEPT
  309. _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
  310. {
  311. return __o->compare_exchange_strong(*__e, __d, __s, __f);
  312. }
  313. // atomic_wait
  314. template <class _Tp>
  315. _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI
  316. void atomic_wait(const volatile atomic<_Tp>* __o,
  317. typename atomic<_Tp>::value_type __v) _NOEXCEPT
  318. {
  319. return __o->wait(__v);
  320. }
  321. template <class _Tp>
  322. _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI
  323. void atomic_wait(const atomic<_Tp>* __o,
  324. typename atomic<_Tp>::value_type __v) _NOEXCEPT
  325. {
  326. return __o->wait(__v);
  327. }
  328. // atomic_wait_explicit
  329. template <class _Tp>
  330. _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI
  331. void atomic_wait_explicit(const volatile atomic<_Tp>* __o,
  332. typename atomic<_Tp>::value_type __v,
  333. memory_order __m) _NOEXCEPT
  334. _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
  335. {
  336. return __o->wait(__v, __m);
  337. }
  338. template <class _Tp>
  339. _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI
  340. void atomic_wait_explicit(const atomic<_Tp>* __o,
  341. typename atomic<_Tp>::value_type __v,
  342. memory_order __m) _NOEXCEPT
  343. _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
  344. {
  345. return __o->wait(__v, __m);
  346. }
  347. // atomic_notify_one
  348. template <class _Tp>
  349. _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI
  350. void atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT
  351. {
  352. __o->notify_one();
  353. }
  354. template <class _Tp>
  355. _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI
  356. void atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT
  357. {
  358. __o->notify_one();
  359. }
  360. // atomic_notify_all
  361. template <class _Tp>
  362. _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI
  363. void atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT
  364. {
  365. __o->notify_all();
  366. }
  367. template <class _Tp>
  368. _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI
  369. void atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT
  370. {
  371. __o->notify_all();
  372. }
  373. // atomic_fetch_add
  374. template <class _Tp>
  375. _LIBCPP_HIDE_FROM_ABI
  376. _Tp
  377. atomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
  378. {
  379. return __o->fetch_add(__op);
  380. }
  381. template <class _Tp>
  382. _LIBCPP_HIDE_FROM_ABI
  383. _Tp
  384. atomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
  385. {
  386. return __o->fetch_add(__op);
  387. }
  388. // atomic_fetch_add_explicit
  389. template <class _Tp>
  390. _LIBCPP_HIDE_FROM_ABI
  391. _Tp atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
  392. {
  393. return __o->fetch_add(__op, __m);
  394. }
  395. template <class _Tp>
  396. _LIBCPP_HIDE_FROM_ABI
  397. _Tp atomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
  398. {
  399. return __o->fetch_add(__op, __m);
  400. }
  401. // atomic_fetch_sub
  402. template <class _Tp>
  403. _LIBCPP_HIDE_FROM_ABI
  404. _Tp atomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
  405. {
  406. return __o->fetch_sub(__op);
  407. }
  408. template <class _Tp>
  409. _LIBCPP_HIDE_FROM_ABI
  410. _Tp atomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
  411. {
  412. return __o->fetch_sub(__op);
  413. }
  414. // atomic_fetch_sub_explicit
  415. template <class _Tp>
  416. _LIBCPP_HIDE_FROM_ABI
  417. _Tp atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
  418. {
  419. return __o->fetch_sub(__op, __m);
  420. }
  421. template <class _Tp>
  422. _LIBCPP_HIDE_FROM_ABI
  423. _Tp atomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
  424. {
  425. return __o->fetch_sub(__op, __m);
  426. }
  427. // atomic_fetch_and
  428. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  429. _LIBCPP_HIDE_FROM_ABI
  430. _Tp
  431. atomic_fetch_and(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
  432. {
  433. return __o->fetch_and(__op);
  434. }
  435. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  436. _LIBCPP_HIDE_FROM_ABI
  437. _Tp
  438. atomic_fetch_and(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
  439. {
  440. return __o->fetch_and(__op);
  441. }
  442. // atomic_fetch_and_explicit
  443. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  444. _LIBCPP_HIDE_FROM_ABI
  445. _Tp
  446. atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
  447. {
  448. return __o->fetch_and(__op, __m);
  449. }
  450. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  451. _LIBCPP_HIDE_FROM_ABI
  452. _Tp
  453. atomic_fetch_and_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
  454. {
  455. return __o->fetch_and(__op, __m);
  456. }
  457. // atomic_fetch_or
  458. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  459. _LIBCPP_HIDE_FROM_ABI
  460. _Tp
  461. atomic_fetch_or(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
  462. {
  463. return __o->fetch_or(__op);
  464. }
  465. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  466. _LIBCPP_HIDE_FROM_ABI
  467. _Tp
  468. atomic_fetch_or(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
  469. {
  470. return __o->fetch_or(__op);
  471. }
  472. // atomic_fetch_or_explicit
  473. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  474. _LIBCPP_HIDE_FROM_ABI
  475. _Tp
  476. atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
  477. {
  478. return __o->fetch_or(__op, __m);
  479. }
  480. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  481. _LIBCPP_HIDE_FROM_ABI
  482. _Tp
  483. atomic_fetch_or_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
  484. {
  485. return __o->fetch_or(__op, __m);
  486. }
  487. // atomic_fetch_xor
  488. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  489. _LIBCPP_HIDE_FROM_ABI
  490. _Tp
  491. atomic_fetch_xor(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
  492. {
  493. return __o->fetch_xor(__op);
  494. }
  495. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  496. _LIBCPP_HIDE_FROM_ABI
  497. _Tp
  498. atomic_fetch_xor(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
  499. {
  500. return __o->fetch_xor(__op);
  501. }
  502. // atomic_fetch_xor_explicit
  503. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  504. _LIBCPP_HIDE_FROM_ABI
  505. _Tp
  506. atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
  507. {
  508. return __o->fetch_xor(__op, __m);
  509. }
  510. template <class _Tp, __enable_if_t<is_integral<_Tp>::value && !is_same<_Tp, bool>::value, int> = 0>
  511. _LIBCPP_HIDE_FROM_ABI
  512. _Tp
  513. atomic_fetch_xor_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
  514. {
  515. return __o->fetch_xor(__op, __m);
  516. }
  517. _LIBCPP_END_NAMESPACE_STD
  518. #endif // _LIBCPP___ATOMIC_ATOMIC_H