atomic 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. // -*- C++ -*- header.
  2. // Copyright (C) 2008-2017 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. // _GLIBCXX_RESOLVE_LIB_DEFECTS
  717. // 2441. Exact-width atomic typedefs should be provided
  718. /// atomic_int8_t
  719. typedef atomic<int8_t> atomic_int8_t;
  720. /// atomic_uint8_t
  721. typedef atomic<uint8_t> atomic_uint8_t;
  722. /// atomic_int16_t
  723. typedef atomic<int16_t> atomic_int16_t;
  724. /// atomic_uint16_t
  725. typedef atomic<uint16_t> atomic_uint16_t;
  726. /// atomic_int32_t
  727. typedef atomic<int32_t> atomic_int32_t;
  728. /// atomic_uint32_t
  729. typedef atomic<uint32_t> atomic_uint32_t;
  730. /// atomic_int64_t
  731. typedef atomic<int64_t> atomic_int64_t;
  732. /// atomic_uint64_t
  733. typedef atomic<uint64_t> atomic_uint64_t;
  734. /// atomic_int_least8_t
  735. typedef atomic<int_least8_t> atomic_int_least8_t;
  736. /// atomic_uint_least8_t
  737. typedef atomic<uint_least8_t> atomic_uint_least8_t;
  738. /// atomic_int_least16_t
  739. typedef atomic<int_least16_t> atomic_int_least16_t;
  740. /// atomic_uint_least16_t
  741. typedef atomic<uint_least16_t> atomic_uint_least16_t;
  742. /// atomic_int_least32_t
  743. typedef atomic<int_least32_t> atomic_int_least32_t;
  744. /// atomic_uint_least32_t
  745. typedef atomic<uint_least32_t> atomic_uint_least32_t;
  746. /// atomic_int_least64_t
  747. typedef atomic<int_least64_t> atomic_int_least64_t;
  748. /// atomic_uint_least64_t
  749. typedef atomic<uint_least64_t> atomic_uint_least64_t;
  750. /// atomic_int_fast8_t
  751. typedef atomic<int_fast8_t> atomic_int_fast8_t;
  752. /// atomic_uint_fast8_t
  753. typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
  754. /// atomic_int_fast16_t
  755. typedef atomic<int_fast16_t> atomic_int_fast16_t;
  756. /// atomic_uint_fast16_t
  757. typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
  758. /// atomic_int_fast32_t
  759. typedef atomic<int_fast32_t> atomic_int_fast32_t;
  760. /// atomic_uint_fast32_t
  761. typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
  762. /// atomic_int_fast64_t
  763. typedef atomic<int_fast64_t> atomic_int_fast64_t;
  764. /// atomic_uint_fast64_t
  765. typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
  766. /// atomic_intptr_t
  767. typedef atomic<intptr_t> atomic_intptr_t;
  768. /// atomic_uintptr_t
  769. typedef atomic<uintptr_t> atomic_uintptr_t;
  770. /// atomic_size_t
  771. typedef atomic<size_t> atomic_size_t;
  772. /// atomic_intmax_t
  773. typedef atomic<intmax_t> atomic_intmax_t;
  774. /// atomic_uintmax_t
  775. typedef atomic<uintmax_t> atomic_uintmax_t;
  776. /// atomic_ptrdiff_t
  777. typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
  778. // Function definitions, atomic_flag operations.
  779. inline bool
  780. atomic_flag_test_and_set_explicit(atomic_flag* __a,
  781. memory_order __m) noexcept
  782. { return __a->test_and_set(__m); }
  783. inline bool
  784. atomic_flag_test_and_set_explicit(volatile atomic_flag* __a,
  785. memory_order __m) noexcept
  786. { return __a->test_and_set(__m); }
  787. inline void
  788. atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept
  789. { __a->clear(__m); }
  790. inline void
  791. atomic_flag_clear_explicit(volatile atomic_flag* __a,
  792. memory_order __m) noexcept
  793. { __a->clear(__m); }
  794. inline bool
  795. atomic_flag_test_and_set(atomic_flag* __a) noexcept
  796. { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
  797. inline bool
  798. atomic_flag_test_and_set(volatile atomic_flag* __a) noexcept
  799. { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
  800. inline void
  801. atomic_flag_clear(atomic_flag* __a) noexcept
  802. { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
  803. inline void
  804. atomic_flag_clear(volatile atomic_flag* __a) noexcept
  805. { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
  806. // Function templates generally applicable to atomic types.
  807. template<typename _ITp>
  808. inline bool
  809. atomic_is_lock_free(const atomic<_ITp>* __a) noexcept
  810. { return __a->is_lock_free(); }
  811. template<typename _ITp>
  812. inline bool
  813. atomic_is_lock_free(const volatile atomic<_ITp>* __a) noexcept
  814. { return __a->is_lock_free(); }
  815. template<typename _ITp>
  816. inline void
  817. atomic_init(atomic<_ITp>* __a, _ITp __i) noexcept
  818. { __a->store(__i, memory_order_relaxed); }
  819. template<typename _ITp>
  820. inline void
  821. atomic_init(volatile atomic<_ITp>* __a, _ITp __i) noexcept
  822. { __a->store(__i, memory_order_relaxed); }
  823. template<typename _ITp>
  824. inline void
  825. atomic_store_explicit(atomic<_ITp>* __a, _ITp __i,
  826. memory_order __m) noexcept
  827. { __a->store(__i, __m); }
  828. template<typename _ITp>
  829. inline void
  830. atomic_store_explicit(volatile atomic<_ITp>* __a, _ITp __i,
  831. memory_order __m) noexcept
  832. { __a->store(__i, __m); }
  833. template<typename _ITp>
  834. inline _ITp
  835. atomic_load_explicit(const atomic<_ITp>* __a, memory_order __m) noexcept
  836. { return __a->load(__m); }
  837. template<typename _ITp>
  838. inline _ITp
  839. atomic_load_explicit(const volatile atomic<_ITp>* __a,
  840. memory_order __m) noexcept
  841. { return __a->load(__m); }
  842. template<typename _ITp>
  843. inline _ITp
  844. atomic_exchange_explicit(atomic<_ITp>* __a, _ITp __i,
  845. memory_order __m) noexcept
  846. { return __a->exchange(__i, __m); }
  847. template<typename _ITp>
  848. inline _ITp
  849. atomic_exchange_explicit(volatile atomic<_ITp>* __a, _ITp __i,
  850. memory_order __m) noexcept
  851. { return __a->exchange(__i, __m); }
  852. template<typename _ITp>
  853. inline bool
  854. atomic_compare_exchange_weak_explicit(atomic<_ITp>* __a,
  855. _ITp* __i1, _ITp __i2,
  856. memory_order __m1,
  857. memory_order __m2) noexcept
  858. { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
  859. template<typename _ITp>
  860. inline bool
  861. atomic_compare_exchange_weak_explicit(volatile atomic<_ITp>* __a,
  862. _ITp* __i1, _ITp __i2,
  863. memory_order __m1,
  864. memory_order __m2) noexcept
  865. { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); }
  866. template<typename _ITp>
  867. inline bool
  868. atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a,
  869. _ITp* __i1, _ITp __i2,
  870. memory_order __m1,
  871. memory_order __m2) noexcept
  872. { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
  873. template<typename _ITp>
  874. inline bool
  875. atomic_compare_exchange_strong_explicit(volatile atomic<_ITp>* __a,
  876. _ITp* __i1, _ITp __i2,
  877. memory_order __m1,
  878. memory_order __m2) noexcept
  879. { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); }
  880. template<typename _ITp>
  881. inline void
  882. atomic_store(atomic<_ITp>* __a, _ITp __i) noexcept
  883. { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
  884. template<typename _ITp>
  885. inline void
  886. atomic_store(volatile atomic<_ITp>* __a, _ITp __i) noexcept
  887. { atomic_store_explicit(__a, __i, memory_order_seq_cst); }
  888. template<typename _ITp>
  889. inline _ITp
  890. atomic_load(const atomic<_ITp>* __a) noexcept
  891. { return atomic_load_explicit(__a, memory_order_seq_cst); }
  892. template<typename _ITp>
  893. inline _ITp
  894. atomic_load(const volatile atomic<_ITp>* __a) noexcept
  895. { return atomic_load_explicit(__a, memory_order_seq_cst); }
  896. template<typename _ITp>
  897. inline _ITp
  898. atomic_exchange(atomic<_ITp>* __a, _ITp __i) noexcept
  899. { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
  900. template<typename _ITp>
  901. inline _ITp
  902. atomic_exchange(volatile atomic<_ITp>* __a, _ITp __i) noexcept
  903. { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); }
  904. template<typename _ITp>
  905. inline bool
  906. atomic_compare_exchange_weak(atomic<_ITp>* __a,
  907. _ITp* __i1, _ITp __i2) noexcept
  908. {
  909. return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
  910. memory_order_seq_cst,
  911. memory_order_seq_cst);
  912. }
  913. template<typename _ITp>
  914. inline bool
  915. atomic_compare_exchange_weak(volatile atomic<_ITp>* __a,
  916. _ITp* __i1, _ITp __i2) noexcept
  917. {
  918. return atomic_compare_exchange_weak_explicit(__a, __i1, __i2,
  919. memory_order_seq_cst,
  920. memory_order_seq_cst);
  921. }
  922. template<typename _ITp>
  923. inline bool
  924. atomic_compare_exchange_strong(atomic<_ITp>* __a,
  925. _ITp* __i1, _ITp __i2) noexcept
  926. {
  927. return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
  928. memory_order_seq_cst,
  929. memory_order_seq_cst);
  930. }
  931. template<typename _ITp>
  932. inline bool
  933. atomic_compare_exchange_strong(volatile atomic<_ITp>* __a,
  934. _ITp* __i1, _ITp __i2) noexcept
  935. {
  936. return atomic_compare_exchange_strong_explicit(__a, __i1, __i2,
  937. memory_order_seq_cst,
  938. memory_order_seq_cst);
  939. }
  940. // Function templates for atomic_integral operations only, using
  941. // __atomic_base. Template argument should be constricted to
  942. // intergral types as specified in the standard, excluding address
  943. // types.
  944. template<typename _ITp>
  945. inline _ITp
  946. atomic_fetch_add_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  947. memory_order __m) noexcept
  948. { return __a->fetch_add(__i, __m); }
  949. template<typename _ITp>
  950. inline _ITp
  951. atomic_fetch_add_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  952. memory_order __m) noexcept
  953. { return __a->fetch_add(__i, __m); }
  954. template<typename _ITp>
  955. inline _ITp
  956. atomic_fetch_sub_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  957. memory_order __m) noexcept
  958. { return __a->fetch_sub(__i, __m); }
  959. template<typename _ITp>
  960. inline _ITp
  961. atomic_fetch_sub_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  962. memory_order __m) noexcept
  963. { return __a->fetch_sub(__i, __m); }
  964. template<typename _ITp>
  965. inline _ITp
  966. atomic_fetch_and_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  967. memory_order __m) noexcept
  968. { return __a->fetch_and(__i, __m); }
  969. template<typename _ITp>
  970. inline _ITp
  971. atomic_fetch_and_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  972. memory_order __m) noexcept
  973. { return __a->fetch_and(__i, __m); }
  974. template<typename _ITp>
  975. inline _ITp
  976. atomic_fetch_or_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  977. memory_order __m) noexcept
  978. { return __a->fetch_or(__i, __m); }
  979. template<typename _ITp>
  980. inline _ITp
  981. atomic_fetch_or_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  982. memory_order __m) noexcept
  983. { return __a->fetch_or(__i, __m); }
  984. template<typename _ITp>
  985. inline _ITp
  986. atomic_fetch_xor_explicit(__atomic_base<_ITp>* __a, _ITp __i,
  987. memory_order __m) noexcept
  988. { return __a->fetch_xor(__i, __m); }
  989. template<typename _ITp>
  990. inline _ITp
  991. atomic_fetch_xor_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i,
  992. memory_order __m) noexcept
  993. { return __a->fetch_xor(__i, __m); }
  994. template<typename _ITp>
  995. inline _ITp
  996. atomic_fetch_add(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  997. { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); }
  998. template<typename _ITp>
  999. inline _ITp
  1000. atomic_fetch_add(volatile __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_sub(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1005. { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); }
  1006. template<typename _ITp>
  1007. inline _ITp
  1008. atomic_fetch_sub(volatile __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_and(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1013. { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); }
  1014. template<typename _ITp>
  1015. inline _ITp
  1016. atomic_fetch_and(volatile __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_or(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1021. { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); }
  1022. template<typename _ITp>
  1023. inline _ITp
  1024. atomic_fetch_or(volatile __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_xor(__atomic_base<_ITp>* __a, _ITp __i) noexcept
  1029. { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
  1030. template<typename _ITp>
  1031. inline _ITp
  1032. atomic_fetch_xor(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept
  1033. { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); }
  1034. // Partial specializations for pointers.
  1035. template<typename _ITp>
  1036. inline _ITp*
  1037. atomic_fetch_add_explicit(atomic<_ITp*>* __a, ptrdiff_t __d,
  1038. memory_order __m) noexcept
  1039. { return __a->fetch_add(__d, __m); }
  1040. template<typename _ITp>
  1041. inline _ITp*
  1042. atomic_fetch_add_explicit(volatile atomic<_ITp*>* __a, ptrdiff_t __d,
  1043. memory_order __m) noexcept
  1044. { return __a->fetch_add(__d, __m); }
  1045. template<typename _ITp>
  1046. inline _ITp*
  1047. atomic_fetch_add(volatile atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1048. { return __a->fetch_add(__d); }
  1049. template<typename _ITp>
  1050. inline _ITp*
  1051. atomic_fetch_add(atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1052. { return __a->fetch_add(__d); }
  1053. template<typename _ITp>
  1054. inline _ITp*
  1055. atomic_fetch_sub_explicit(volatile atomic<_ITp*>* __a,
  1056. ptrdiff_t __d, memory_order __m) noexcept
  1057. { return __a->fetch_sub(__d, __m); }
  1058. template<typename _ITp>
  1059. inline _ITp*
  1060. atomic_fetch_sub_explicit(atomic<_ITp*>* __a, ptrdiff_t __d,
  1061. memory_order __m) noexcept
  1062. { return __a->fetch_sub(__d, __m); }
  1063. template<typename _ITp>
  1064. inline _ITp*
  1065. atomic_fetch_sub(volatile atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1066. { return __a->fetch_sub(__d); }
  1067. template<typename _ITp>
  1068. inline _ITp*
  1069. atomic_fetch_sub(atomic<_ITp*>* __a, ptrdiff_t __d) noexcept
  1070. { return __a->fetch_sub(__d); }
  1071. // @} group atomics
  1072. _GLIBCXX_END_NAMESPACE_VERSION
  1073. } // namespace
  1074. #endif // C++11
  1075. #endif // _GLIBCXX_ATOMIC