atomic 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  1. // -*- C++ -*- header.
  2. // Copyright (C) 2008-2018 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. /** @file include/atomic
  21. * This is a Standard C++ Library header.
  22. */
  23. // Based on "C++ Atomic Types and Operations" by Hans Boehm and Lawrence Crowl.
  24. // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2427.html
  25. #ifndef _GLIBCXX_ATOMIC
  26. #define _GLIBCXX_ATOMIC 1
  27. #pragma GCC system_header
  28. #if __cplusplus < 201103L
  29. # include <bits/c++0x_warning.h>
  30. #else
  31. #include <bits/atomic_base.h>
  32. #include <bits/move.h>
  33. namespace std _GLIBCXX_VISIBILITY(default)
  34. {
  35. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  36. /**
  37. * @addtogroup atomics
  38. * @{
  39. */
  40. #if __cplusplus > 201402L
  41. # define __cpp_lib_atomic_is_always_lock_free 201603
  42. #endif
  43. template<typename _Tp>
  44. struct atomic;
  45. /// atomic<bool>
  46. // NB: No operators or fetch-operations for this type.
  47. template<>
  48. struct atomic<bool>
  49. {
  50. private:
  51. __atomic_base<bool> _M_base;
  52. public:
  53. atomic() noexcept = default;
  54. ~atomic() noexcept = default;
  55. atomic(const atomic&) = delete;
  56. atomic& operator=(const atomic&) = delete;
  57. atomic& operator=(const atomic&) volatile = delete;
  58. constexpr atomic(bool __i) noexcept : _M_base(__i) { }
  59. bool
  60. operator=(bool __i) noexcept
  61. { return _M_base.operator=(__i); }
  62. bool
  63. operator=(bool __i) volatile noexcept
  64. { return _M_base.operator=(__i); }
  65. operator bool() const noexcept
  66. { return _M_base.load(); }
  67. operator bool() const volatile noexcept
  68. { return _M_base.load(); }
  69. bool
  70. is_lock_free() const noexcept { return _M_base.is_lock_free(); }
  71. bool
  72. is_lock_free() const volatile noexcept { return _M_base.is_lock_free(); }
  73. #if __cplusplus > 201402L
  74. static constexpr bool is_always_lock_free = ATOMIC_BOOL_LOCK_FREE == 2;
  75. #endif
  76. void
  77. store(bool __i, memory_order __m = memory_order_seq_cst) noexcept
  78. { _M_base.store(__i, __m); }
  79. void
  80. store(bool __i, memory_order __m = memory_order_seq_cst) volatile noexcept
  81. { _M_base.store(__i, __m); }
  82. bool
  83. load(memory_order __m = memory_order_seq_cst) const noexcept
  84. { return _M_base.load(__m); }
  85. bool
  86. load(memory_order __m = memory_order_seq_cst) const volatile noexcept
  87. { return _M_base.load(__m); }
  88. bool
  89. exchange(bool __i, memory_order __m = memory_order_seq_cst) noexcept
  90. { return _M_base.exchange(__i, __m); }
  91. bool
  92. exchange(bool __i,
  93. memory_order __m = memory_order_seq_cst) volatile noexcept
  94. { return _M_base.exchange(__i, __m); }
  95. bool
  96. compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
  97. memory_order __m2) noexcept
  98. { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
  99. bool
  100. compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1,
  101. memory_order __m2) volatile noexcept
  102. { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); }
  103. bool
  104. compare_exchange_weak(bool& __i1, bool __i2,
  105. memory_order __m = memory_order_seq_cst) noexcept
  106. { return _M_base.compare_exchange_weak(__i1, __i2, __m); }
  107. bool
  108. compare_exchange_weak(bool& __i1, bool __i2,
  109. memory_order __m = memory_order_seq_cst) volatile noexcept
  110. { return _M_base.compare_exchange_weak(__i1, __i2, __m); }
  111. bool
  112. compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
  113. memory_order __m2) noexcept
  114. { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
  115. bool
  116. compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1,
  117. memory_order __m2) volatile noexcept
  118. { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); }
  119. bool
  120. compare_exchange_strong(bool& __i1, bool __i2,
  121. memory_order __m = memory_order_seq_cst) noexcept
  122. { return _M_base.compare_exchange_strong(__i1, __i2, __m); }
  123. bool
  124. compare_exchange_strong(bool& __i1, bool __i2,
  125. memory_order __m = memory_order_seq_cst) volatile noexcept
  126. { return _M_base.compare_exchange_strong(__i1, __i2, __m); }
  127. };
  128. /**
  129. * @brief Generic atomic type, primary class template.
  130. *
  131. * @tparam _Tp Type to be made atomic, must be trivally copyable.
  132. */
  133. template<typename _Tp>
  134. struct atomic
  135. {
  136. private:
  137. // Align 1/2/4/8/16-byte types to at least their size.
  138. static constexpr int _S_min_alignment
  139. = (sizeof(_Tp) & (sizeof(_Tp) - 1)) || sizeof(_Tp) > 16
  140. ? 0 : sizeof(_Tp);
  141. static constexpr int _S_alignment
  142. = _S_min_alignment > alignof(_Tp) ? _S_min_alignment : alignof(_Tp);
  143. alignas(_S_alignment) _Tp _M_i;
  144. static_assert(__is_trivially_copyable(_Tp),
  145. "std::atomic requires a trivially copyable type");
  146. static_assert(sizeof(_Tp) > 0,
  147. "Incomplete or zero-sized types are not supported");
  148. public:
  149. atomic() noexcept = default;
  150. ~atomic() noexcept = default;
  151. atomic(const atomic&) = delete;
  152. atomic& operator=(const atomic&) = delete;
  153. atomic& operator=(const atomic&) volatile = delete;
  154. constexpr atomic(_Tp __i) noexcept : _M_i(__i) { }
  155. operator _Tp() const noexcept
  156. { return load(); }
  157. operator _Tp() const volatile noexcept
  158. { return load(); }
  159. _Tp
  160. operator=(_Tp __i) noexcept
  161. { store(__i); return __i; }
  162. _Tp
  163. operator=(_Tp __i) volatile noexcept
  164. { store(__i); return __i; }
  165. bool
  166. is_lock_free() const noexcept
  167. {
  168. // Produce a fake, minimally aligned pointer.
  169. return __atomic_is_lock_free(sizeof(_M_i),
  170. reinterpret_cast<void *>(-__alignof(_M_i)));
  171. }
  172. bool
  173. is_lock_free() const volatile noexcept
  174. {
  175. // Produce a fake, minimally aligned pointer.
  176. return __atomic_is_lock_free(sizeof(_M_i),
  177. reinterpret_cast<void *>(-__alignof(_M_i)));
  178. }
  179. #if __cplusplus > 201402L
  180. static constexpr bool is_always_lock_free
  181. = __atomic_always_lock_free(sizeof(_M_i), 0);
  182. #endif
  183. void
  184. store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
  185. { __atomic_store(std::__addressof(_M_i), std::__addressof(__i), __m); }
  186. void
  187. store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile noexcept
  188. { __atomic_store(std::__addressof(_M_i), std::__addressof(__i), __m); }
  189. _Tp
  190. load(memory_order __m = memory_order_seq_cst) const noexcept
  191. {
  192. alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
  193. _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
  194. __atomic_load(std::__addressof(_M_i), __ptr, __m);
  195. return *__ptr;
  196. }
  197. _Tp
  198. load(memory_order __m = memory_order_seq_cst) const volatile noexcept
  199. {
  200. alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
  201. _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
  202. __atomic_load(std::__addressof(_M_i), __ptr, __m);
  203. return *__ptr;
  204. }
  205. _Tp
  206. exchange(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
  207. {
  208. alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
  209. _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
  210. __atomic_exchange(std::__addressof(_M_i), std::__addressof(__i),
  211. __ptr, __m);
  212. return *__ptr;
  213. }
  214. _Tp
  215. exchange(_Tp __i,
  216. memory_order __m = memory_order_seq_cst) volatile noexcept
  217. {
  218. alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
  219. _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
  220. __atomic_exchange(std::__addressof(_M_i), std::__addressof(__i),
  221. __ptr, __m);
  222. return *__ptr;
  223. }
  224. bool
  225. compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
  226. memory_order __f) noexcept
  227. {
  228. return __atomic_compare_exchange(std::__addressof(_M_i),
  229. std::__addressof(__e),
  230. std::__addressof(__i),
  231. true, __s, __f);
  232. }
  233. bool
  234. compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
  235. memory_order __f) volatile noexcept
  236. {
  237. return __atomic_compare_exchange(std::__addressof(_M_i),
  238. std::__addressof(__e),
  239. std::__addressof(__i),
  240. true, __s, __f);
  241. }
  242. bool
  243. compare_exchange_weak(_Tp& __e, _Tp __i,
  244. memory_order __m = memory_order_seq_cst) noexcept
  245. { return compare_exchange_weak(__e, __i, __m,
  246. __cmpexch_failure_order(__m)); }
  247. bool
  248. compare_exchange_weak(_Tp& __e, _Tp __i,
  249. memory_order __m = memory_order_seq_cst) volatile noexcept
  250. { return compare_exchange_weak(__e, __i, __m,
  251. __cmpexch_failure_order(__m)); }
  252. bool
  253. compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
  254. memory_order __f) noexcept
  255. {
  256. return __atomic_compare_exchange(std::__addressof(_M_i),
  257. std::__addressof(__e),
  258. std::__addressof(__i),
  259. false, __s, __f);
  260. }
  261. bool
  262. compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
  263. memory_order __f) volatile noexcept
  264. {
  265. return __atomic_compare_exchange(std::__addressof(_M_i),
  266. std::__addressof(__e),
  267. std::__addressof(__i),
  268. false, __s, __f);
  269. }
  270. bool
  271. compare_exchange_strong(_Tp& __e, _Tp __i,
  272. memory_order __m = memory_order_seq_cst) noexcept
  273. { return compare_exchange_strong(__e, __i, __m,
  274. __cmpexch_failure_order(__m)); }
  275. bool
  276. compare_exchange_strong(_Tp& __e, _Tp __i,
  277. memory_order __m = memory_order_seq_cst) volatile noexcept
  278. { return compare_exchange_strong(__e, __i, __m,
  279. __cmpexch_failure_order(__m)); }
  280. };
  281. /// Partial specialization for pointer types.
  282. template<typename _Tp>
  283. struct atomic<_Tp*>
  284. {
  285. typedef _Tp* __pointer_type;
  286. typedef __atomic_base<_Tp*> __base_type;
  287. __base_type _M_b;
  288. atomic() noexcept = default;
  289. ~atomic() noexcept = default;
  290. atomic(const atomic&) = delete;
  291. atomic& operator=(const atomic&) = delete;
  292. atomic& operator=(const atomic&) volatile = delete;
  293. constexpr atomic(__pointer_type __p) noexcept : _M_b(__p) { }
  294. operator __pointer_type() const noexcept
  295. { return __pointer_type(_M_b); }
  296. operator __pointer_type() const volatile noexcept
  297. { return __pointer_type(_M_b); }
  298. __pointer_type
  299. operator=(__pointer_type __p) noexcept
  300. { return _M_b.operator=(__p); }
  301. __pointer_type
  302. operator=(__pointer_type __p) volatile noexcept
  303. { return _M_b.operator=(__p); }
  304. __pointer_type
  305. operator++(int) noexcept
  306. { return _M_b++; }
  307. __pointer_type
  308. operator++(int) volatile noexcept
  309. { return _M_b++; }
  310. __pointer_type
  311. operator--(int) noexcept
  312. { return _M_b--; }
  313. __pointer_type
  314. operator--(int) volatile noexcept
  315. { return _M_b--; }
  316. __pointer_type
  317. operator++() noexcept
  318. { return ++_M_b; }
  319. __pointer_type
  320. operator++() volatile noexcept
  321. { return ++_M_b; }
  322. __pointer_type
  323. operator--() noexcept
  324. { return --_M_b; }
  325. __pointer_type
  326. operator--() volatile noexcept
  327. { return --_M_b; }
  328. __pointer_type
  329. operator+=(ptrdiff_t __d) noexcept
  330. { return _M_b.operator+=(__d); }
  331. __pointer_type
  332. operator+=(ptrdiff_t __d) volatile noexcept
  333. { return _M_b.operator+=(__d); }
  334. __pointer_type
  335. operator-=(ptrdiff_t __d) noexcept
  336. { return _M_b.operator-=(__d); }
  337. __pointer_type
  338. operator-=(ptrdiff_t __d) volatile noexcept
  339. { return _M_b.operator-=(__d); }
  340. bool
  341. is_lock_free() const noexcept
  342. { return _M_b.is_lock_free(); }
  343. bool
  344. is_lock_free() const volatile noexcept
  345. { return _M_b.is_lock_free(); }
  346. #if __cplusplus > 201402L
  347. static constexpr bool is_always_lock_free = ATOMIC_POINTER_LOCK_FREE == 2;
  348. #endif
  349. void
  350. store(__pointer_type __p,
  351. memory_order __m = memory_order_seq_cst) noexcept
  352. { return _M_b.store(__p, __m); }
  353. void
  354. store(__pointer_type __p,
  355. memory_order __m = memory_order_seq_cst) volatile noexcept
  356. { return _M_b.store(__p, __m); }
  357. __pointer_type
  358. load(memory_order __m = memory_order_seq_cst) const noexcept
  359. { return _M_b.load(__m); }
  360. __pointer_type
  361. load(memory_order __m = memory_order_seq_cst) const volatile noexcept
  362. { return _M_b.load(__m); }
  363. __pointer_type
  364. exchange(__pointer_type __p,
  365. memory_order __m = memory_order_seq_cst) noexcept
  366. { return _M_b.exchange(__p, __m); }
  367. __pointer_type
  368. exchange(__pointer_type __p,
  369. memory_order __m = memory_order_seq_cst) volatile noexcept
  370. { return _M_b.exchange(__p, __m); }
  371. bool
  372. compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
  373. memory_order __m1, memory_order __m2) noexcept
  374. { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
  375. bool
  376. compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
  377. memory_order __m1,
  378. memory_order __m2) volatile noexcept
  379. { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
  380. bool
  381. compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
  382. memory_order __m = memory_order_seq_cst) noexcept
  383. {
  384. return compare_exchange_weak(__p1, __p2, __m,
  385. __cmpexch_failure_order(__m));
  386. }
  387. bool
  388. compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2,
  389. memory_order __m = memory_order_seq_cst) volatile noexcept
  390. {
  391. return compare_exchange_weak(__p1, __p2, __m,
  392. __cmpexch_failure_order(__m));
  393. }
  394. bool
  395. compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
  396. memory_order __m1, memory_order __m2) noexcept
  397. { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
  398. bool
  399. compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
  400. memory_order __m1,
  401. memory_order __m2) volatile noexcept
  402. { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); }
  403. bool
  404. compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
  405. memory_order __m = memory_order_seq_cst) noexcept
  406. {
  407. return _M_b.compare_exchange_strong(__p1, __p2, __m,
  408. __cmpexch_failure_order(__m));
  409. }
  410. bool
  411. compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2,
  412. memory_order __m = memory_order_seq_cst) volatile noexcept
  413. {
  414. return _M_b.compare_exchange_strong(__p1, __p2, __m,
  415. __cmpexch_failure_order(__m));
  416. }
  417. __pointer_type
  418. fetch_add(ptrdiff_t __d,
  419. memory_order __m = memory_order_seq_cst) noexcept
  420. { return _M_b.fetch_add(__d, __m); }
  421. __pointer_type
  422. fetch_add(ptrdiff_t __d,
  423. memory_order __m = memory_order_seq_cst) volatile noexcept
  424. { return _M_b.fetch_add(__d, __m); }
  425. __pointer_type
  426. fetch_sub(ptrdiff_t __d,
  427. memory_order __m = memory_order_seq_cst) noexcept
  428. { return _M_b.fetch_sub(__d, __m); }
  429. __pointer_type
  430. fetch_sub(ptrdiff_t __d,
  431. memory_order __m = memory_order_seq_cst) volatile noexcept
  432. { return _M_b.fetch_sub(__d, __m); }
  433. };
  434. /// Explicit specialization for char.
  435. template<>
  436. struct atomic<char> : __atomic_base<char>
  437. {
  438. typedef char __integral_type;
  439. typedef __atomic_base<char> __base_type;
  440. atomic() noexcept = default;
  441. ~atomic() noexcept = default;
  442. atomic(const atomic&) = delete;
  443. atomic& operator=(const atomic&) = delete;
  444. atomic& operator=(const atomic&) volatile = delete;
  445. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  446. using __base_type::operator __integral_type;
  447. using __base_type::operator=;
  448. #if __cplusplus > 201402L
  449. static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
  450. #endif
  451. };
  452. /// Explicit specialization for signed char.
  453. template<>
  454. struct atomic<signed char> : __atomic_base<signed char>
  455. {
  456. typedef signed char __integral_type;
  457. typedef __atomic_base<signed char> __base_type;
  458. atomic() noexcept= default;
  459. ~atomic() noexcept = default;
  460. atomic(const atomic&) = delete;
  461. atomic& operator=(const atomic&) = delete;
  462. atomic& operator=(const atomic&) volatile = delete;
  463. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  464. using __base_type::operator __integral_type;
  465. using __base_type::operator=;
  466. #if __cplusplus > 201402L
  467. static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
  468. #endif
  469. };
  470. /// Explicit specialization for unsigned char.
  471. template<>
  472. struct atomic<unsigned char> : __atomic_base<unsigned char>
  473. {
  474. typedef unsigned char __integral_type;
  475. typedef __atomic_base<unsigned char> __base_type;
  476. atomic() noexcept= default;
  477. ~atomic() noexcept = default;
  478. atomic(const atomic&) = delete;
  479. atomic& operator=(const atomic&) = delete;
  480. atomic& operator=(const atomic&) volatile = delete;
  481. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  482. using __base_type::operator __integral_type;
  483. using __base_type::operator=;
  484. #if __cplusplus > 201402L
  485. static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2;
  486. #endif
  487. };
  488. /// Explicit specialization for short.
  489. template<>
  490. struct atomic<short> : __atomic_base<short>
  491. {
  492. typedef short __integral_type;
  493. typedef __atomic_base<short> __base_type;
  494. atomic() noexcept = default;
  495. ~atomic() noexcept = default;
  496. atomic(const atomic&) = delete;
  497. atomic& operator=(const atomic&) = delete;
  498. atomic& operator=(const atomic&) volatile = delete;
  499. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  500. using __base_type::operator __integral_type;
  501. using __base_type::operator=;
  502. #if __cplusplus > 201402L
  503. static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
  504. #endif
  505. };
  506. /// Explicit specialization for unsigned short.
  507. template<>
  508. struct atomic<unsigned short> : __atomic_base<unsigned short>
  509. {
  510. typedef unsigned short __integral_type;
  511. typedef __atomic_base<unsigned short> __base_type;
  512. atomic() noexcept = default;
  513. ~atomic() noexcept = default;
  514. atomic(const atomic&) = delete;
  515. atomic& operator=(const atomic&) = delete;
  516. atomic& operator=(const atomic&) volatile = delete;
  517. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  518. using __base_type::operator __integral_type;
  519. using __base_type::operator=;
  520. #if __cplusplus > 201402L
  521. static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2;
  522. #endif
  523. };
  524. /// Explicit specialization for int.
  525. template<>
  526. struct atomic<int> : __atomic_base<int>
  527. {
  528. typedef int __integral_type;
  529. typedef __atomic_base<int> __base_type;
  530. atomic() noexcept = default;
  531. ~atomic() noexcept = default;
  532. atomic(const atomic&) = delete;
  533. atomic& operator=(const atomic&) = delete;
  534. atomic& operator=(const atomic&) volatile = delete;
  535. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  536. using __base_type::operator __integral_type;
  537. using __base_type::operator=;
  538. #if __cplusplus > 201402L
  539. static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
  540. #endif
  541. };
  542. /// Explicit specialization for unsigned int.
  543. template<>
  544. struct atomic<unsigned int> : __atomic_base<unsigned int>
  545. {
  546. typedef unsigned int __integral_type;
  547. typedef __atomic_base<unsigned int> __base_type;
  548. atomic() noexcept = default;
  549. ~atomic() noexcept = default;
  550. atomic(const atomic&) = delete;
  551. atomic& operator=(const atomic&) = delete;
  552. atomic& operator=(const atomic&) volatile = delete;
  553. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  554. using __base_type::operator __integral_type;
  555. using __base_type::operator=;
  556. #if __cplusplus > 201402L
  557. static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2;
  558. #endif
  559. };
  560. /// Explicit specialization for long.
  561. template<>
  562. struct atomic<long> : __atomic_base<long>
  563. {
  564. typedef long __integral_type;
  565. typedef __atomic_base<long> __base_type;
  566. atomic() noexcept = default;
  567. ~atomic() noexcept = default;
  568. atomic(const atomic&) = delete;
  569. atomic& operator=(const atomic&) = delete;
  570. atomic& operator=(const atomic&) volatile = delete;
  571. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  572. using __base_type::operator __integral_type;
  573. using __base_type::operator=;
  574. #if __cplusplus > 201402L
  575. static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
  576. #endif
  577. };
  578. /// Explicit specialization for unsigned long.
  579. template<>
  580. struct atomic<unsigned long> : __atomic_base<unsigned long>
  581. {
  582. typedef unsigned long __integral_type;
  583. typedef __atomic_base<unsigned long> __base_type;
  584. atomic() noexcept = default;
  585. ~atomic() noexcept = default;
  586. atomic(const atomic&) = delete;
  587. atomic& operator=(const atomic&) = delete;
  588. atomic& operator=(const atomic&) volatile = delete;
  589. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  590. using __base_type::operator __integral_type;
  591. using __base_type::operator=;
  592. #if __cplusplus > 201402L
  593. static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2;
  594. #endif
  595. };
  596. /// Explicit specialization for long long.
  597. template<>
  598. struct atomic<long long> : __atomic_base<long long>
  599. {
  600. typedef long long __integral_type;
  601. typedef __atomic_base<long long> __base_type;
  602. atomic() noexcept = default;
  603. ~atomic() noexcept = default;
  604. atomic(const atomic&) = delete;
  605. atomic& operator=(const atomic&) = delete;
  606. atomic& operator=(const atomic&) volatile = delete;
  607. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  608. using __base_type::operator __integral_type;
  609. using __base_type::operator=;
  610. #if __cplusplus > 201402L
  611. static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
  612. #endif
  613. };
  614. /// Explicit specialization for unsigned long long.
  615. template<>
  616. struct atomic<unsigned long long> : __atomic_base<unsigned long long>
  617. {
  618. typedef unsigned long long __integral_type;
  619. typedef __atomic_base<unsigned long long> __base_type;
  620. atomic() noexcept = default;
  621. ~atomic() noexcept = default;
  622. atomic(const atomic&) = delete;
  623. atomic& operator=(const atomic&) = delete;
  624. atomic& operator=(const atomic&) volatile = delete;
  625. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  626. using __base_type::operator __integral_type;
  627. using __base_type::operator=;
  628. #if __cplusplus > 201402L
  629. static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2;
  630. #endif
  631. };
  632. /// Explicit specialization for wchar_t.
  633. template<>
  634. struct atomic<wchar_t> : __atomic_base<wchar_t>
  635. {
  636. typedef wchar_t __integral_type;
  637. typedef __atomic_base<wchar_t> __base_type;
  638. atomic() noexcept = default;
  639. ~atomic() noexcept = default;
  640. atomic(const atomic&) = delete;
  641. atomic& operator=(const atomic&) = delete;
  642. atomic& operator=(const atomic&) volatile = delete;
  643. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  644. using __base_type::operator __integral_type;
  645. using __base_type::operator=;
  646. #if __cplusplus > 201402L
  647. static constexpr bool is_always_lock_free = ATOMIC_WCHAR_T_LOCK_FREE == 2;
  648. #endif
  649. };
  650. /// Explicit specialization for char16_t.
  651. template<>
  652. struct atomic<char16_t> : __atomic_base<char16_t>
  653. {
  654. typedef char16_t __integral_type;
  655. typedef __atomic_base<char16_t> __base_type;
  656. atomic() noexcept = default;
  657. ~atomic() noexcept = default;
  658. atomic(const atomic&) = delete;
  659. atomic& operator=(const atomic&) = delete;
  660. atomic& operator=(const atomic&) volatile = delete;
  661. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  662. using __base_type::operator __integral_type;
  663. using __base_type::operator=;
  664. #if __cplusplus > 201402L
  665. static constexpr bool is_always_lock_free = ATOMIC_CHAR16_T_LOCK_FREE == 2;
  666. #endif
  667. };
  668. /// Explicit specialization for char32_t.
  669. template<>
  670. struct atomic<char32_t> : __atomic_base<char32_t>
  671. {
  672. typedef char32_t __integral_type;
  673. typedef __atomic_base<char32_t> __base_type;
  674. atomic() noexcept = default;
  675. ~atomic() noexcept = default;
  676. atomic(const atomic&) = delete;
  677. atomic& operator=(const atomic&) = delete;
  678. atomic& operator=(const atomic&) volatile = delete;
  679. constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { }
  680. using __base_type::operator __integral_type;
  681. using __base_type::operator=;
  682. #if __cplusplus > 201402L
  683. static constexpr bool is_always_lock_free = ATOMIC_CHAR32_T_LOCK_FREE == 2;
  684. #endif
  685. };
  686. /// atomic_bool
  687. typedef atomic<bool> atomic_bool;
  688. /// atomic_char
  689. typedef atomic<char> atomic_char;
  690. /// atomic_schar
  691. typedef atomic<signed char> atomic_schar;
  692. /// atomic_uchar
  693. typedef atomic<unsigned char> atomic_uchar;
  694. /// atomic_short
  695. typedef atomic<short> atomic_short;
  696. /// atomic_ushort
  697. typedef atomic<unsigned short> atomic_ushort;
  698. /// atomic_int
  699. typedef atomic<int> atomic_int;
  700. /// atomic_uint
  701. typedef atomic<unsigned int> atomic_uint;
  702. /// atomic_long
  703. typedef atomic<long> atomic_long;
  704. /// atomic_ulong
  705. typedef atomic<unsigned long> atomic_ulong;
  706. /// atomic_llong
  707. typedef atomic<long long> atomic_llong;
  708. /// atomic_ullong
  709. typedef atomic<unsigned long long> atomic_ullong;
  710. /// atomic_wchar_t
  711. typedef atomic<wchar_t> atomic_wchar_t;
  712. /// atomic_char16_t
  713. typedef atomic<char16_t> atomic_char16_t;
  714. /// atomic_char32_t
  715. typedef atomic<char32_t> atomic_char32_t;
  716. #ifdef _GLIBCXX_USE_C99_STDINT_TR1
  717. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  718. // 2441. Exact-width atomic typedefs should be provided
  719. /// atomic_int8_t
  720. typedef atomic<int8_t> atomic_int8_t;
  721. /// atomic_uint8_t
  722. typedef atomic<uint8_t> atomic_uint8_t;
  723. /// atomic_int16_t
  724. typedef atomic<int16_t> atomic_int16_t;
  725. /// atomic_uint16_t
  726. typedef atomic<uint16_t> atomic_uint16_t;
  727. /// atomic_int32_t
  728. typedef atomic<int32_t> atomic_int32_t;
  729. /// atomic_uint32_t
  730. typedef atomic<uint32_t> atomic_uint32_t;
  731. /// atomic_int64_t
  732. typedef atomic<int64_t> atomic_int64_t;
  733. /// atomic_uint64_t
  734. typedef atomic<uint64_t> atomic_uint64_t;
  735. /// atomic_int_least8_t
  736. typedef atomic<int_least8_t> atomic_int_least8_t;
  737. /// atomic_uint_least8_t
  738. typedef atomic<uint_least8_t> atomic_uint_least8_t;
  739. /// atomic_int_least16_t
  740. typedef atomic<int_least16_t> atomic_int_least16_t;
  741. /// atomic_uint_least16_t
  742. typedef atomic<uint_least16_t> atomic_uint_least16_t;
  743. /// atomic_int_least32_t
  744. typedef atomic<int_least32_t> atomic_int_least32_t;
  745. /// atomic_uint_least32_t
  746. typedef atomic<uint_least32_t> atomic_uint_least32_t;
  747. /// atomic_int_least64_t
  748. typedef atomic<int_least64_t> atomic_int_least64_t;
  749. /// atomic_uint_least64_t
  750. typedef atomic<uint_least64_t> atomic_uint_least64_t;
  751. /// atomic_int_fast8_t
  752. typedef atomic<int_fast8_t> atomic_int_fast8_t;
  753. /// atomic_uint_fast8_t
  754. typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
  755. /// atomic_int_fast16_t
  756. typedef atomic<int_fast16_t> atomic_int_fast16_t;
  757. /// atomic_uint_fast16_t
  758. typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
  759. /// atomic_int_fast32_t
  760. typedef atomic<int_fast32_t> atomic_int_fast32_t;
  761. /// atomic_uint_fast32_t
  762. typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
  763. /// atomic_int_fast64_t
  764. typedef atomic<int_fast64_t> atomic_int_fast64_t;
  765. /// atomic_uint_fast64_t
  766. typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
  767. #endif
  768. /// atomic_intptr_t
  769. typedef atomic<intptr_t> atomic_intptr_t;
  770. /// atomic_uintptr_t
  771. typedef atomic<uintptr_t> atomic_uintptr_t;
  772. /// atomic_size_t
  773. typedef atomic<size_t> atomic_size_t;
  774. /// atomic_ptrdiff_t
  775. typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
  776. #ifdef _GLIBCXX_USE_C99_STDINT_TR1
  777. /// atomic_intmax_t
  778. typedef atomic<intmax_t> atomic_intmax_t;
  779. /// atomic_uintmax_t
  780. typedef atomic<uintmax_t> atomic_uintmax_t;
  781. #endif
  782. // Function definitions, atomic_flag operations.
  783. inline bool
  784. atomic_flag_test_and_set_explicit(atomic_flag* __a,
  785. memory_order __m) noexcept
  786. { return __a->test_and_set(__m); }
  787. inline bool
  788. atomic_flag_test_and_set_explicit(volatile atomic_flag* __a,
  789. memory_order __m) noexcept
  790. { return __a->test_and_set(__m); }
  791. inline void
  792. atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept
  793. { __a->clear(__m); }
  794. inline void
  795. atomic_flag_clear_explicit(volatile atomic_flag* __a,
  796. memory_order __m) noexcept
  797. { __a->clear(__m); }
  798. inline bool
  799. atomic_flag_test_and_set(atomic_flag* __a) noexcept
  800. { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
  801. inline bool
  802. atomic_flag_test_and_set(volatile atomic_flag* __a) noexcept
  803. { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
  804. inline void
  805. atomic_flag_clear(atomic_flag* __a) noexcept
  806. { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
  807. inline void
  808. atomic_flag_clear(volatile atomic_flag* __a) noexcept
  809. { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
  810. // Function templates generally applicable to atomic types.
  811. template<typename _ITp>
  812. inline bool
  813. atomic_is_lock_free(const atomic<_ITp>* __a) noexcept
  814. { return __a->is_lock_free(); }
  815. template<typename _ITp>
  816. inline bool
  817. atomic_is_lock_free(const volatile atomic<_ITp>* __a) noexcept
  818. { return __a->is_lock_free(); }
  819. template<typename _ITp>
  820. inline void
  821. atomic_init(atomic<_ITp>* __a, _ITp __i) noexcept
  822. { __a->store(__i, memory_order_relaxed); }
  823. template<typename _ITp>
  824. inline void
  825. atomic_init(volatile atomic<_ITp>* __a, _ITp __i) noexcept
  826. { __a->store(__i, memory_order_relaxed); }
  827. template<typename _ITp>
  828. inline void
  829. atomic_store_explicit(atomic<_ITp>* __a, _ITp __i,
  830. memory_order __m) noexcept
  831. { __a->store(__i, __m); }
  832. template<typename _ITp>
  833. inline void
  834. atomic_store_explicit(volatile atomic<_ITp>* __a, _ITp __i,
  835. memory_order __m) noexcept
  836. { __a->store(__i, __m); }
  837. template<typename _ITp>
  838. inline _ITp
  839. atomic_load_explicit(const atomic<_ITp>* __a, memory_order __m) noexcept
  840. { return __a->load(__m); }
  841. template<typename _ITp>
  842. inline _ITp
  843. atomic_load_explicit(const volatile atomic<_ITp>* __a,
  844. memory_order __m) noexcept
  845. { return __a->load(__m); }
  846. template<typename _ITp>
  847. inline _ITp
  848. atomic_exchange_explicit(atomic<_ITp>* __a, _ITp __i,
  849. memory_order __m) noexcept
  850. { return __a->exchange(__i, __m); }
  851. template<typename _ITp>
  852. inline _ITp
  853. atomic_exchange_explicit(volatile atomic<_ITp>* __a, _ITp __i,
  854. memory_order __m) noexcept
  855. { return __a->exchange(__i, __m); }
  856. template<typename _ITp>
  857. inline bool
  858. atomic_compare_exchange_weak_explicit(atomic<_ITp>* __a,
  859. _ITp* __i1, _ITp __i2,
  860. memory_order __m1,
  861. memory_order __m2) noexcept
  862. { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
  863. template<typename _ITp>
  864. inline bool
  865. atomic_compare_exchange_weak_explicit(volatile atomic<_ITp>* __a,
  866. _ITp* __i1, _ITp __i2,
  867. memory_order __m1,
  868. memory_order __m2) noexcept
  869. { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
  870. template<typename _ITp>
  871. inline bool
  872. atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a,
  873. _ITp* __i1, _ITp __i2,
  874. memory_order __m1,
  875. memory_order __m2) noexcept
  876. { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
  877. template<typename _ITp>
  878. inline bool
  879. atomic_compare_exchange_strong_explicit(volatile atomic<_ITp>* __a,
  880. _ITp* __i1, _ITp __i2,
  881. memory_order __m1,
  882. memory_order __m2) noexcept
  883. { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
  884. template<typename _ITp>
  885. inline void
  886. atomic_store(atomic<_ITp>* __a, _ITp __i) noexcept
  887. { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
  888. template<typename _ITp>
  889. inline void
  890. atomic_store(volatile atomic<_ITp>* __a, _ITp __i) noexcept
  891. { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
  892. template<typename _ITp>
  893. inline _ITp
  894. atomic_load(const atomic<_ITp>* __a) noexcept
  895. { return atomic_load_explicit(__a, memory_order_seq_cst); }
  896. template<typename _ITp>
  897. inline _ITp
  898. atomic_load(const volatile atomic<_ITp>* __a) noexcept
  899. { return atomic_load_explicit(__a, memory_order_seq_cst); }
  900. template<typename _ITp>
  901. inline _ITp
  902. atomic_exchange(atomic<_ITp>* __a, _ITp __i) noexcept
  903. { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
  904. template<typename _ITp>
  905. inline _ITp
  906. atomic_exchange(volatile atomic<_ITp>* __a, _ITp __i) noexcept
  907. { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
  908. template<typename _ITp>
  909. inline bool
  910. atomic_compare_exchange_weak(atomic<_ITp>* __a,
  911. _ITp* __i1, _ITp __i2) noexcept
  912. {
  913. return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
  914. memory_order_seq_cst,
  915. memory_order_seq_cst);
  916. }
  917. template<typename _ITp>
  918. inline bool
  919. atomic_compare_exchange_weak(volatile atomic<_ITp>* __a,
  920. _ITp* __i1, _ITp __i2) noexcept
  921. {
  922. return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
  923. memory_order_seq_cst,
  924. memory_order_seq_cst);
  925. }
  926. template<typename _ITp>
  927. inline bool
  928. atomic_compare_exchange_strong(atomic<_ITp>* __a,
  929. _ITp* __i1, _ITp __i2) noexcept
  930. {
  931. return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
  932. memory_order_seq_cst,
  933. memory_order_seq_cst);
  934. }
  935. template<typename _ITp>
  936. inline bool
  937. atomic_compare_exchange_strong(volatile atomic<_ITp>* __a,
  938. _ITp* __i1, _ITp __i2) noexcept
  939. {
  940. return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
  941. memory_order_seq_cst,
  942. memory_order_seq_cst);
  943. }
  944. // Function templates for atomic_integral operations only, using
  945. // __atomic_base. Template argument should be constricted to
  946. // intergral types as specified in the standard, excluding address
  947. // types.
  948. template<typename _ITp>
  949. inline _ITp
  950. atomic_fetch_add_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  951. memory_order __m) noexcept
  952. { return __a->fetch_add(__i, __m); }
  953. template<typename _ITp>
  954. inline _ITp
  955. atomic_fetch_add_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  956. memory_order __m) noexcept
  957. { return __a->fetch_add(__i, __m); }
  958. template<typename _ITp>
  959. inline _ITp
  960. atomic_fetch_sub_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  961. memory_order __m) noexcept
  962. { return __a->fetch_sub(__i, __m); }
  963. template<typename _ITp>
  964. inline _ITp
  965. atomic_fetch_sub_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  966. memory_order __m) noexcept
  967. { return __a->fetch_sub(__i, __m); }
  968. template<typename _ITp>
  969. inline _ITp
  970. atomic_fetch_and_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  971. memory_order __m) noexcept
  972. { return __a->fetch_and(__i, __m); }
  973. template<typename _ITp>
  974. inline _ITp
  975. atomic_fetch_and_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  976. memory_order __m) noexcept
  977. { return __a->fetch_and(__i, __m); }
  978. template<typename _ITp>
  979. inline _ITp
  980. atomic_fetch_or_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  981. memory_order __m) noexcept
  982. { return __a->fetch_or(__i, __m); }
  983. template<typename _ITp>
  984. inline _ITp
  985. atomic_fetch_or_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  986. memory_order __m) noexcept
  987. { return __a->fetch_or(__i, __m); }
  988. template<typename _ITp>
  989. inline _ITp
  990. atomic_fetch_xor_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  991. memory_order __m) noexcept
  992. { return __a->fetch_xor(__i, __m); }
  993. template<typename _ITp>
  994. inline _ITp
  995. atomic_fetch_xor_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  996. memory_order __m) noexcept
  997. { return __a->fetch_xor(__i, __m); }
  998. template<typename _ITp>
  999. inline _ITp
  1000. atomic_fetch_add(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1001. { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
  1002. template<typename _ITp>
  1003. inline _ITp
  1004. atomic_fetch_add(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1005. { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
  1006. template<typename _ITp>
  1007. inline _ITp
  1008. atomic_fetch_sub(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1009. { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
  1010. template<typename _ITp>
  1011. inline _ITp
  1012. atomic_fetch_sub(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1013. { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
  1014. template<typename _ITp>
  1015. inline _ITp
  1016. atomic_fetch_and(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1017. { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
  1018. template<typename _ITp>
  1019. inline _ITp
  1020. atomic_fetch_and(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1021. { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
  1022. template<typename _ITp>
  1023. inline _ITp
  1024. atomic_fetch_or(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1025. { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
  1026. template<typename _ITp>
  1027. inline _ITp
  1028. atomic_fetch_or(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1029. { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
  1030. template<typename _ITp>
  1031. inline _ITp
  1032. atomic_fetch_xor(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1033. { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
  1034. template<typename _ITp>
  1035. inline _ITp
  1036. atomic_fetch_xor(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1037. { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
  1038. // Partial specializations for pointers.
  1039. template<typename _ITp>
  1040. inline _ITp*
  1041. atomic_fetch_add_explicit(atomic<_ITp*>* __a, ptrdiff_t __d,
  1042. memory_order __m) noexcept
  1043. { return __a->fetch_add(__d, __m); }
  1044. template<typename _ITp>
  1045. inline _ITp*
  1046. atomic_fetch_add_explicit(volatile atomic<_ITp*>* __a, ptrdiff_t __d,
  1047. memory_order __m) noexcept
  1048. { return __a->fetch_add(__d, __m); }
  1049. template<typename _ITp>
  1050. inline _ITp*
  1051. atomic_fetch_add(volatile atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1052. { return __a->fetch_add(__d); }
  1053. template<typename _ITp>
  1054. inline _ITp*
  1055. atomic_fetch_add(atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1056. { return __a->fetch_add(__d); }
  1057. template<typename _ITp>
  1058. inline _ITp*
  1059. atomic_fetch_sub_explicit(volatile atomic<_ITp*>* __a,
  1060. ptrdiff_t __d, memory_order __m) noexcept
  1061. { return __a->fetch_sub(__d, __m); }
  1062. template<typename _ITp>
  1063. inline _ITp*
  1064. atomic_fetch_sub_explicit(atomic<_ITp*>* __a, ptrdiff_t __d,
  1065. memory_order __m) noexcept
  1066. { return __a->fetch_sub(__d, __m); }
  1067. template<typename _ITp>
  1068. inline _ITp*
  1069. atomic_fetch_sub(volatile atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1070. { return __a->fetch_sub(__d); }
  1071. template<typename _ITp>
  1072. inline _ITp*
  1073. atomic_fetch_sub(atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1074. { return __a->fetch_sub(__d); }
  1075. // @} group atomics
  1076. _GLIBCXX_END_NAMESPACE_VERSION
  1077. } // namespace
  1078. #endif // C++11
  1079. #endif // _GLIBCXX_ATOMIC