local_atomic 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905
  1. // -*- C++ -*- header.
  2. // Copyright (C) 2008-2015 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. // ????????????????????????????????????????????????????????????????????
  21. //
  22. // This is a copy of the libstdc++ header, with the trivial modification
  23. // of ignoring the c++config.h include. If and when the top-level build is
  24. // fixed so that target libraries can be built using the newly built, we can
  25. // delete this file.
  26. //
  27. // ????????????????????????????????????????????????????????????????????
  28. /** @file include/atomic
  29. * This is a Standard C++ Library header.
  30. */
  31. // Based on "C++ Atomic Types and Operations" by Hans Boehm and Lawrence Crowl.
  32. // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2427.html
  33. #ifndef _GLIBCXX_ATOMIC
  34. #define _GLIBCXX_ATOMIC 1
  35. #undef __always_inline
  36. #define __always_inline __attribute__((always_inline))
  37. // #pragma GCC system_header
  38. // #ifndef __GXX_EXPERIMENTAL_CXX0X__
  39. // # include <bits/c++0x_warning.h>
  40. // #endif
  41. // #include <bits/atomic_base.h>
  42. namespace std // _GLIBCXX_VISIBILITY(default)
  43. {
  44. // _GLIBCXX_BEGIN_NAMESPACE_VERSION
  45. /**
  46. * @defgroup atomics Atomics
  47. *
  48. * Components for performing atomic operations.
  49. * @{
  50. */
  51. /// Enumeration for memory_order
  52. typedef enum memory_order
  53. {
  54. memory_order_relaxed,
  55. memory_order_consume,
  56. memory_order_acquire,
  57. memory_order_release,
  58. memory_order_acq_rel,
  59. memory_order_seq_cst
  60. } memory_order;
  61. inline __always_inline memory_order
  62. __calculate_memory_order(memory_order __m) noexcept
  63. {
  64. const bool __cond1 = __m == memory_order_release;
  65. const bool __cond2 = __m == memory_order_acq_rel;
  66. memory_order __mo1(__cond1 ? memory_order_relaxed : __m);
  67. memory_order __mo2(__cond2 ? memory_order_acquire : __mo1);
  68. return __mo2;
  69. }
  70. inline __always_inline void
  71. atomic_thread_fence(memory_order __m) noexcept
  72. {
  73. __atomic_thread_fence (__m);
  74. }
  75. inline __always_inline void
  76. atomic_signal_fence(memory_order __m) noexcept
  77. {
  78. __atomic_thread_fence (__m);
  79. }
  80. /// kill_dependency
  81. template<typename _Tp>
  82. inline _Tp
  83. kill_dependency(_Tp __y) noexcept
  84. {
  85. _Tp __ret(__y);
  86. return __ret;
  87. }
  88. /// Lock-free Property
  89. #define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
  90. #define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
  91. #define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
  92. #define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
  93. #define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
  94. #define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
  95. #define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
  96. #define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
  97. #define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
  98. #define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
  99. // Base types for atomics.
  100. template<typename _IntTp>
  101. struct __atomic_base;
  102. /// atomic_char
  103. typedef __atomic_base<char> atomic_char;
  104. /// atomic_schar
  105. typedef __atomic_base<signed char> atomic_schar;
  106. /// atomic_uchar
  107. typedef __atomic_base<unsigned char> atomic_uchar;
  108. /// atomic_short
  109. typedef __atomic_base<short> atomic_short;
  110. /// atomic_ushort
  111. typedef __atomic_base<unsigned short> atomic_ushort;
  112. /// atomic_int
  113. typedef __atomic_base<int> atomic_int;
  114. /// atomic_uint
  115. typedef __atomic_base<unsigned int> atomic_uint;
  116. /// atomic_long
  117. typedef __atomic_base<long> atomic_long;
  118. /// atomic_ulong
  119. typedef __atomic_base<unsigned long> atomic_ulong;
  120. /// atomic_llong
  121. typedef __atomic_base<long long> atomic_llong;
  122. /// atomic_ullong
  123. typedef __atomic_base<unsigned long long> atomic_ullong;
  124. /// atomic_wchar_t
  125. typedef __atomic_base<wchar_t> atomic_wchar_t;
  126. /// atomic_char16_t
  127. typedef __atomic_base<char16_t> atomic_char16_t;
  128. /// atomic_char32_t
  129. typedef __atomic_base<char32_t> atomic_char32_t;
  130. /// atomic_char32_t
  131. typedef __atomic_base<char32_t> atomic_char32_t;
  132. /// atomic_int_least8_t
  133. typedef __atomic_base<int_least8_t> atomic_int_least8_t;
  134. /// atomic_uint_least8_t
  135. typedef __atomic_base<uint_least8_t> atomic_uint_least8_t;
  136. /// atomic_int_least16_t
  137. typedef __atomic_base<int_least16_t> atomic_int_least16_t;
  138. /// atomic_uint_least16_t
  139. typedef __atomic_base<uint_least16_t> atomic_uint_least16_t;
  140. /// atomic_int_least32_t
  141. typedef __atomic_base<int_least32_t> atomic_int_least32_t;
  142. /// atomic_uint_least32_t
  143. typedef __atomic_base<uint_least32_t> atomic_uint_least32_t;
  144. /// atomic_int_least64_t
  145. typedef __atomic_base<int_least64_t> atomic_int_least64_t;
  146. /// atomic_uint_least64_t
  147. typedef __atomic_base<uint_least64_t> atomic_uint_least64_t;
  148. /// atomic_int_fast8_t
  149. typedef __atomic_base<int_fast8_t> atomic_int_fast8_t;
  150. /// atomic_uint_fast8_t
  151. typedef __atomic_base<uint_fast8_t> atomic_uint_fast8_t;
  152. /// atomic_int_fast16_t
  153. typedef __atomic_base<int_fast16_t> atomic_int_fast16_t;
  154. /// atomic_uint_fast16_t
  155. typedef __atomic_base<uint_fast16_t> atomic_uint_fast16_t;
  156. /// atomic_int_fast32_t
  157. typedef __atomic_base<int_fast32_t> atomic_int_fast32_t;
  158. /// atomic_uint_fast32_t
  159. typedef __atomic_base<uint_fast32_t> atomic_uint_fast32_t;
  160. /// atomic_int_fast64_t
  161. typedef __atomic_base<int_fast64_t> atomic_int_fast64_t;
  162. /// atomic_uint_fast64_t
  163. typedef __atomic_base<uint_fast64_t> atomic_uint_fast64_t;
  164. /// atomic_intptr_t
  165. typedef __atomic_base<intptr_t> atomic_intptr_t;
  166. /// atomic_uintptr_t
  167. typedef __atomic_base<uintptr_t> atomic_uintptr_t;
  168. /// atomic_size_t
  169. typedef __atomic_base<size_t> atomic_size_t;
  170. /// atomic_intmax_t
  171. typedef __atomic_base<intmax_t> atomic_intmax_t;
  172. /// atomic_uintmax_t
  173. typedef __atomic_base<uintmax_t> atomic_uintmax_t;
  174. /// atomic_ptrdiff_t
  175. typedef __atomic_base<ptrdiff_t> atomic_ptrdiff_t;
  176. #define ATOMIC_VAR_INIT(_VI) { _VI }
  177. template<typename _Tp>
  178. struct atomic;
  179. template<typename _Tp>
  180. struct atomic<_Tp*>;
  181. /**
  182. * @brief Base type for atomic_flag.
  183. *
  184. * Base type is POD with data, allowing atomic_flag to derive from
  185. * it and meet the standard layout type requirement. In addition to
  186. * compatibilty with a C interface, this allows different
  187. * implementations of atomic_flag to use the same atomic operation
  188. * functions, via a standard conversion to the __atomic_flag_base
  189. * argument.
  190. */
  191. // _GLIBCXX_BEGIN_EXTERN_C
  192. struct __atomic_flag_base
  193. {
  194. bool _M_i;
  195. };
  196. // _GLIBCXX_END_EXTERN_C
  197. #define ATOMIC_FLAG_INIT { false }
  198. /// atomic_flag
  199. struct atomic_flag : public __atomic_flag_base
  200. {
  201. atomic_flag() noexcept = default;
  202. ~atomic_flag() noexcept = default;
  203. atomic_flag(const atomic_flag&) = delete;
  204. atomic_flag& operator=(const atomic_flag&) = delete;
  205. atomic_flag& operator=(const atomic_flag&) volatile = delete;
  206. // Conversion to ATOMIC_FLAG_INIT.
  207. atomic_flag(bool __i) noexcept : __atomic_flag_base({ __i }) { }
  208. __always_inline bool
  209. test_and_set(memory_order __m = memory_order_seq_cst) noexcept
  210. {
  211. return __atomic_test_and_set (&_M_i, __m);
  212. }
  213. __always_inline bool
  214. test_and_set(memory_order __m = memory_order_seq_cst) volatile noexcept
  215. {
  216. return __atomic_test_and_set (&_M_i, __m);
  217. }
  218. __always_inline void
  219. clear(memory_order __m = memory_order_seq_cst) noexcept
  220. {
  221. // __glibcxx_assert(__m != memory_order_consume);
  222. // __glibcxx_assert(__m != memory_order_acquire);
  223. // __glibcxx_assert(__m != memory_order_acq_rel);
  224. __atomic_clear (&_M_i, __m);
  225. }
  226. __always_inline void
  227. clear(memory_order __m = memory_order_seq_cst) volatile noexcept
  228. {
  229. // __glibcxx_assert(__m != memory_order_consume);
  230. // __glibcxx_assert(__m != memory_order_acquire);
  231. // __glibcxx_assert(__m != memory_order_acq_rel);
  232. __atomic_clear (&_M_i, __m);
  233. }
  234. };
  235. /// Base class for atomic integrals.
  236. //
  237. // For each of the integral types, define atomic_[integral type] struct
  238. //
  239. // atomic_bool bool
  240. // atomic_char char
  241. // atomic_schar signed char
  242. // atomic_uchar unsigned char
  243. // atomic_short short
  244. // atomic_ushort unsigned short
  245. // atomic_int int
  246. // atomic_uint unsigned int
  247. // atomic_long long
  248. // atomic_ulong unsigned long
  249. // atomic_llong long long
  250. // atomic_ullong unsigned long long
  251. // atomic_char16_t char16_t
  252. // atomic_char32_t char32_t
  253. // atomic_wchar_t wchar_t
  254. //
  255. // NB: Assuming _ITp is an integral scalar type that is 1, 2, 4, or
  256. // 8 bytes, since that is what GCC built-in functions for atomic
  257. // memory access expect.
  258. template<typename _ITp>
  259. struct __atomic_base
  260. {
  261. private:
  262. typedef _ITp __int_type;
  263. __int_type _M_i;
  264. public:
  265. __atomic_base() noexcept = default;
  266. ~__atomic_base() noexcept = default;
  267. __atomic_base(const __atomic_base&) = delete;
  268. __atomic_base& operator=(const __atomic_base&) = delete;
  269. __atomic_base& operator=(const __atomic_base&) volatile = delete;
  270. // Requires __int_type convertible to _M_i.
  271. constexpr __atomic_base(__int_type __i) noexcept : _M_i (__i) { }
  272. operator __int_type() const noexcept
  273. { return load(); }
  274. operator __int_type() const volatile noexcept
  275. { return load(); }
  276. __int_type
  277. operator=(__int_type __i) noexcept
  278. {
  279. store(__i);
  280. return __i;
  281. }
  282. __int_type
  283. operator=(__int_type __i) volatile noexcept
  284. {
  285. store(__i);
  286. return __i;
  287. }
  288. __int_type
  289. operator++(int) noexcept
  290. { return fetch_add(1); }
  291. __int_type
  292. operator++(int) volatile noexcept
  293. { return fetch_add(1); }
  294. __int_type
  295. operator--(int) noexcept
  296. { return fetch_sub(1); }
  297. __int_type
  298. operator--(int) volatile noexcept
  299. { return fetch_sub(1); }
  300. __int_type
  301. operator++() noexcept
  302. { return __atomic_add_fetch(&_M_i, 1, memory_order_seq_cst); }
  303. __int_type
  304. operator++() volatile noexcept
  305. { return __atomic_add_fetch(&_M_i, 1, memory_order_seq_cst); }
  306. __int_type
  307. operator--() noexcept
  308. { return __atomic_sub_fetch(&_M_i, 1, memory_order_seq_cst); }
  309. __int_type
  310. operator--() volatile noexcept
  311. { return __atomic_sub_fetch(&_M_i, 1, memory_order_seq_cst); }
  312. __int_type
  313. operator+=(__int_type __i) noexcept
  314. { return __atomic_add_fetch(&_M_i, __i, memory_order_seq_cst); }
  315. __int_type
  316. operator+=(__int_type __i) volatile noexcept
  317. { return __atomic_add_fetch(&_M_i, __i, memory_order_seq_cst); }
  318. __int_type
  319. operator-=(__int_type __i) noexcept
  320. { return __atomic_sub_fetch(&_M_i, __i, memory_order_seq_cst); }
  321. __int_type
  322. operator-=(__int_type __i) volatile noexcept
  323. { return __atomic_sub_fetch(&_M_i, __i, memory_order_seq_cst); }
  324. __int_type
  325. operator&=(__int_type __i) noexcept
  326. { return __atomic_and_fetch(&_M_i, __i, memory_order_seq_cst); }
  327. __int_type
  328. operator&=(__int_type __i) volatile noexcept
  329. { return __atomic_and_fetch(&_M_i, __i, memory_order_seq_cst); }
  330. __int_type
  331. operator|=(__int_type __i) noexcept
  332. { return __atomic_or_fetch(&_M_i, __i, memory_order_seq_cst); }
  333. __int_type
  334. operator|=(__int_type __i) volatile noexcept
  335. { return __atomic_or_fetch(&_M_i, __i, memory_order_seq_cst); }
  336. __int_type
  337. operator^=(__int_type __i) noexcept
  338. { return __atomic_xor_fetch(&_M_i, __i, memory_order_seq_cst); }
  339. __int_type
  340. operator^=(__int_type __i) volatile noexcept
  341. { return __atomic_xor_fetch(&_M_i, __i, memory_order_seq_cst); }
  342. bool
  343. is_lock_free() const noexcept
  344. { return __atomic_is_lock_free (sizeof (_M_i), &_M_i); }
  345. bool
  346. is_lock_free() const volatile noexcept
  347. { return __atomic_is_lock_free (sizeof (_M_i), &_M_i); }
  348. __always_inline void
  349. store(__int_type __i, memory_order __m = memory_order_seq_cst) noexcept
  350. {
  351. // __glibcxx_assert(__m != memory_order_acquire);
  352. // __glibcxx_assert(__m != memory_order_acq_rel);
  353. // __glibcxx_assert(__m != memory_order_consume);
  354. __atomic_store_n(&_M_i, __i, __m);
  355. }
  356. __always_inline void
  357. store(__int_type __i,
  358. memory_order __m = memory_order_seq_cst) volatile noexcept
  359. {
  360. // __glibcxx_assert(__m != memory_order_acquire);
  361. // __glibcxx_assert(__m != memory_order_acq_rel);
  362. // __glibcxx_assert(__m != memory_order_consume);
  363. __atomic_store_n(&_M_i, __i, __m);
  364. }
  365. __always_inline __int_type
  366. load(memory_order __m = memory_order_seq_cst) const noexcept
  367. {
  368. // __glibcxx_assert(__m != memory_order_release);
  369. // __glibcxx_assert(__m != memory_order_acq_rel);
  370. return __atomic_load_n(&_M_i, __m);
  371. }
  372. __always_inline __int_type
  373. load(memory_order __m = memory_order_seq_cst) const volatile noexcept
  374. {
  375. // __glibcxx_assert(__m != memory_order_release);
  376. // __glibcxx_assert(__m != memory_order_acq_rel);
  377. return __atomic_load_n(&_M_i, __m);
  378. }
  379. __always_inline __int_type
  380. exchange(__int_type __i,
  381. memory_order __m = memory_order_seq_cst) noexcept
  382. {
  383. return __atomic_exchange_n(&_M_i, __i, __m);
  384. }
  385. __always_inline __int_type
  386. exchange(__int_type __i,
  387. memory_order __m = memory_order_seq_cst) volatile noexcept
  388. {
  389. return __atomic_exchange_n(&_M_i, __i, __m);
  390. }
  391. __always_inline bool
  392. compare_exchange_weak(__int_type& __i1, __int_type __i2,
  393. memory_order __m1, memory_order __m2) noexcept
  394. {
  395. // __glibcxx_assert(__m2 != memory_order_release);
  396. // __glibcxx_assert(__m2 != memory_order_acq_rel);
  397. // __glibcxx_assert(__m2 <= __m1);
  398. return __atomic_compare_exchange_n(&_M_i, &__i1, __i2, 1, __m1, __m2);
  399. }
  400. __always_inline bool
  401. compare_exchange_weak(__int_type& __i1, __int_type __i2,
  402. memory_order __m1,
  403. memory_order __m2) volatile noexcept
  404. {
  405. // __glibcxx_assert(__m2 != memory_order_release);
  406. // __glibcxx_assert(__m2 != memory_order_acq_rel);
  407. // __glibcxx_assert(__m2 <= __m1);
  408. return __atomic_compare_exchange_n(&_M_i, &__i1, __i2, 1, __m1, __m2);
  409. }
  410. __always_inline bool
  411. compare_exchange_weak(__int_type& __i1, __int_type __i2,
  412. memory_order __m = memory_order_seq_cst) noexcept
  413. {
  414. return compare_exchange_weak(__i1, __i2, __m,
  415. __calculate_memory_order(__m));
  416. }
  417. __always_inline bool
  418. compare_exchange_weak(__int_type& __i1, __int_type __i2,
  419. memory_order __m = memory_order_seq_cst) volatile noexcept
  420. {
  421. return compare_exchange_weak(__i1, __i2, __m,
  422. __calculate_memory_order(__m));
  423. }
  424. __always_inline bool
  425. compare_exchange_strong(__int_type& __i1, __int_type __i2,
  426. memory_order __m1, memory_order __m2) noexcept
  427. {
  428. // __glibcxx_assert(__m2 != memory_order_release);
  429. // __glibcxx_assert(__m2 != memory_order_acq_rel);
  430. // __glibcxx_assert(__m2 <= __m1);
  431. return __atomic_compare_exchange_n(&_M_i, &__i1, __i2, 0, __m1, __m2);
  432. }
  433. __always_inline bool
  434. compare_exchange_strong(__int_type& __i1, __int_type __i2,
  435. memory_order __m1,
  436. memory_order __m2) volatile noexcept
  437. {
  438. // __glibcxx_assert(__m2 != memory_order_release);
  439. // __glibcxx_assert(__m2 != memory_order_acq_rel);
  440. // __glibcxx_assert(__m2 <= __m1);
  441. return __atomic_compare_exchange_n(&_M_i, &__i1, __i2, 0, __m1, __m2);
  442. }
  443. __always_inline bool
  444. compare_exchange_strong(__int_type& __i1, __int_type __i2,
  445. memory_order __m = memory_order_seq_cst) noexcept
  446. {
  447. return compare_exchange_strong(__i1, __i2, __m,
  448. __calculate_memory_order(__m));
  449. }
  450. __always_inline bool
  451. compare_exchange_strong(__int_type& __i1, __int_type __i2,
  452. memory_order __m = memory_order_seq_cst) volatile noexcept
  453. {
  454. return compare_exchange_strong(__i1, __i2, __m,
  455. __calculate_memory_order(__m));
  456. }
  457. __always_inline __int_type
  458. fetch_add(__int_type __i,
  459. memory_order __m = memory_order_seq_cst) noexcept
  460. { return __atomic_fetch_add(&_M_i, __i, __m); }
  461. __always_inline __int_type
  462. fetch_add(__int_type __i,
  463. memory_order __m = memory_order_seq_cst) volatile noexcept
  464. { return __atomic_fetch_add(&_M_i, __i, __m); }
  465. __always_inline __int_type
  466. fetch_sub(__int_type __i,
  467. memory_order __m = memory_order_seq_cst) noexcept
  468. { return __atomic_fetch_sub(&_M_i, __i, __m); }
  469. __always_inline __int_type
  470. fetch_sub(__int_type __i,
  471. memory_order __m = memory_order_seq_cst) volatile noexcept
  472. { return __atomic_fetch_sub(&_M_i, __i, __m); }
  473. __always_inline __int_type
  474. fetch_and(__int_type __i,
  475. memory_order __m = memory_order_seq_cst) noexcept
  476. { return __atomic_fetch_and(&_M_i, __i, __m); }
  477. __always_inline __int_type
  478. fetch_and(__int_type __i,
  479. memory_order __m = memory_order_seq_cst) volatile noexcept
  480. { return __atomic_fetch_and(&_M_i, __i, __m); }
  481. __always_inline __int_type
  482. fetch_or(__int_type __i,
  483. memory_order __m = memory_order_seq_cst) noexcept
  484. { return __atomic_fetch_or(&_M_i, __i, __m); }
  485. __always_inline __int_type
  486. fetch_or(__int_type __i,
  487. memory_order __m = memory_order_seq_cst) volatile noexcept
  488. { return __atomic_fetch_or(&_M_i, __i, __m); }
  489. __always_inline __int_type
  490. fetch_xor(__int_type __i,
  491. memory_order __m = memory_order_seq_cst) noexcept
  492. { return __atomic_fetch_xor(&_M_i, __i, __m); }
  493. __always_inline __int_type
  494. fetch_xor(__int_type __i,
  495. memory_order __m = memory_order_seq_cst) volatile noexcept
  496. { return __atomic_fetch_xor(&_M_i, __i, __m); }
  497. };
  498. /// Partial specialization for pointer types.
  499. template<typename _PTp>
  500. struct __atomic_base<_PTp*>
  501. {
  502. private:
  503. typedef _PTp* __pointer_type;
  504. __pointer_type _M_p;
  505. public:
  506. __atomic_base() noexcept = default;
  507. ~__atomic_base() noexcept = default;
  508. __atomic_base(const __atomic_base&) = delete;
  509. __atomic_base& operator=(const __atomic_base&) = delete;
  510. __atomic_base& operator=(const __atomic_base&) volatile = delete;
  511. // Requires __pointer_type convertible to _M_p.
  512. constexpr __atomic_base(__pointer_type __p) noexcept : _M_p (__p) { }
  513. operator __pointer_type() const noexcept
  514. { return load(); }
  515. operator __pointer_type() const volatile noexcept
  516. { return load(); }
  517. __pointer_type
  518. operator=(__pointer_type __p) noexcept
  519. {
  520. store(__p);
  521. return __p;
  522. }
  523. __pointer_type
  524. operator=(__pointer_type __p) volatile noexcept
  525. {
  526. store(__p);
  527. return __p;
  528. }
  529. __pointer_type
  530. operator++(int) noexcept
  531. { return fetch_add(1); }
  532. __pointer_type
  533. operator++(int) volatile noexcept
  534. { return fetch_add(1); }
  535. __pointer_type
  536. operator--(int) noexcept
  537. { return fetch_sub(1); }
  538. __pointer_type
  539. operator--(int) volatile noexcept
  540. { return fetch_sub(1); }
  541. __pointer_type
  542. operator++() noexcept
  543. { return __atomic_add_fetch(&_M_p, 1, memory_order_seq_cst); }
  544. __pointer_type
  545. operator++() volatile noexcept
  546. { return __atomic_add_fetch(&_M_p, 1, memory_order_seq_cst); }
  547. __pointer_type
  548. operator--() noexcept
  549. { return __atomic_sub_fetch(&_M_p, 1, memory_order_seq_cst); }
  550. __pointer_type
  551. operator--() volatile noexcept
  552. { return __atomic_sub_fetch(&_M_p, 1, memory_order_seq_cst); }
  553. __pointer_type
  554. operator+=(ptrdiff_t __d) noexcept
  555. { return __atomic_add_fetch(&_M_p, __d, memory_order_seq_cst); }
  556. __pointer_type
  557. operator+=(ptrdiff_t __d) volatile noexcept
  558. { return __atomic_add_fetch(&_M_p, __d, memory_order_seq_cst); }
  559. __pointer_type
  560. operator-=(ptrdiff_t __d) noexcept
  561. { return __atomic_sub_fetch(&_M_p, __d, memory_order_seq_cst); }
  562. __pointer_type
  563. operator-=(ptrdiff_t __d) volatile noexcept
  564. { return __atomic_sub_fetch(&_M_p, __d, memory_order_seq_cst); }
  565. bool
  566. is_lock_free() const noexcept
  567. { return __atomic_is_lock_free (sizeof (_M_p), &_M_p); }
  568. bool
  569. is_lock_free() const volatile noexcept
  570. { return __atomic_is_lock_free (sizeof (_M_p), &_M_p); }
  571. __always_inline void
  572. store(__pointer_type __p,
  573. memory_order __m = memory_order_seq_cst) noexcept
  574. {
  575. // __glibcxx_assert(__m != memory_order_acquire);
  576. // __glibcxx_assert(__m != memory_order_acq_rel);
  577. // __glibcxx_assert(__m != memory_order_consume);
  578. __atomic_store_n(&_M_p, __p, __m);
  579. }
  580. __always_inline void
  581. store(__pointer_type __p,
  582. memory_order __m = memory_order_seq_cst) volatile noexcept
  583. {
  584. // __glibcxx_assert(__m != memory_order_acquire);
  585. // __glibcxx_assert(__m != memory_order_acq_rel);
  586. // __glibcxx_assert(__m != memory_order_consume);
  587. __atomic_store_n(&_M_p, __p, __m);
  588. }
  589. __always_inline __pointer_type
  590. load(memory_order __m = memory_order_seq_cst) const noexcept
  591. {
  592. // __glibcxx_assert(__m != memory_order_release);
  593. // __glibcxx_assert(__m != memory_order_acq_rel);
  594. return __atomic_load_n(&_M_p, __m);
  595. }
  596. __always_inline __pointer_type
  597. load(memory_order __m = memory_order_seq_cst) const volatile noexcept
  598. {
  599. // __glibcxx_assert(__m != memory_order_release);
  600. // __glibcxx_assert(__m != memory_order_acq_rel);
  601. return __atomic_load_n(&_M_p, __m);
  602. }
  603. __always_inline __pointer_type
  604. exchange(__pointer_type __p,
  605. memory_order __m = memory_order_seq_cst) noexcept
  606. {
  607. return __atomic_exchange_n(&_M_p, __p, __m);
  608. }
  609. __always_inline __pointer_type
  610. exchange(__pointer_type __p,
  611. memory_order __m = memory_order_seq_cst) volatile noexcept
  612. {
  613. return __atomic_exchange_n(&_M_p, __p, __m);
  614. }
  615. __always_inline bool
  616. compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
  617. memory_order __m1,
  618. memory_order __m2) noexcept
  619. {
  620. // __glibcxx_assert(__m2 != memory_order_release);
  621. // __glibcxx_assert(__m2 != memory_order_acq_rel);
  622. // __glibcxx_assert(__m2 <= __m1);
  623. return __atomic_compare_exchange_n(&_M_p, &__p1, __p2, 0, __m1, __m2);
  624. }
  625. __always_inline bool
  626. compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
  627. memory_order __m1,
  628. memory_order __m2) volatile noexcept
  629. {
  630. // __glibcxx_assert(__m2 != memory_order_release);
  631. // __glibcxx_assert(__m2 != memory_order_acq_rel);
  632. // __glibcxx_assert(__m2 <= __m1);
  633. return __atomic_compare_exchange_n(&_M_p, &__p1, __p2, 0, __m1, __m2);
  634. }
  635. __always_inline __pointer_type
  636. fetch_add(ptrdiff_t __d,
  637. memory_order __m = memory_order_seq_cst) noexcept
  638. { return __atomic_fetch_add(&_M_p, __d, __m); }
  639. __always_inline __pointer_type
  640. fetch_add(ptrdiff_t __d,
  641. memory_order __m = memory_order_seq_cst) volatile noexcept
  642. { return __atomic_fetch_add(&_M_p, __d, __m); }
  643. __always_inline __pointer_type
  644. fetch_sub(ptrdiff_t __d,
  645. memory_order __m = memory_order_seq_cst) noexcept
  646. { return __atomic_fetch_sub(&_M_p, __d, __m); }
  647. __always_inline __pointer_type
  648. fetch_sub(ptrdiff_t __d,
  649. memory_order __m = memory_order_seq_cst) volatile noexcept
  650. { return __atomic_fetch_sub(&_M_p, __d, __m); }
  651. };
  652. /**
  653. * @addtogroup atomics
  654. * @{
  655. */
  656. /// atomic_bool
  657. // NB: No operators or fetch-operations for this type.
  658. struct atomic_bool
  659. {
  660. private:
  661. __atomic_base<bool> _M_base;
  662. public:
  663. atomic_bool() noexcept = default;
  664. ~atomic_bool() noexcept = default;
  665. atomic_bool(const atomic_bool&) = delete;
  666. atomic_bool& operator=(const atomic_bool&) = delete;
  667. atomic_bool& operator=(const atomic_bool&) volatile = delete;
  668. constexpr atomic_bool(bool __i) noexcept : _M_base(__i) { }
  669. bool
  670. operator=(bool __i) noexcept
  671. { return _M_base.operator=(__i); }
  672. operator bool() const noexcept
  673. { return _M_base.load(); }
  674. operator bool() const volatile noexcept
  675. { return _M_base.load(); }
  676. bool
  677. is_lock_free() const noexcept { return _M_base.is_lock_free(); }
  678. bool
  679. is_lock_free() const volatile noexcept { return _M_base.is_lock_free(); }
  680. __always_inline void
  681. store(bool __i, memory_order __m = memory_order_seq_cst) noexcept
  682. { _M_base.store(__i, __m); }
  683. __always_inline void
  684. store(bool __i, memory_order __m = memory_order_seq_cst) volatile noexcept
  685. { _M_base.store(__i, __m); }
  686. __always_inline bool
  687. load(memory_order __m = memory_order_seq_cst) const noexcept
  688. { return _M_base.load(__m); }
  689. __always_inline bool
  690. load(memory_order __m = memory_order_seq_cst) const volatile noexcept
  691. { return _M_base.load(__m); }
  692. __always_inline bool
  693. exchange(bool __i, memory_order __m = memory_order_seq_cst) noexcept
  694. { return _M_base.exchange(__i, __m); }
  695. __always_inline bool
  696. exchange(bool __i,
  697. memory_order __m = memory_order_seq_cst) volatile noexcept
  698. { return _M_base.exchange(__i, __m); }
  699. __always_inline bool
  700. compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
  701. memory_order __m2) noexcept
  702. { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
  703. __always_inline bool
  704. compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
  705. memory_order __m2) volatile noexcept
  706. { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
  707. __always_inline bool
  708. compare_exchange_weak(bool& __i1, bool __i2,
  709. memory_order __m = memory_order_seq_cst) noexcept
  710. { return _M_base.compare_exchange_weak(__i1, __i2, __m); }
  711. __always_inline bool
  712. compare_exchange_weak(bool& __i1, bool __i2,
  713. memory_order __m = memory_order_seq_cst) volatile noexcept
  714. { return _M_base.compare_exchange_weak(__i1, __i2, __m); }
  715. __always_inline bool
  716. compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
  717. memory_order __m2) noexcept
  718. { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
  719. __always_inline bool
  720. compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
  721. memory_order __m2) volatile noexcept
  722. { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
  723. __always_inline bool
  724. compare_exchange_strong(bool& __i1, bool __i2,
  725. memory_order __m = memory_order_seq_cst) noexcept
  726. { return _M_base.compare_exchange_strong(__i1, __i2, __m); }
  727. __always_inline bool
  728. compare_exchange_strong(bool& __i1, bool __i2,
  729. memory_order __m = memory_order_seq_cst) volatile noexcept
  730. { return _M_base.compare_exchange_strong(__i1, __i2, __m); }
  731. };
  732. /// atomic
  733. /// 29.4.3, Generic atomic type, primary class template.
  734. template<typename _Tp>
  735. struct atomic
  736. {
  737. private:
  738. _Tp _M_i;
  739. public:
  740. atomic() noexcept = default;
  741. ~atomic() noexcept = default;
  742. atomic(const atomic&) = delete;
  743. atomic& operator=(const atomic&) = delete;
  744. atomic& operator=(const atomic&) volatile = delete;
  745. constexpr atomic(_Tp __i) noexcept : _M_i(__i) { }
  746. operator _Tp() const noexcept
  747. { return load(); }
  748. operator _Tp() const volatile noexcept
  749. { return load(); }
  750. _Tp
  751. operator=(_Tp __i) noexcept
  752. { store(__i); return __i; }
  753. _Tp
  754. operator=(_Tp __i) volatile noexcept
  755. { store(__i); return __i; }
  756. bool
  757. is_lock_free() const noexcept
  758. { return __atomic_is_lock_free(sizeof(_M_i), &_M_i); }
  759. bool
  760. is_lock_free() const volatile noexcept
  761. { return __atomic_is_lock_free(sizeof(_M_i), &_M_i); }
  762. void
  763. store(_Tp __i, memory_order _m = memory_order_seq_cst) noexcept
  764. { __atomic_store(&_M_i, &__i, _m); }
  765. __always_inline void
  766. store(_Tp __i, memory_order _m = memory_order_seq_cst) volatile noexcept
  767. { __atomic_store(&_M_i, &__i, _m); }
  768. __always_inline _Tp
  769. load(memory_order _m = memory_order_seq_cst) const noexcept
  770. {
  771. _Tp tmp;
  772. __atomic_load(&_M_i, &tmp, _m);
  773. return tmp;
  774. }
  775. __always_inline _Tp
  776. load(memory_order _m = memory_order_seq_cst) const volatile noexcept
  777. {
  778. _Tp tmp;
  779. __atomic_load(&_M_i, &tmp, _m);
  780. return tmp;
  781. }
  782. __always_inline _Tp
  783. exchange(_Tp __i, memory_order _m = memory_order_seq_cst) noexcept
  784. {
  785. _Tp tmp;
  786. __atomic_exchange(&_M_i, &__i, &tmp, _m);
  787. return tmp;
  788. }
  789. __always_inline _Tp
  790. exchange(_Tp __i,
  791. memory_order _m = memory_order_seq_cst) volatile noexcept
  792. {
  793. _Tp tmp;
  794. __atomic_exchange(&_M_i, &__i, &tmp, _m);
  795. return tmp;
  796. }
  797. __always_inline bool
  798. compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
  799. memory_order __f) noexcept
  800. {
  801. return __atomic_compare_exchange(&_M_i, &__e, &__i, true, __s, __f);
  802. }
  803. __always_inline bool
  804. compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
  805. memory_order __f) volatile noexcept
  806. {
  807. return __atomic_compare_exchange(&_M_i, &__e, &__i, true, __s, __f);
  808. }
  809. __always_inline bool
  810. compare_exchange_weak(_Tp& __e, _Tp __i,
  811. memory_order __m = memory_order_seq_cst) noexcept
  812. { return compare_exchange_weak(__e, __i, __m, __m); }
  813. __always_inline bool
  814. compare_exchange_weak(_Tp& __e, _Tp __i,
  815. memory_order __m = memory_order_seq_cst) volatile noexcept
  816. { return compare_exchange_weak(__e, __i, __m, __m); }
  817. __always_inline bool
  818. compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
  819. memory_order __f) noexcept
  820. {
  821. return __atomic_compare_exchange(&_M_i, &__e, &__i, false, __s, __f);
  822. }
  823. __always_inline bool
  824. compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
  825. memory_order __f) volatile noexcept
  826. {
  827. return __atomic_compare_exchange(&_M_i, &__e, &__i, false, __s, __f);
  828. }
  829. __always_inline bool
  830. compare_exchange_strong(_Tp& __e, _Tp __i,
  831. memory_order __m = memory_order_seq_cst) noexcept
  832. { return compare_exchange_strong(__e, __i, __m, __m); }
  833. __always_inline bool
  834. compare_exchange_strong(_Tp& __e, _Tp __i,
  835. memory_order __m = memory_order_seq_cst) volatile noexcept
  836. { return compare_exchange_strong(__e, __i, __m, __m); }
  837. };
  838. /// Partial specialization for pointer types.
  839. template<typename _Tp>
  840. struct atomic<_Tp*>
  841. {
  842. typedef _Tp* __pointer_type;
  843. typedef __atomic_base<_Tp*> __base_type;
  844. __base_type _M_b;
  845. atomic() noexcept = default;
  846. ~atomic() noexcept = default;
  847. atomic(const atomic&) = delete;
  848. atomic& operator=(const atomic&) = delete;
  849. atomic& operator=(const atomic&) volatile = delete;
  850. constexpr atomic(__pointer_type __p) noexcept : _M_b(__p) { }
  851. operator __pointer_type() const noexcept
  852. { return __pointer_type(_M_b); }
  853. operator __pointer_type() const volatile noexcept
  854. { return __pointer_type(_M_b); }
  855. __pointer_type
  856. operator=(__pointer_type __p) noexcept
  857. { return _M_b.operator=(__p); }
  858. __pointer_type
  859. operator=(__pointer_type __p) volatile noexcept
  860. { return _M_b.operator=(__p); }
  861. __pointer_type
  862. operator++(int) noexcept
  863. { return _M_b++; }
  864. __pointer_type
  865. operator++(int) volatile noexcept
  866. { return _M_b++; }
  867. __pointer_type
  868. operator--(int) noexcept
  869. { return _M_b--; }
  870. __pointer_type
  871. operator--(int) volatile noexcept
  872. { return _M_b--; }
  873. __pointer_type
  874. operator++() noexcept
  875. { return ++_M_b; }
  876. __pointer_type
  877. operator++() volatile noexcept
  878. { return ++_M_b; }
  879. __pointer_type
  880. operator--() noexcept
  881. { return --_M_b; }
  882. __pointer_type
  883. operator--() volatile noexcept
  884. { return --_M_b; }
  885. __pointer_type
  886. operator+=(ptrdiff_t __d) noexcept
  887. { return _M_b.operator+=(__d); }
  888. __pointer_type
  889. operator+=(ptrdiff_t __d) volatile noexcept
  890. { return _M_b.operator+=(__d); }
  891. __pointer_type
  892. operator-=(ptrdiff_t __d) noexcept
  893. { return _M_b.operator-=(__d); }
  894. __pointer_type
  895. operator-=(ptrdiff_t __d) volatile noexcept
  896. { return _M_b.operator-=(__d); }
  897. bool
  898. is_lock_free() const noexcept
  899. { return _M_b.is_lock_free(); }
  900. bool
  901. is_lock_free() const volatile noexcept
  902. { return _M_b.is_lock_free(); }
  903. __always_inline void
  904. store(__pointer_type __p,
  905. memory_order __m = memory_order_seq_cst) noexcept
  906. { return _M_b.store(__p, __m); }
  907. __always_inline void
  908. store(__pointer_type __p,
  909. memory_order __m = memory_order_seq_cst) volatile noexcept
  910. { return _M_b.store(__p, __m); }
  911. __always_inline __pointer_type
  912. load(memory_order __m = memory_order_seq_cst) const noexcept
  913. { return _M_b.load(__m); }
  914. __always_inline __pointer_type
  915. load(memory_order __m = memory_order_seq_cst) const volatile noexcept
  916. { return _M_b.load(__m); }
  917. __always_inline __pointer_type
  918. exchange(__pointer_type __p,
  919. memory_order __m = memory_order_seq_cst) noexcept
  920. { return _M_b.exchange(__p, __m); }
  921. __always_inline __pointer_type
  922. exchange(__pointer_type __p,
  923. memory_order __m = memory_order_seq_cst) volatile noexcept
  924. { return _M_b.exchange(__p, __m); }
  925. __always_inline bool
  926. compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
  927. memory_order __m1, memory_order __m2) noexcept
  928. { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
  929. __always_inline bool
  930. compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
  931. memory_order __m1,
  932. memory_order __m2) volatile noexcept
  933. { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
  934. __always_inline bool
  935. compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
  936. memory_order __m = memory_order_seq_cst) noexcept
  937. {
  938. return compare_exchange_weak(__p1, __p2, __m,
  939. __calculate_memory_order(__m));
  940. }
  941. __always_inline bool
  942. compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
  943. memory_order __m = memory_order_seq_cst) volatile noexcept
  944. {
  945. return compare_exchange_weak(__p1, __p2, __m,
  946. __calculate_memory_order(__m));
  947. }
  948. __always_inline bool
  949. compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
  950. memory_order __m1, memory_order __m2) noexcept
  951. { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
  952. __always_inline bool
  953. compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
  954. memory_order __m1,
  955. memory_order __m2) volatile noexcept
  956. { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
  957. __always_inline bool
  958. compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
  959. memory_order __m = memory_order_seq_cst) noexcept
  960. {
  961. return _M_b.compare_exchange_strong(__p1, __p2, __m,
  962. __calculate_memory_order(__m));
  963. }
  964. __always_inline bool
  965. compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
  966. memory_order __m = memory_order_seq_cst) volatile noexcept
  967. {
  968. return _M_b.compare_exchange_strong(__p1, __p2, __m,
  969. __calculate_memory_order(__m));
  970. }
  971. __always_inline __pointer_type
  972. fetch_add(ptrdiff_t __d,
  973. memory_order __m = memory_order_seq_cst) noexcept
  974. { return _M_b.fetch_add(__d, __m); }
  975. __always_inline __pointer_type
  976. fetch_add(ptrdiff_t __d,
  977. memory_order __m = memory_order_seq_cst) volatile noexcept
  978. { return _M_b.fetch_add(__d, __m); }
  979. __always_inline __pointer_type
  980. fetch_sub(ptrdiff_t __d,
  981. memory_order __m = memory_order_seq_cst) noexcept
  982. { return _M_b.fetch_sub(__d, __m); }
  983. __always_inline __pointer_type
  984. fetch_sub(ptrdiff_t __d,
  985. memory_order __m = memory_order_seq_cst) volatile noexcept
  986. { return _M_b.fetch_sub(__d, __m); }
  987. };
  988. /// Explicit specialization for bool.
  989. template<>
  990. struct atomic<bool> : public atomic_bool
  991. {
  992. typedef bool __integral_type;
  993. typedef atomic_bool __base_type;
  994. atomic() noexcept = default;
  995. ~atomic() noexcept = default;
  996. atomic(const atomic&) = delete;
  997. atomic& operator=(const atomic&) = delete;
  998. atomic& operator=(const atomic&) volatile = delete;
  999. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1000. using __base_type::operator __integral_type;
  1001. using __base_type::operator=;
  1002. };
  1003. /// Explicit specialization for char.
  1004. template<>
  1005. struct atomic<char> : public atomic_char
  1006. {
  1007. typedef char __integral_type;
  1008. typedef atomic_char __base_type;
  1009. atomic() noexcept = default;
  1010. ~atomic() noexcept = default;
  1011. atomic(const atomic&) = delete;
  1012. atomic& operator=(const atomic&) = delete;
  1013. atomic& operator=(const atomic&) volatile = delete;
  1014. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1015. using __base_type::operator __integral_type;
  1016. using __base_type::operator=;
  1017. };
  1018. /// Explicit specialization for signed char.
  1019. template<>
  1020. struct atomic<signed char> : public atomic_schar
  1021. {
  1022. typedef signed char __integral_type;
  1023. typedef atomic_schar __base_type;
  1024. atomic() noexcept= default;
  1025. ~atomic() noexcept = default;
  1026. atomic(const atomic&) = delete;
  1027. atomic& operator=(const atomic&) = delete;
  1028. atomic& operator=(const atomic&) volatile = delete;
  1029. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1030. using __base_type::operator __integral_type;
  1031. using __base_type::operator=;
  1032. };
  1033. /// Explicit specialization for unsigned char.
  1034. template<>
  1035. struct atomic<unsigned char> : public atomic_uchar
  1036. {
  1037. typedef unsigned char __integral_type;
  1038. typedef atomic_uchar __base_type;
  1039. atomic() noexcept= default;
  1040. ~atomic() noexcept = default;
  1041. atomic(const atomic&) = delete;
  1042. atomic& operator=(const atomic&) = delete;
  1043. atomic& operator=(const atomic&) volatile = delete;
  1044. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1045. using __base_type::operator __integral_type;
  1046. using __base_type::operator=;
  1047. };
  1048. /// Explicit specialization for short.
  1049. template<>
  1050. struct atomic<short> : public atomic_short
  1051. {
  1052. typedef short __integral_type;
  1053. typedef atomic_short __base_type;
  1054. atomic() noexcept = default;
  1055. ~atomic() noexcept = default;
  1056. atomic(const atomic&) = delete;
  1057. atomic& operator=(const atomic&) = delete;
  1058. atomic& operator=(const atomic&) volatile = delete;
  1059. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1060. using __base_type::operator __integral_type;
  1061. using __base_type::operator=;
  1062. };
  1063. /// Explicit specialization for unsigned short.
  1064. template<>
  1065. struct atomic<unsigned short> : public atomic_ushort
  1066. {
  1067. typedef unsigned short __integral_type;
  1068. typedef atomic_ushort __base_type;
  1069. atomic() noexcept = default;
  1070. ~atomic() noexcept = default;
  1071. atomic(const atomic&) = delete;
  1072. atomic& operator=(const atomic&) = delete;
  1073. atomic& operator=(const atomic&) volatile = delete;
  1074. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1075. using __base_type::operator __integral_type;
  1076. using __base_type::operator=;
  1077. };
  1078. /// Explicit specialization for int.
  1079. template<>
  1080. struct atomic<int> : atomic_int
  1081. {
  1082. typedef int __integral_type;
  1083. typedef atomic_int __base_type;
  1084. atomic() noexcept = default;
  1085. ~atomic() noexcept = default;
  1086. atomic(const atomic&) = delete;
  1087. atomic& operator=(const atomic&) = delete;
  1088. atomic& operator=(const atomic&) volatile = delete;
  1089. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1090. using __base_type::operator __integral_type;
  1091. using __base_type::operator=;
  1092. };
  1093. /// Explicit specialization for unsigned int.
  1094. template<>
  1095. struct atomic<unsigned int> : public atomic_uint
  1096. {
  1097. typedef unsigned int __integral_type;
  1098. typedef atomic_uint __base_type;
  1099. atomic() noexcept = default;
  1100. ~atomic() noexcept = default;
  1101. atomic(const atomic&) = delete;
  1102. atomic& operator=(const atomic&) = delete;
  1103. atomic& operator=(const atomic&) volatile = delete;
  1104. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1105. using __base_type::operator __integral_type;
  1106. using __base_type::operator=;
  1107. };
  1108. /// Explicit specialization for long.
  1109. template<>
  1110. struct atomic<long> : public atomic_long
  1111. {
  1112. typedef long __integral_type;
  1113. typedef atomic_long __base_type;
  1114. atomic() noexcept = default;
  1115. ~atomic() noexcept = default;
  1116. atomic(const atomic&) = delete;
  1117. atomic& operator=(const atomic&) = delete;
  1118. atomic& operator=(const atomic&) volatile = delete;
  1119. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1120. using __base_type::operator __integral_type;
  1121. using __base_type::operator=;
  1122. };
  1123. /// Explicit specialization for unsigned long.
  1124. template<>
  1125. struct atomic<unsigned long> : public atomic_ulong
  1126. {
  1127. typedef unsigned long __integral_type;
  1128. typedef atomic_ulong __base_type;
  1129. atomic() noexcept = default;
  1130. ~atomic() noexcept = default;
  1131. atomic(const atomic&) = delete;
  1132. atomic& operator=(const atomic&) = delete;
  1133. atomic& operator=(const atomic&) volatile = delete;
  1134. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1135. using __base_type::operator __integral_type;
  1136. using __base_type::operator=;
  1137. };
  1138. /// Explicit specialization for long long.
  1139. template<>
  1140. struct atomic<long long> : public atomic_llong
  1141. {
  1142. typedef long long __integral_type;
  1143. typedef atomic_llong __base_type;
  1144. atomic() noexcept = default;
  1145. ~atomic() noexcept = default;
  1146. atomic(const atomic&) = delete;
  1147. atomic& operator=(const atomic&) = delete;
  1148. atomic& operator=(const atomic&) volatile = delete;
  1149. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1150. using __base_type::operator __integral_type;
  1151. using __base_type::operator=;
  1152. };
  1153. /// Explicit specialization for unsigned long long.
  1154. template<>
  1155. struct atomic<unsigned long long> : public atomic_ullong
  1156. {
  1157. typedef unsigned long long __integral_type;
  1158. typedef atomic_ullong __base_type;
  1159. atomic() noexcept = default;
  1160. ~atomic() noexcept = default;
  1161. atomic(const atomic&) = delete;
  1162. atomic& operator=(const atomic&) = delete;
  1163. atomic& operator=(const atomic&) volatile = delete;
  1164. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1165. using __base_type::operator __integral_type;
  1166. using __base_type::operator=;
  1167. };
  1168. /// Explicit specialization for wchar_t.
  1169. template<>
  1170. struct atomic<wchar_t> : public atomic_wchar_t
  1171. {
  1172. typedef wchar_t __integral_type;
  1173. typedef atomic_wchar_t __base_type;
  1174. atomic() noexcept = default;
  1175. ~atomic() noexcept = default;
  1176. atomic(const atomic&) = delete;
  1177. atomic& operator=(const atomic&) = delete;
  1178. atomic& operator=(const atomic&) volatile = delete;
  1179. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1180. using __base_type::operator __integral_type;
  1181. using __base_type::operator=;
  1182. };
  1183. /// Explicit specialization for char16_t.
  1184. template<>
  1185. struct atomic<char16_t> : public atomic_char16_t
  1186. {
  1187. typedef char16_t __integral_type;
  1188. typedef atomic_char16_t __base_type;
  1189. atomic() noexcept = default;
  1190. ~atomic() noexcept = default;
  1191. atomic(const atomic&) = delete;
  1192. atomic& operator=(const atomic&) = delete;
  1193. atomic& operator=(const atomic&) volatile = delete;
  1194. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1195. using __base_type::operator __integral_type;
  1196. using __base_type::operator=;
  1197. };
  1198. /// Explicit specialization for char32_t.
  1199. template<>
  1200. struct atomic<char32_t> : public atomic_char32_t
  1201. {
  1202. typedef char32_t __integral_type;
  1203. typedef atomic_char32_t __base_type;
  1204. atomic() noexcept = default;
  1205. ~atomic() noexcept = default;
  1206. atomic(const atomic&) = delete;
  1207. atomic& operator=(const atomic&) = delete;
  1208. atomic& operator=(const atomic&) volatile = delete;
  1209. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  1210. using __base_type::operator __integral_type;
  1211. using __base_type::operator=;
  1212. };
  1213. // Function definitions, atomic_flag operations.
  1214. inline __always_inline bool
  1215. atomic_flag_test_and_set_explicit(atomic_flag* __a,
  1216. memory_order __m) noexcept
  1217. { return __a->test_and_set(__m); }
  1218. inline __always_inline bool
  1219. atomic_flag_test_and_set_explicit(volatile atomic_flag* __a,
  1220. memory_order __m) noexcept
  1221. { return __a->test_and_set(__m); }
  1222. inline __always_inline void
  1223. atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept
  1224. { __a->clear(__m); }
  1225. inline __always_inline void
  1226. atomic_flag_clear_explicit(volatile atomic_flag* __a,
  1227. memory_order __m) noexcept
  1228. { __a->clear(__m); }
  1229. inline __always_inline bool
  1230. atomic_flag_test_and_set(atomic_flag* __a) noexcept
  1231. { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
  1232. inline __always_inline bool
  1233. atomic_flag_test_and_set(volatile atomic_flag* __a) noexcept
  1234. { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
  1235. inline __always_inline void
  1236. atomic_flag_clear(atomic_flag* __a) noexcept
  1237. { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
  1238. inline __always_inline void
  1239. atomic_flag_clear(volatile atomic_flag* __a) noexcept
  1240. { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
  1241. // Function templates generally applicable to atomic types.
  1242. template<typename _ITp>
  1243. __always_inline bool
  1244. atomic_is_lock_free(const atomic<_ITp>* __a) noexcept
  1245. { return __a->is_lock_free(); }
  1246. template<typename _ITp>
  1247. __always_inline bool
  1248. atomic_is_lock_free(const volatile atomic<_ITp>* __a) noexcept
  1249. { return __a->is_lock_free(); }
  1250. template<typename _ITp>
  1251. __always_inline void
  1252. atomic_init(atomic<_ITp>* __a, _ITp __i) noexcept;
  1253. template<typename _ITp>
  1254. __always_inline void
  1255. atomic_init(volatile atomic<_ITp>* __a, _ITp __i) noexcept;
  1256. template<typename _ITp>
  1257. __always_inline void
  1258. atomic_store_explicit(atomic<_ITp>* __a, _ITp __i,
  1259. memory_order __m) noexcept
  1260. { __a->store(__i, __m); }
  1261. template<typename _ITp>
  1262. __always_inline void
  1263. atomic_store_explicit(volatile atomic<_ITp>* __a, _ITp __i,
  1264. memory_order __m) noexcept
  1265. { __a->store(__i, __m); }
  1266. template<typename _ITp>
  1267. __always_inline _ITp
  1268. atomic_load_explicit(const atomic<_ITp>* __a, memory_order __m) noexcept
  1269. { return __a->load(__m); }
  1270. template<typename _ITp>
  1271. __always_inline _ITp
  1272. atomic_load_explicit(const volatile atomic<_ITp>* __a,
  1273. memory_order __m) noexcept
  1274. { return __a->load(__m); }
  1275. template<typename _ITp>
  1276. __always_inline _ITp
  1277. atomic_exchange_explicit(atomic<_ITp>* __a, _ITp __i,
  1278. memory_order __m) noexcept
  1279. { return __a->exchange(__i, __m); }
  1280. template<typename _ITp>
  1281. __always_inline _ITp
  1282. atomic_exchange_explicit(volatile atomic<_ITp>* __a, _ITp __i,
  1283. memory_order __m) noexcept
  1284. { return __a->exchange(__i, __m); }
  1285. template<typename _ITp>
  1286. __always_inline bool
  1287. atomic_compare_exchange_weak_explicit(atomic<_ITp>* __a,
  1288. _ITp* __i1, _ITp __i2,
  1289. memory_order __m1,
  1290. memory_order __m2) noexcept
  1291. { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
  1292. template<typename _ITp>
  1293. __always_inline bool
  1294. atomic_compare_exchange_weak_explicit(volatile atomic<_ITp>* __a,
  1295. _ITp* __i1, _ITp __i2,
  1296. memory_order __m1,
  1297. memory_order __m2) noexcept
  1298. { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
  1299. template<typename _ITp>
  1300. __always_inline bool
  1301. atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a,
  1302. _ITp* __i1, _ITp __i2,
  1303. memory_order __m1,
  1304. memory_order __m2) noexcept
  1305. { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
  1306. template<typename _ITp>
  1307. __always_inline bool
  1308. atomic_compare_exchange_strong_explicit(volatile atomic<_ITp>* __a,
  1309. _ITp* __i1, _ITp __i2,
  1310. memory_order __m1,
  1311. memory_order __m2) noexcept
  1312. { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
  1313. template<typename _ITp>
  1314. __always_inline void
  1315. atomic_store(atomic<_ITp>* __a, _ITp __i) noexcept
  1316. { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
  1317. template<typename _ITp>
  1318. __always_inline void
  1319. atomic_store(volatile atomic<_ITp>* __a, _ITp __i) noexcept
  1320. { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
  1321. template<typename _ITp>
  1322. __always_inline _ITp
  1323. atomic_load(const atomic<_ITp>* __a) noexcept
  1324. { return atomic_load_explicit(__a, memory_order_seq_cst); }
  1325. template<typename _ITp>
  1326. __always_inline _ITp
  1327. atomic_load(const volatile atomic<_ITp>* __a) noexcept
  1328. { return atomic_load_explicit(__a, memory_order_seq_cst); }
  1329. template<typename _ITp>
  1330. __always_inline _ITp
  1331. atomic_exchange(atomic<_ITp>* __a, _ITp __i) noexcept
  1332. { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
  1333. template<typename _ITp>
  1334. __always_inline _ITp
  1335. atomic_exchange(volatile atomic<_ITp>* __a, _ITp __i) noexcept
  1336. { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
  1337. template<typename _ITp>
  1338. __always_inline bool
  1339. atomic_compare_exchange_weak(atomic<_ITp>* __a,
  1340. _ITp* __i1, _ITp __i2) noexcept
  1341. {
  1342. return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
  1343. memory_order_seq_cst,
  1344. memory_order_seq_cst);
  1345. }
  1346. template<typename _ITp>
  1347. __always_inline bool
  1348. atomic_compare_exchange_weak(volatile atomic<_ITp>* __a,
  1349. _ITp* __i1, _ITp __i2) noexcept
  1350. {
  1351. return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
  1352. memory_order_seq_cst,
  1353. memory_order_seq_cst);
  1354. }
  1355. template<typename _ITp>
  1356. __always_inline bool
  1357. atomic_compare_exchange_strong(atomic<_ITp>* __a,
  1358. _ITp* __i1, _ITp __i2) noexcept
  1359. {
  1360. return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
  1361. memory_order_seq_cst,
  1362. memory_order_seq_cst);
  1363. }
  1364. template<typename _ITp>
  1365. __always_inline bool
  1366. atomic_compare_exchange_strong(volatile atomic<_ITp>* __a,
  1367. _ITp* __i1, _ITp __i2) noexcept
  1368. {
  1369. return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
  1370. memory_order_seq_cst,
  1371. memory_order_seq_cst);
  1372. }
  1373. // Function templates for atomic_integral operations only, using
  1374. // __atomic_base. Template argument should be constricted to
  1375. // intergral types as specified in the standard, excluding address
  1376. // types.
  1377. template<typename _ITp>
  1378. __always_inline _ITp
  1379. atomic_fetch_add_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  1380. memory_order __m) noexcept
  1381. { return __a->fetch_add(__i, __m); }
  1382. template<typename _ITp>
  1383. __always_inline _ITp
  1384. atomic_fetch_add_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  1385. memory_order __m) noexcept
  1386. { return __a->fetch_add(__i, __m); }
  1387. template<typename _ITp>
  1388. __always_inline _ITp
  1389. atomic_fetch_sub_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  1390. memory_order __m) noexcept
  1391. { return __a->fetch_sub(__i, __m); }
  1392. template<typename _ITp>
  1393. __always_inline _ITp
  1394. atomic_fetch_sub_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  1395. memory_order __m) noexcept
  1396. { return __a->fetch_sub(__i, __m); }
  1397. template<typename _ITp>
  1398. __always_inline _ITp
  1399. atomic_fetch_and_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  1400. memory_order __m) noexcept
  1401. { return __a->fetch_and(__i, __m); }
  1402. template<typename _ITp>
  1403. __always_inline _ITp
  1404. atomic_fetch_and_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  1405. memory_order __m) noexcept
  1406. { return __a->fetch_and(__i, __m); }
  1407. template<typename _ITp>
  1408. __always_inline _ITp
  1409. atomic_fetch_or_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  1410. memory_order __m) noexcept
  1411. { return __a->fetch_or(__i, __m); }
  1412. template<typename _ITp>
  1413. __always_inline _ITp
  1414. atomic_fetch_or_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  1415. memory_order __m) noexcept
  1416. { return __a->fetch_or(__i, __m); }
  1417. template<typename _ITp>
  1418. __always_inline _ITp
  1419. atomic_fetch_xor_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  1420. memory_order __m) noexcept
  1421. { return __a->fetch_xor(__i, __m); }
  1422. template<typename _ITp>
  1423. __always_inline _ITp
  1424. atomic_fetch_xor_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  1425. memory_order __m) noexcept
  1426. { return __a->fetch_xor(__i, __m); }
  1427. template<typename _ITp>
  1428. __always_inline _ITp
  1429. atomic_fetch_add(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1430. { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
  1431. template<typename _ITp>
  1432. __always_inline _ITp
  1433. atomic_fetch_add(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1434. { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
  1435. template<typename _ITp>
  1436. __always_inline _ITp
  1437. atomic_fetch_sub(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1438. { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
  1439. template<typename _ITp>
  1440. __always_inline _ITp
  1441. atomic_fetch_sub(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1442. { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
  1443. template<typename _ITp>
  1444. __always_inline _ITp
  1445. atomic_fetch_and(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1446. { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
  1447. template<typename _ITp>
  1448. __always_inline _ITp
  1449. atomic_fetch_and(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1450. { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
  1451. template<typename _ITp>
  1452. __always_inline _ITp
  1453. atomic_fetch_or(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1454. { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
  1455. template<typename _ITp>
  1456. __always_inline _ITp
  1457. atomic_fetch_or(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1458. { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
  1459. template<typename _ITp>
  1460. __always_inline _ITp
  1461. atomic_fetch_xor(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1462. { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
  1463. template<typename _ITp>
  1464. __always_inline _ITp
  1465. atomic_fetch_xor(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1466. { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
  1467. // Partial specializations for pointers.
  1468. template<typename _ITp>
  1469. __always_inline _ITp*
  1470. atomic_fetch_add_explicit(atomic<_ITp*>* __a, ptrdiff_t __d,
  1471. memory_order __m) noexcept
  1472. { return __a->fetch_add(__d, __m); }
  1473. template<typename _ITp>
  1474. __always_inline _ITp*
  1475. atomic_fetch_add_explicit(volatile atomic<_ITp*>* __a, ptrdiff_t __d,
  1476. memory_order __m) noexcept
  1477. { return __a->fetch_add(__d, __m); }
  1478. template<typename _ITp>
  1479. __always_inline _ITp*
  1480. atomic_fetch_add(volatile atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1481. { return __a->fetch_add(__d); }
  1482. template<typename _ITp>
  1483. __always_inline _ITp*
  1484. atomic_fetch_add(atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1485. { return __a->fetch_add(__d); }
  1486. template<typename _ITp>
  1487. __always_inline _ITp*
  1488. atomic_fetch_sub_explicit(volatile atomic<_ITp*>* __a,
  1489. ptrdiff_t __d, memory_order __m) noexcept
  1490. { return __a->fetch_sub(__d, __m); }
  1491. template<typename _ITp>
  1492. __always_inline _ITp*
  1493. atomic_fetch_sub_explicit(atomic<_ITp*>* __a, ptrdiff_t __d,
  1494. memory_order __m) noexcept
  1495. { return __a->fetch_sub(__d, __m); }
  1496. template<typename _ITp>
  1497. __always_inline _ITp*
  1498. atomic_fetch_sub(volatile atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1499. { return __a->fetch_sub(__d); }
  1500. template<typename _ITp>
  1501. __always_inline _ITp*
  1502. atomic_fetch_sub(atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1503. { return __a->fetch_sub(__d); }
  1504. // @} group atomics
  1505. // _GLIBCXX_END_NAMESPACE_VERSION
  1506. } // namespace
  1507. #endif