]>
Commit | Line | Data |
---|---|---|
d466a7e2 BK |
1 | // -*- C++ -*- header. |
2 | ||
818ab71a | 3 | // Copyright (C) 2008-2016 Free Software Foundation, Inc. |
d466a7e2 BK |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
d466a7e2 BK |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | // You should have received a copy of the GNU General Public License and | |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
d466a7e2 | 24 | |
f910786b | 25 | /** @file include/atomic |
afd88205 | 26 | * This is a Standard C++ Library header. |
d466a7e2 BK |
27 | */ |
28 | ||
29 | // Based on "C++ Atomic Types and Operations" by Hans Boehm and Lawrence Crowl. | |
30 | // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2427.html | |
31 | ||
afd88205 BK |
32 | #ifndef _GLIBCXX_ATOMIC |
33 | #define _GLIBCXX_ATOMIC 1 | |
d466a7e2 BK |
34 | |
35 | #pragma GCC system_header | |
36 | ||
734f5023 | 37 | #if __cplusplus < 201103L |
ab65a4c7 | 38 | # include <bits/c++0x_warning.h> |
709def90 | 39 | #else |
d466a7e2 | 40 | |
afd88205 | 41 | #include <bits/atomic_base.h> |
9f9eb84e | 42 | #include <bits/move.h> |
d466a7e2 | 43 | |
12ffa228 BK |
44 | namespace std _GLIBCXX_VISIBILITY(default) |
45 | { | |
46 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
d466a7e2 | 47 | |
5b9daa7e BK |
48 | /** |
49 | * @addtogroup atomics | |
50 | * @{ | |
51 | */ | |
52 | ||
d31b8797 JW |
53 | template<typename _Tp> |
54 | struct atomic; | |
55 | ||
56 | /// atomic<bool> | |
94a86be0 | 57 | // NB: No operators or fetch-operations for this type. |
d31b8797 JW |
58 | template<> |
59 | struct atomic<bool> | |
d466a7e2 | 60 | { |
94a86be0 BK |
61 | private: |
62 | __atomic_base<bool> _M_base; | |
63 | ||
64 | public: | |
d31b8797 JW |
65 | atomic() noexcept = default; |
66 | ~atomic() noexcept = default; | |
67 | atomic(const atomic&) = delete; | |
68 | atomic& operator=(const atomic&) = delete; | |
69 | atomic& operator=(const atomic&) volatile = delete; | |
94a86be0 | 70 | |
d31b8797 | 71 | constexpr atomic(bool __i) noexcept : _M_base(__i) { } |
94a86be0 BK |
72 | |
73 | bool | |
bdc05efb | 74 | operator=(bool __i) noexcept |
94a86be0 BK |
75 | { return _M_base.operator=(__i); } |
76 | ||
a26f0501 JW |
77 | bool |
78 | operator=(bool __i) volatile noexcept | |
79 | { return _M_base.operator=(__i); } | |
80 | ||
bdc05efb | 81 | operator bool() const noexcept |
94a86be0 BK |
82 | { return _M_base.load(); } |
83 | ||
bdc05efb | 84 | operator bool() const volatile noexcept |
94a86be0 BK |
85 | { return _M_base.load(); } |
86 | ||
87 | bool | |
bdc05efb | 88 | is_lock_free() const noexcept { return _M_base.is_lock_free(); } |
94a86be0 BK |
89 | |
90 | bool | |
bdc05efb | 91 | is_lock_free() const volatile noexcept { return _M_base.is_lock_free(); } |
94a86be0 BK |
92 | |
93 | void | |
bdc05efb | 94 | store(bool __i, memory_order __m = memory_order_seq_cst) noexcept |
94a86be0 BK |
95 | { _M_base.store(__i, __m); } |
96 | ||
97 | void | |
bdc05efb | 98 | store(bool __i, memory_order __m = memory_order_seq_cst) volatile noexcept |
94a86be0 BK |
99 | { _M_base.store(__i, __m); } |
100 | ||
101 | bool | |
bdc05efb | 102 | load(memory_order __m = memory_order_seq_cst) const noexcept |
94a86be0 BK |
103 | { return _M_base.load(__m); } |
104 | ||
105 | bool | |
bdc05efb | 106 | load(memory_order __m = memory_order_seq_cst) const volatile noexcept |
94a86be0 BK |
107 | { return _M_base.load(__m); } |
108 | ||
109 | bool | |
bdc05efb | 110 | exchange(bool __i, memory_order __m = memory_order_seq_cst) noexcept |
94a86be0 BK |
111 | { return _M_base.exchange(__i, __m); } |
112 | ||
113 | bool | |
bdc05efb PC |
114 | exchange(bool __i, |
115 | memory_order __m = memory_order_seq_cst) volatile noexcept | |
94a86be0 BK |
116 | { return _M_base.exchange(__i, __m); } |
117 | ||
118 | bool | |
119 | compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1, | |
bdc05efb | 120 | memory_order __m2) noexcept |
94a86be0 BK |
121 | { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); } |
122 | ||
123 | bool | |
124 | compare_exchange_weak(bool& __i1, bool __i2, memory_order __m1, | |
bdc05efb | 125 | memory_order __m2) volatile noexcept |
94a86be0 BK |
126 | { return _M_base.compare_exchange_weak(__i1, __i2, __m1, __m2); } |
127 | ||
128 | bool | |
129 | compare_exchange_weak(bool& __i1, bool __i2, | |
bdc05efb | 130 | memory_order __m = memory_order_seq_cst) noexcept |
94a86be0 BK |
131 | { return _M_base.compare_exchange_weak(__i1, __i2, __m); } |
132 | ||
133 | bool | |
134 | compare_exchange_weak(bool& __i1, bool __i2, | |
bdc05efb | 135 | memory_order __m = memory_order_seq_cst) volatile noexcept |
94a86be0 BK |
136 | { return _M_base.compare_exchange_weak(__i1, __i2, __m); } |
137 | ||
138 | bool | |
139 | compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1, | |
bdc05efb | 140 | memory_order __m2) noexcept |
94a86be0 BK |
141 | { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); } |
142 | ||
143 | bool | |
144 | compare_exchange_strong(bool& __i1, bool __i2, memory_order __m1, | |
bdc05efb | 145 | memory_order __m2) volatile noexcept |
94a86be0 BK |
146 | { return _M_base.compare_exchange_strong(__i1, __i2, __m1, __m2); } |
147 | ||
148 | bool | |
149 | compare_exchange_strong(bool& __i1, bool __i2, | |
bdc05efb | 150 | memory_order __m = memory_order_seq_cst) noexcept |
94a86be0 BK |
151 | { return _M_base.compare_exchange_strong(__i1, __i2, __m); } |
152 | ||
153 | bool | |
154 | compare_exchange_strong(bool& __i1, bool __i2, | |
bdc05efb | 155 | memory_order __m = memory_order_seq_cst) volatile noexcept |
94a86be0 BK |
156 | { return _M_base.compare_exchange_strong(__i1, __i2, __m); } |
157 | }; | |
d466a7e2 | 158 | |
d466a7e2 | 159 | |
d632488a BK |
160 | /** |
161 | * @brief Generic atomic type, primary class template. | |
162 | * | |
163 | * @tparam _Tp Type to be made atomic, must be trivally copyable. | |
164 | */ | |
50ce8d3d BK |
165 | template<typename _Tp> |
166 | struct atomic | |
167 | { | |
168 | private: | |
4cbaaa45 | 169 | // Align 1/2/4/8/16-byte types to at least their size. |
4280698d | 170 | static constexpr int _S_min_alignment |
4cbaaa45 JW |
171 | = (sizeof(_Tp) & (sizeof(_Tp) - 1)) || sizeof(_Tp) > 16 |
172 | ? 0 : sizeof(_Tp); | |
4280698d JW |
173 | |
174 | static constexpr int _S_alignment | |
175 | = _S_min_alignment > alignof(_Tp) ? _S_min_alignment : alignof(_Tp); | |
176 | ||
177 | alignas(_S_alignment) _Tp _M_i; | |
d466a7e2 | 178 | |
bc2da0fc JW |
179 | static_assert(__is_trivially_copyable(_Tp), |
180 | "std::atomic requires a trivially copyable type"); | |
9ffc6d0b JW |
181 | |
182 | static_assert(sizeof(_Tp) > 0, | |
183 | "Incomplete or zero-sized types are not supported"); | |
184 | ||
50ce8d3d | 185 | public: |
bdc05efb PC |
186 | atomic() noexcept = default; |
187 | ~atomic() noexcept = default; | |
50ce8d3d | 188 | atomic(const atomic&) = delete; |
94a86be0 | 189 | atomic& operator=(const atomic&) = delete; |
afd88205 | 190 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 191 | |
bdc05efb | 192 | constexpr atomic(_Tp __i) noexcept : _M_i(__i) { } |
d466a7e2 | 193 | |
86951993 AM |
194 | operator _Tp() const noexcept |
195 | { return load(); } | |
d466a7e2 | 196 | |
86951993 AM |
197 | operator _Tp() const volatile noexcept |
198 | { return load(); } | |
94a86be0 | 199 | |
afd88205 | 200 | _Tp |
33ac58d5 | 201 | operator=(_Tp __i) noexcept |
86951993 | 202 | { store(__i); return __i; } |
d466a7e2 | 203 | |
94a86be0 | 204 | _Tp |
33ac58d5 | 205 | operator=(_Tp __i) volatile noexcept |
86951993 | 206 | { store(__i); return __i; } |
94a86be0 BK |
207 | |
208 | bool | |
86951993 | 209 | is_lock_free() const noexcept |
8be56851 RH |
210 | { |
211 | // Produce a fake, minimally aligned pointer. | |
310055e7 JW |
212 | return __atomic_is_lock_free(sizeof(_M_i), |
213 | reinterpret_cast<void *>(-__alignof(_M_i))); | |
8be56851 | 214 | } |
94a86be0 | 215 | |
afd88205 | 216 | bool |
86951993 | 217 | is_lock_free() const volatile noexcept |
8be56851 RH |
218 | { |
219 | // Produce a fake, minimally aligned pointer. | |
310055e7 JW |
220 | return __atomic_is_lock_free(sizeof(_M_i), |
221 | reinterpret_cast<void *>(-__alignof(_M_i))); | |
8be56851 | 222 | } |
d466a7e2 | 223 | |
94a86be0 | 224 | void |
227df36e | 225 | store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept |
9f9eb84e | 226 | { __atomic_store(std::__addressof(_M_i), std::__addressof(__i), __m); } |
94a86be0 | 227 | |
afd88205 | 228 | void |
227df36e | 229 | store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile noexcept |
9f9eb84e | 230 | { __atomic_store(std::__addressof(_M_i), std::__addressof(__i), __m); } |
d466a7e2 | 231 | |
94a86be0 | 232 | _Tp |
227df36e | 233 | load(memory_order __m = memory_order_seq_cst) const noexcept |
33ac58d5 | 234 | { |
86951993 | 235 | _Tp tmp; |
9f9eb84e | 236 | __atomic_load(std::__addressof(_M_i), std::__addressof(tmp), __m); |
86951993 AM |
237 | return tmp; |
238 | } | |
94a86be0 | 239 | |
afd88205 | 240 | _Tp |
227df36e | 241 | load(memory_order __m = memory_order_seq_cst) const volatile noexcept |
33ac58d5 | 242 | { |
86951993 | 243 | _Tp tmp; |
9f9eb84e | 244 | __atomic_load(std::__addressof(_M_i), std::__addressof(tmp), __m); |
86951993 AM |
245 | return tmp; |
246 | } | |
d466a7e2 | 247 | |
94a86be0 | 248 | _Tp |
227df36e | 249 | exchange(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept |
33ac58d5 | 250 | { |
86951993 | 251 | _Tp tmp; |
9f9eb84e JW |
252 | __atomic_exchange(std::__addressof(_M_i), std::__addressof(__i), |
253 | std::__addressof(tmp), __m); | |
86951993 AM |
254 | return tmp; |
255 | } | |
94a86be0 | 256 | |
afd88205 | 257 | _Tp |
33ac58d5 | 258 | exchange(_Tp __i, |
227df36e | 259 | memory_order __m = memory_order_seq_cst) volatile noexcept |
33ac58d5 | 260 | { |
86951993 | 261 | _Tp tmp; |
9f9eb84e JW |
262 | __atomic_exchange(std::__addressof(_M_i), std::__addressof(__i), |
263 | std::__addressof(tmp), __m); | |
86951993 AM |
264 | return tmp; |
265 | } | |
d466a7e2 | 266 | |
94a86be0 | 267 | bool |
33ac58d5 | 268 | compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s, |
86951993 AM |
269 | memory_order __f) noexcept |
270 | { | |
9f9eb84e JW |
271 | return __atomic_compare_exchange(std::__addressof(_M_i), |
272 | std::__addressof(__e), | |
273 | std::__addressof(__i), | |
274 | true, __s, __f); | |
86951993 | 275 | } |
94a86be0 | 276 | |
afd88205 | 277 | bool |
33ac58d5 | 278 | compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s, |
86951993 AM |
279 | memory_order __f) volatile noexcept |
280 | { | |
9f9eb84e JW |
281 | return __atomic_compare_exchange(std::__addressof(_M_i), |
282 | std::__addressof(__e), | |
283 | std::__addressof(__i), | |
284 | true, __s, __f); | |
86951993 | 285 | } |
d466a7e2 | 286 | |
afd88205 | 287 | bool |
86951993 AM |
288 | compare_exchange_weak(_Tp& __e, _Tp __i, |
289 | memory_order __m = memory_order_seq_cst) noexcept | |
272827e4 NF |
290 | { return compare_exchange_weak(__e, __i, __m, |
291 | __cmpexch_failure_order(__m)); } | |
d466a7e2 | 292 | |
afd88205 | 293 | bool |
86951993 AM |
294 | compare_exchange_weak(_Tp& __e, _Tp __i, |
295 | memory_order __m = memory_order_seq_cst) volatile noexcept | |
272827e4 NF |
296 | { return compare_exchange_weak(__e, __i, __m, |
297 | __cmpexch_failure_order(__m)); } | |
d466a7e2 | 298 | |
94a86be0 | 299 | bool |
33ac58d5 | 300 | compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s, |
86951993 AM |
301 | memory_order __f) noexcept |
302 | { | |
9f9eb84e JW |
303 | return __atomic_compare_exchange(std::__addressof(_M_i), |
304 | std::__addressof(__e), | |
305 | std::__addressof(__i), | |
306 | false, __s, __f); | |
86951993 | 307 | } |
94a86be0 BK |
308 | |
309 | bool | |
33ac58d5 | 310 | compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s, |
86951993 AM |
311 | memory_order __f) volatile noexcept |
312 | { | |
9f9eb84e JW |
313 | return __atomic_compare_exchange(std::__addressof(_M_i), |
314 | std::__addressof(__e), | |
315 | std::__addressof(__i), | |
316 | false, __s, __f); | |
86951993 | 317 | } |
94a86be0 BK |
318 | |
319 | bool | |
86951993 AM |
320 | compare_exchange_strong(_Tp& __e, _Tp __i, |
321 | memory_order __m = memory_order_seq_cst) noexcept | |
272827e4 NF |
322 | { return compare_exchange_strong(__e, __i, __m, |
323 | __cmpexch_failure_order(__m)); } | |
94a86be0 | 324 | |
afd88205 | 325 | bool |
86951993 AM |
326 | compare_exchange_strong(_Tp& __e, _Tp __i, |
327 | memory_order __m = memory_order_seq_cst) volatile noexcept | |
272827e4 NF |
328 | { return compare_exchange_strong(__e, __i, __m, |
329 | __cmpexch_failure_order(__m)); } | |
50ce8d3d | 330 | }; |
d466a7e2 | 331 | |
d466a7e2 | 332 | |
50ce8d3d | 333 | /// Partial specialization for pointer types. |
afd88205 | 334 | template<typename _Tp> |
036e0d4f | 335 | struct atomic<_Tp*> |
50ce8d3d | 336 | { |
036e0d4f BK |
337 | typedef _Tp* __pointer_type; |
338 | typedef __atomic_base<_Tp*> __base_type; | |
339 | __base_type _M_b; | |
340 | ||
bdc05efb PC |
341 | atomic() noexcept = default; |
342 | ~atomic() noexcept = default; | |
50ce8d3d | 343 | atomic(const atomic&) = delete; |
036e0d4f | 344 | atomic& operator=(const atomic&) = delete; |
afd88205 | 345 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 346 | |
bdc05efb | 347 | constexpr atomic(__pointer_type __p) noexcept : _M_b(__p) { } |
94a86be0 | 348 | |
bdc05efb | 349 | operator __pointer_type() const noexcept |
036e0d4f | 350 | { return __pointer_type(_M_b); } |
d466a7e2 | 351 | |
bdc05efb | 352 | operator __pointer_type() const volatile noexcept |
036e0d4f | 353 | { return __pointer_type(_M_b); } |
d466a7e2 | 354 | |
036e0d4f | 355 | __pointer_type |
bdc05efb | 356 | operator=(__pointer_type __p) noexcept |
036e0d4f | 357 | { return _M_b.operator=(__p); } |
d466a7e2 | 358 | |
036e0d4f | 359 | __pointer_type |
bdc05efb | 360 | operator=(__pointer_type __p) volatile noexcept |
036e0d4f | 361 | { return _M_b.operator=(__p); } |
94a86be0 | 362 | |
036e0d4f | 363 | __pointer_type |
bdc05efb | 364 | operator++(int) noexcept |
036e0d4f | 365 | { return _M_b++; } |
94a86be0 | 366 | |
036e0d4f | 367 | __pointer_type |
bdc05efb | 368 | operator++(int) volatile noexcept |
036e0d4f | 369 | { return _M_b++; } |
d466a7e2 | 370 | |
036e0d4f | 371 | __pointer_type |
bdc05efb | 372 | operator--(int) noexcept |
036e0d4f | 373 | { return _M_b--; } |
d466a7e2 | 374 | |
036e0d4f | 375 | __pointer_type |
bdc05efb | 376 | operator--(int) volatile noexcept |
036e0d4f | 377 | { return _M_b--; } |
d466a7e2 | 378 | |
036e0d4f | 379 | __pointer_type |
bdc05efb | 380 | operator++() noexcept |
036e0d4f | 381 | { return ++_M_b; } |
d466a7e2 | 382 | |
036e0d4f | 383 | __pointer_type |
bdc05efb | 384 | operator++() volatile noexcept |
036e0d4f | 385 | { return ++_M_b; } |
94a86be0 | 386 | |
036e0d4f | 387 | __pointer_type |
bdc05efb | 388 | operator--() noexcept |
036e0d4f | 389 | { return --_M_b; } |
94a86be0 | 390 | |
036e0d4f | 391 | __pointer_type |
bdc05efb | 392 | operator--() volatile noexcept |
036e0d4f BK |
393 | { return --_M_b; } |
394 | ||
395 | __pointer_type | |
bdc05efb | 396 | operator+=(ptrdiff_t __d) noexcept |
036e0d4f BK |
397 | { return _M_b.operator+=(__d); } |
398 | ||
399 | __pointer_type | |
bdc05efb | 400 | operator+=(ptrdiff_t __d) volatile noexcept |
036e0d4f BK |
401 | { return _M_b.operator+=(__d); } |
402 | ||
403 | __pointer_type | |
bdc05efb | 404 | operator-=(ptrdiff_t __d) noexcept |
036e0d4f BK |
405 | { return _M_b.operator-=(__d); } |
406 | ||
407 | __pointer_type | |
bdc05efb | 408 | operator-=(ptrdiff_t __d) volatile noexcept |
036e0d4f | 409 | { return _M_b.operator-=(__d); } |
94a86be0 | 410 | |
afd88205 | 411 | bool |
bdc05efb | 412 | is_lock_free() const noexcept |
036e0d4f | 413 | { return _M_b.is_lock_free(); } |
d466a7e2 | 414 | |
94a86be0 | 415 | bool |
bdc05efb | 416 | is_lock_free() const volatile noexcept |
036e0d4f BK |
417 | { return _M_b.is_lock_free(); } |
418 | ||
419 | void | |
bdc05efb PC |
420 | store(__pointer_type __p, |
421 | memory_order __m = memory_order_seq_cst) noexcept | |
036e0d4f BK |
422 | { return _M_b.store(__p, __m); } |
423 | ||
424 | void | |
425 | store(__pointer_type __p, | |
bdc05efb | 426 | memory_order __m = memory_order_seq_cst) volatile noexcept |
036e0d4f | 427 | { return _M_b.store(__p, __m); } |
94a86be0 | 428 | |
036e0d4f | 429 | __pointer_type |
bdc05efb | 430 | load(memory_order __m = memory_order_seq_cst) const noexcept |
036e0d4f | 431 | { return _M_b.load(__m); } |
d466a7e2 | 432 | |
036e0d4f | 433 | __pointer_type |
bdc05efb | 434 | load(memory_order __m = memory_order_seq_cst) const volatile noexcept |
036e0d4f | 435 | { return _M_b.load(__m); } |
94a86be0 | 436 | |
036e0d4f | 437 | __pointer_type |
bdc05efb PC |
438 | exchange(__pointer_type __p, |
439 | memory_order __m = memory_order_seq_cst) noexcept | |
036e0d4f | 440 | { return _M_b.exchange(__p, __m); } |
d466a7e2 | 441 | |
036e0d4f BK |
442 | __pointer_type |
443 | exchange(__pointer_type __p, | |
bdc05efb | 444 | memory_order __m = memory_order_seq_cst) volatile noexcept |
036e0d4f | 445 | { return _M_b.exchange(__p, __m); } |
94a86be0 | 446 | |
036e0d4f BK |
447 | bool |
448 | compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2, | |
bdc05efb | 449 | memory_order __m1, memory_order __m2) noexcept |
036e0d4f | 450 | { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); } |
d466a7e2 | 451 | |
036e0d4f BK |
452 | bool |
453 | compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2, | |
bdc05efb PC |
454 | memory_order __m1, |
455 | memory_order __m2) volatile noexcept | |
036e0d4f | 456 | { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); } |
94a86be0 | 457 | |
036e0d4f BK |
458 | bool |
459 | compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2, | |
bdc05efb | 460 | memory_order __m = memory_order_seq_cst) noexcept |
afd88205 | 461 | { |
036e0d4f | 462 | return compare_exchange_weak(__p1, __p2, __m, |
3d0c32fe | 463 | __cmpexch_failure_order(__m)); |
50ce8d3d | 464 | } |
d466a7e2 | 465 | |
036e0d4f BK |
466 | bool |
467 | compare_exchange_weak(__pointer_type& __p1, __pointer_type __p2, | |
bdc05efb | 468 | memory_order __m = memory_order_seq_cst) volatile noexcept |
94a86be0 | 469 | { |
036e0d4f | 470 | return compare_exchange_weak(__p1, __p2, __m, |
3d0c32fe | 471 | __cmpexch_failure_order(__m)); |
94a86be0 BK |
472 | } |
473 | ||
036e0d4f BK |
474 | bool |
475 | compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2, | |
bdc05efb | 476 | memory_order __m1, memory_order __m2) noexcept |
036e0d4f | 477 | { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); } |
d466a7e2 | 478 | |
036e0d4f BK |
479 | bool |
480 | compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2, | |
bdc05efb PC |
481 | memory_order __m1, |
482 | memory_order __m2) volatile noexcept | |
036e0d4f | 483 | { return _M_b.compare_exchange_strong(__p1, __p2, __m1, __m2); } |
94a86be0 | 484 | |
036e0d4f BK |
485 | bool |
486 | compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2, | |
bdc05efb | 487 | memory_order __m = memory_order_seq_cst) noexcept |
036e0d4f BK |
488 | { |
489 | return _M_b.compare_exchange_strong(__p1, __p2, __m, | |
3d0c32fe | 490 | __cmpexch_failure_order(__m)); |
036e0d4f | 491 | } |
d466a7e2 | 492 | |
036e0d4f BK |
493 | bool |
494 | compare_exchange_strong(__pointer_type& __p1, __pointer_type __p2, | |
bdc05efb | 495 | memory_order __m = memory_order_seq_cst) volatile noexcept |
036e0d4f BK |
496 | { |
497 | return _M_b.compare_exchange_strong(__p1, __p2, __m, | |
3d0c32fe | 498 | __cmpexch_failure_order(__m)); |
036e0d4f | 499 | } |
94a86be0 | 500 | |
036e0d4f | 501 | __pointer_type |
bdc05efb PC |
502 | fetch_add(ptrdiff_t __d, |
503 | memory_order __m = memory_order_seq_cst) noexcept | |
036e0d4f | 504 | { return _M_b.fetch_add(__d, __m); } |
d466a7e2 | 505 | |
036e0d4f BK |
506 | __pointer_type |
507 | fetch_add(ptrdiff_t __d, | |
bdc05efb | 508 | memory_order __m = memory_order_seq_cst) volatile noexcept |
036e0d4f | 509 | { return _M_b.fetch_add(__d, __m); } |
94a86be0 | 510 | |
036e0d4f | 511 | __pointer_type |
bdc05efb PC |
512 | fetch_sub(ptrdiff_t __d, |
513 | memory_order __m = memory_order_seq_cst) noexcept | |
036e0d4f | 514 | { return _M_b.fetch_sub(__d, __m); } |
d466a7e2 | 515 | |
036e0d4f BK |
516 | __pointer_type |
517 | fetch_sub(ptrdiff_t __d, | |
bdc05efb | 518 | memory_order __m = memory_order_seq_cst) volatile noexcept |
036e0d4f | 519 | { return _M_b.fetch_sub(__d, __m); } |
50ce8d3d | 520 | }; |
d466a7e2 | 521 | |
036e0d4f | 522 | |
50ce8d3d | 523 | /// Explicit specialization for char. |
afd88205 | 524 | template<> |
d31b8797 | 525 | struct atomic<char> : __atomic_base<char> |
50ce8d3d BK |
526 | { |
527 | typedef char __integral_type; | |
d31b8797 | 528 | typedef __atomic_base<char> __base_type; |
d466a7e2 | 529 | |
bdc05efb PC |
530 | atomic() noexcept = default; |
531 | ~atomic() noexcept = default; | |
50ce8d3d | 532 | atomic(const atomic&) = delete; |
94a86be0 | 533 | atomic& operator=(const atomic&) = delete; |
afd88205 | 534 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 535 | |
bdc05efb | 536 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 537 | |
50ce8d3d BK |
538 | using __base_type::operator __integral_type; |
539 | using __base_type::operator=; | |
540 | }; | |
d466a7e2 | 541 | |
50ce8d3d | 542 | /// Explicit specialization for signed char. |
afd88205 | 543 | template<> |
d31b8797 | 544 | struct atomic<signed char> : __atomic_base<signed char> |
afd88205 | 545 | { |
50ce8d3d | 546 | typedef signed char __integral_type; |
d31b8797 | 547 | typedef __atomic_base<signed char> __base_type; |
d466a7e2 | 548 | |
bdc05efb PC |
549 | atomic() noexcept= default; |
550 | ~atomic() noexcept = default; | |
50ce8d3d | 551 | atomic(const atomic&) = delete; |
94a86be0 | 552 | atomic& operator=(const atomic&) = delete; |
afd88205 | 553 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 554 | |
bdc05efb | 555 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 556 | |
50ce8d3d BK |
557 | using __base_type::operator __integral_type; |
558 | using __base_type::operator=; | |
559 | }; | |
d466a7e2 | 560 | |
50ce8d3d | 561 | /// Explicit specialization for unsigned char. |
afd88205 | 562 | template<> |
d31b8797 | 563 | struct atomic<unsigned char> : __atomic_base<unsigned char> |
50ce8d3d BK |
564 | { |
565 | typedef unsigned char __integral_type; | |
d31b8797 | 566 | typedef __atomic_base<unsigned char> __base_type; |
d466a7e2 | 567 | |
bdc05efb PC |
568 | atomic() noexcept= default; |
569 | ~atomic() noexcept = default; | |
50ce8d3d | 570 | atomic(const atomic&) = delete; |
94a86be0 | 571 | atomic& operator=(const atomic&) = delete; |
afd88205 | 572 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 573 | |
bdc05efb | 574 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 575 | |
50ce8d3d BK |
576 | using __base_type::operator __integral_type; |
577 | using __base_type::operator=; | |
578 | }; | |
d466a7e2 | 579 | |
50ce8d3d | 580 | /// Explicit specialization for short. |
afd88205 | 581 | template<> |
d31b8797 | 582 | struct atomic<short> : __atomic_base<short> |
50ce8d3d BK |
583 | { |
584 | typedef short __integral_type; | |
d31b8797 | 585 | typedef __atomic_base<short> __base_type; |
d466a7e2 | 586 | |
bdc05efb PC |
587 | atomic() noexcept = default; |
588 | ~atomic() noexcept = default; | |
50ce8d3d | 589 | atomic(const atomic&) = delete; |
94a86be0 | 590 | atomic& operator=(const atomic&) = delete; |
afd88205 | 591 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 592 | |
bdc05efb | 593 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 594 | |
50ce8d3d BK |
595 | using __base_type::operator __integral_type; |
596 | using __base_type::operator=; | |
597 | }; | |
d466a7e2 | 598 | |
50ce8d3d | 599 | /// Explicit specialization for unsigned short. |
afd88205 | 600 | template<> |
d31b8797 | 601 | struct atomic<unsigned short> : __atomic_base<unsigned short> |
50ce8d3d BK |
602 | { |
603 | typedef unsigned short __integral_type; | |
d31b8797 | 604 | typedef __atomic_base<unsigned short> __base_type; |
d466a7e2 | 605 | |
bdc05efb PC |
606 | atomic() noexcept = default; |
607 | ~atomic() noexcept = default; | |
50ce8d3d | 608 | atomic(const atomic&) = delete; |
94a86be0 | 609 | atomic& operator=(const atomic&) = delete; |
afd88205 | 610 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 611 | |
bdc05efb | 612 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 613 | |
50ce8d3d BK |
614 | using __base_type::operator __integral_type; |
615 | using __base_type::operator=; | |
616 | }; | |
d466a7e2 | 617 | |
50ce8d3d | 618 | /// Explicit specialization for int. |
afd88205 | 619 | template<> |
d31b8797 | 620 | struct atomic<int> : __atomic_base<int> |
50ce8d3d BK |
621 | { |
622 | typedef int __integral_type; | |
d31b8797 | 623 | typedef __atomic_base<int> __base_type; |
d466a7e2 | 624 | |
bdc05efb PC |
625 | atomic() noexcept = default; |
626 | ~atomic() noexcept = default; | |
50ce8d3d | 627 | atomic(const atomic&) = delete; |
94a86be0 | 628 | atomic& operator=(const atomic&) = delete; |
afd88205 | 629 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 630 | |
bdc05efb | 631 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 632 | |
50ce8d3d BK |
633 | using __base_type::operator __integral_type; |
634 | using __base_type::operator=; | |
635 | }; | |
d466a7e2 | 636 | |
50ce8d3d | 637 | /// Explicit specialization for unsigned int. |
afd88205 | 638 | template<> |
d31b8797 | 639 | struct atomic<unsigned int> : __atomic_base<unsigned int> |
50ce8d3d BK |
640 | { |
641 | typedef unsigned int __integral_type; | |
d31b8797 | 642 | typedef __atomic_base<unsigned int> __base_type; |
d466a7e2 | 643 | |
bdc05efb PC |
644 | atomic() noexcept = default; |
645 | ~atomic() noexcept = default; | |
50ce8d3d | 646 | atomic(const atomic&) = delete; |
94a86be0 | 647 | atomic& operator=(const atomic&) = delete; |
afd88205 | 648 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 649 | |
bdc05efb | 650 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 651 | |
50ce8d3d BK |
652 | using __base_type::operator __integral_type; |
653 | using __base_type::operator=; | |
654 | }; | |
d466a7e2 | 655 | |
50ce8d3d | 656 | /// Explicit specialization for long. |
afd88205 | 657 | template<> |
d31b8797 | 658 | struct atomic<long> : __atomic_base<long> |
50ce8d3d BK |
659 | { |
660 | typedef long __integral_type; | |
d31b8797 | 661 | typedef __atomic_base<long> __base_type; |
d466a7e2 | 662 | |
bdc05efb PC |
663 | atomic() noexcept = default; |
664 | ~atomic() noexcept = default; | |
50ce8d3d | 665 | atomic(const atomic&) = delete; |
94a86be0 | 666 | atomic& operator=(const atomic&) = delete; |
afd88205 | 667 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 668 | |
bdc05efb | 669 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 670 | |
50ce8d3d BK |
671 | using __base_type::operator __integral_type; |
672 | using __base_type::operator=; | |
673 | }; | |
d466a7e2 | 674 | |
50ce8d3d | 675 | /// Explicit specialization for unsigned long. |
afd88205 | 676 | template<> |
d31b8797 | 677 | struct atomic<unsigned long> : __atomic_base<unsigned long> |
50ce8d3d BK |
678 | { |
679 | typedef unsigned long __integral_type; | |
d31b8797 | 680 | typedef __atomic_base<unsigned long> __base_type; |
d466a7e2 | 681 | |
bdc05efb PC |
682 | atomic() noexcept = default; |
683 | ~atomic() noexcept = default; | |
50ce8d3d | 684 | atomic(const atomic&) = delete; |
94a86be0 | 685 | atomic& operator=(const atomic&) = delete; |
afd88205 | 686 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 687 | |
bdc05efb | 688 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 689 | |
50ce8d3d BK |
690 | using __base_type::operator __integral_type; |
691 | using __base_type::operator=; | |
692 | }; | |
d466a7e2 | 693 | |
50ce8d3d | 694 | /// Explicit specialization for long long. |
afd88205 | 695 | template<> |
d31b8797 | 696 | struct atomic<long long> : __atomic_base<long long> |
50ce8d3d BK |
697 | { |
698 | typedef long long __integral_type; | |
d31b8797 | 699 | typedef __atomic_base<long long> __base_type; |
d466a7e2 | 700 | |
bdc05efb PC |
701 | atomic() noexcept = default; |
702 | ~atomic() noexcept = default; | |
50ce8d3d | 703 | atomic(const atomic&) = delete; |
94a86be0 | 704 | atomic& operator=(const atomic&) = delete; |
afd88205 | 705 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 706 | |
bdc05efb | 707 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 708 | |
50ce8d3d BK |
709 | using __base_type::operator __integral_type; |
710 | using __base_type::operator=; | |
711 | }; | |
d466a7e2 | 712 | |
50ce8d3d | 713 | /// Explicit specialization for unsigned long long. |
afd88205 | 714 | template<> |
d31b8797 | 715 | struct atomic<unsigned long long> : __atomic_base<unsigned long long> |
50ce8d3d BK |
716 | { |
717 | typedef unsigned long long __integral_type; | |
d31b8797 | 718 | typedef __atomic_base<unsigned long long> __base_type; |
d466a7e2 | 719 | |
bdc05efb PC |
720 | atomic() noexcept = default; |
721 | ~atomic() noexcept = default; | |
50ce8d3d | 722 | atomic(const atomic&) = delete; |
94a86be0 | 723 | atomic& operator=(const atomic&) = delete; |
afd88205 | 724 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 725 | |
bdc05efb | 726 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 727 | |
50ce8d3d BK |
728 | using __base_type::operator __integral_type; |
729 | using __base_type::operator=; | |
730 | }; | |
d466a7e2 | 731 | |
50ce8d3d | 732 | /// Explicit specialization for wchar_t. |
afd88205 | 733 | template<> |
d31b8797 | 734 | struct atomic<wchar_t> : __atomic_base<wchar_t> |
50ce8d3d BK |
735 | { |
736 | typedef wchar_t __integral_type; | |
d31b8797 | 737 | typedef __atomic_base<wchar_t> __base_type; |
d466a7e2 | 738 | |
bdc05efb PC |
739 | atomic() noexcept = default; |
740 | ~atomic() noexcept = default; | |
50ce8d3d | 741 | atomic(const atomic&) = delete; |
94a86be0 | 742 | atomic& operator=(const atomic&) = delete; |
afd88205 | 743 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 744 | |
bdc05efb | 745 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 746 | |
50ce8d3d BK |
747 | using __base_type::operator __integral_type; |
748 | using __base_type::operator=; | |
749 | }; | |
d466a7e2 | 750 | |
50ce8d3d | 751 | /// Explicit specialization for char16_t. |
afd88205 | 752 | template<> |
d31b8797 | 753 | struct atomic<char16_t> : __atomic_base<char16_t> |
50ce8d3d BK |
754 | { |
755 | typedef char16_t __integral_type; | |
d31b8797 | 756 | typedef __atomic_base<char16_t> __base_type; |
d466a7e2 | 757 | |
bdc05efb PC |
758 | atomic() noexcept = default; |
759 | ~atomic() noexcept = default; | |
50ce8d3d | 760 | atomic(const atomic&) = delete; |
94a86be0 | 761 | atomic& operator=(const atomic&) = delete; |
afd88205 | 762 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 763 | |
bdc05efb | 764 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 765 | |
50ce8d3d BK |
766 | using __base_type::operator __integral_type; |
767 | using __base_type::operator=; | |
768 | }; | |
d466a7e2 | 769 | |
50ce8d3d | 770 | /// Explicit specialization for char32_t. |
afd88205 | 771 | template<> |
d31b8797 | 772 | struct atomic<char32_t> : __atomic_base<char32_t> |
50ce8d3d BK |
773 | { |
774 | typedef char32_t __integral_type; | |
d31b8797 | 775 | typedef __atomic_base<char32_t> __base_type; |
d466a7e2 | 776 | |
bdc05efb PC |
777 | atomic() noexcept = default; |
778 | ~atomic() noexcept = default; | |
50ce8d3d | 779 | atomic(const atomic&) = delete; |
94a86be0 | 780 | atomic& operator=(const atomic&) = delete; |
afd88205 | 781 | atomic& operator=(const atomic&) volatile = delete; |
d466a7e2 | 782 | |
bdc05efb | 783 | constexpr atomic(__integral_type __i) noexcept : __base_type(__i) { } |
d466a7e2 | 784 | |
50ce8d3d BK |
785 | using __base_type::operator __integral_type; |
786 | using __base_type::operator=; | |
787 | }; | |
d466a7e2 | 788 | |
94a86be0 | 789 | |
d31b8797 JW |
790 | /// atomic_bool |
791 | typedef atomic<bool> atomic_bool; | |
792 | ||
793 | /// atomic_char | |
794 | typedef atomic<char> atomic_char; | |
795 | ||
796 | /// atomic_schar | |
797 | typedef atomic<signed char> atomic_schar; | |
798 | ||
799 | /// atomic_uchar | |
800 | typedef atomic<unsigned char> atomic_uchar; | |
801 | ||
802 | /// atomic_short | |
803 | typedef atomic<short> atomic_short; | |
804 | ||
805 | /// atomic_ushort | |
806 | typedef atomic<unsigned short> atomic_ushort; | |
807 | ||
808 | /// atomic_int | |
809 | typedef atomic<int> atomic_int; | |
810 | ||
811 | /// atomic_uint | |
812 | typedef atomic<unsigned int> atomic_uint; | |
813 | ||
814 | /// atomic_long | |
815 | typedef atomic<long> atomic_long; | |
816 | ||
817 | /// atomic_ulong | |
818 | typedef atomic<unsigned long> atomic_ulong; | |
819 | ||
820 | /// atomic_llong | |
821 | typedef atomic<long long> atomic_llong; | |
822 | ||
823 | /// atomic_ullong | |
824 | typedef atomic<unsigned long long> atomic_ullong; | |
825 | ||
826 | /// atomic_wchar_t | |
827 | typedef atomic<wchar_t> atomic_wchar_t; | |
828 | ||
829 | /// atomic_char16_t | |
830 | typedef atomic<char16_t> atomic_char16_t; | |
831 | ||
832 | /// atomic_char32_t | |
833 | typedef atomic<char32_t> atomic_char32_t; | |
834 | ||
835 | ||
e87b7d52 JW |
836 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
837 | // 2441. Exact-width atomic typedefs should be provided | |
838 | ||
839 | /// atomic_int8_t | |
840 | typedef atomic<int8_t> atomic_int8_t; | |
841 | ||
842 | /// atomic_uint8_t | |
843 | typedef atomic<uint8_t> atomic_uint8_t; | |
844 | ||
845 | /// atomic_int16_t | |
846 | typedef atomic<int16_t> atomic_int16_t; | |
847 | ||
848 | /// atomic_uint16_t | |
849 | typedef atomic<uint16_t> atomic_uint16_t; | |
850 | ||
851 | /// atomic_int32_t | |
852 | typedef atomic<int32_t> atomic_int32_t; | |
853 | ||
854 | /// atomic_uint32_t | |
855 | typedef atomic<uint32_t> atomic_uint32_t; | |
856 | ||
857 | /// atomic_int64_t | |
858 | typedef atomic<int64_t> atomic_int64_t; | |
859 | ||
860 | /// atomic_uint64_t | |
861 | typedef atomic<uint64_t> atomic_uint64_t; | |
862 | ||
863 | ||
d31b8797 JW |
864 | /// atomic_int_least8_t |
865 | typedef atomic<int_least8_t> atomic_int_least8_t; | |
866 | ||
867 | /// atomic_uint_least8_t | |
868 | typedef atomic<uint_least8_t> atomic_uint_least8_t; | |
869 | ||
870 | /// atomic_int_least16_t | |
871 | typedef atomic<int_least16_t> atomic_int_least16_t; | |
872 | ||
873 | /// atomic_uint_least16_t | |
874 | typedef atomic<uint_least16_t> atomic_uint_least16_t; | |
875 | ||
876 | /// atomic_int_least32_t | |
877 | typedef atomic<int_least32_t> atomic_int_least32_t; | |
878 | ||
879 | /// atomic_uint_least32_t | |
880 | typedef atomic<uint_least32_t> atomic_uint_least32_t; | |
881 | ||
882 | /// atomic_int_least64_t | |
883 | typedef atomic<int_least64_t> atomic_int_least64_t; | |
884 | ||
885 | /// atomic_uint_least64_t | |
886 | typedef atomic<uint_least64_t> atomic_uint_least64_t; | |
887 | ||
888 | ||
889 | /// atomic_int_fast8_t | |
890 | typedef atomic<int_fast8_t> atomic_int_fast8_t; | |
891 | ||
892 | /// atomic_uint_fast8_t | |
893 | typedef atomic<uint_fast8_t> atomic_uint_fast8_t; | |
894 | ||
895 | /// atomic_int_fast16_t | |
896 | typedef atomic<int_fast16_t> atomic_int_fast16_t; | |
897 | ||
898 | /// atomic_uint_fast16_t | |
899 | typedef atomic<uint_fast16_t> atomic_uint_fast16_t; | |
900 | ||
901 | /// atomic_int_fast32_t | |
902 | typedef atomic<int_fast32_t> atomic_int_fast32_t; | |
903 | ||
904 | /// atomic_uint_fast32_t | |
905 | typedef atomic<uint_fast32_t> atomic_uint_fast32_t; | |
906 | ||
907 | /// atomic_int_fast64_t | |
908 | typedef atomic<int_fast64_t> atomic_int_fast64_t; | |
909 | ||
910 | /// atomic_uint_fast64_t | |
911 | typedef atomic<uint_fast64_t> atomic_uint_fast64_t; | |
912 | ||
913 | ||
914 | /// atomic_intptr_t | |
915 | typedef atomic<intptr_t> atomic_intptr_t; | |
916 | ||
917 | /// atomic_uintptr_t | |
918 | typedef atomic<uintptr_t> atomic_uintptr_t; | |
919 | ||
920 | /// atomic_size_t | |
921 | typedef atomic<size_t> atomic_size_t; | |
922 | ||
923 | /// atomic_intmax_t | |
924 | typedef atomic<intmax_t> atomic_intmax_t; | |
925 | ||
926 | /// atomic_uintmax_t | |
927 | typedef atomic<uintmax_t> atomic_uintmax_t; | |
928 | ||
929 | /// atomic_ptrdiff_t | |
930 | typedef atomic<ptrdiff_t> atomic_ptrdiff_t; | |
931 | ||
932 | ||
94a86be0 | 933 | // Function definitions, atomic_flag operations. |
afd88205 | 934 | inline bool |
bdc05efb PC |
935 | atomic_flag_test_and_set_explicit(atomic_flag* __a, |
936 | memory_order __m) noexcept | |
50ce8d3d | 937 | { return __a->test_and_set(__m); } |
d466a7e2 | 938 | |
94a86be0 | 939 | inline bool |
036e0d4f | 940 | atomic_flag_test_and_set_explicit(volatile atomic_flag* __a, |
bdc05efb | 941 | memory_order __m) noexcept |
94a86be0 BK |
942 | { return __a->test_and_set(__m); } |
943 | ||
afd88205 | 944 | inline void |
bdc05efb | 945 | atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept |
94a86be0 BK |
946 | { __a->clear(__m); } |
947 | ||
948 | inline void | |
bdc05efb PC |
949 | atomic_flag_clear_explicit(volatile atomic_flag* __a, |
950 | memory_order __m) noexcept | |
94a86be0 | 951 | { __a->clear(__m); } |
d466a7e2 | 952 | |
94a86be0 | 953 | inline bool |
bdc05efb | 954 | atomic_flag_test_and_set(atomic_flag* __a) noexcept |
94a86be0 | 955 | { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); } |
d466a7e2 | 956 | |
94a86be0 | 957 | inline bool |
bdc05efb | 958 | atomic_flag_test_and_set(volatile atomic_flag* __a) noexcept |
94a86be0 BK |
959 | { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); } |
960 | ||
961 | inline void | |
bdc05efb | 962 | atomic_flag_clear(atomic_flag* __a) noexcept |
94a86be0 BK |
963 | { atomic_flag_clear_explicit(__a, memory_order_seq_cst); } |
964 | ||
965 | inline void | |
bdc05efb | 966 | atomic_flag_clear(volatile atomic_flag* __a) noexcept |
94a86be0 | 967 | { atomic_flag_clear_explicit(__a, memory_order_seq_cst); } |
94a86be0 | 968 | |
d466a7e2 | 969 | |
036e0d4f | 970 | // Function templates generally applicable to atomic types. |
94a86be0 BK |
971 | template<typename _ITp> |
972 | inline bool | |
bdc05efb | 973 | atomic_is_lock_free(const atomic<_ITp>* __a) noexcept |
94a86be0 BK |
974 | { return __a->is_lock_free(); } |
975 | ||
976 | template<typename _ITp> | |
977 | inline bool | |
bdc05efb | 978 | atomic_is_lock_free(const volatile atomic<_ITp>* __a) noexcept |
94a86be0 BK |
979 | { return __a->is_lock_free(); } |
980 | ||
981 | template<typename _ITp> | |
036e0d4f | 982 | inline void |
0e4974d6 JW |
983 | atomic_init(atomic<_ITp>* __a, _ITp __i) noexcept |
984 | { __a->store(__i, memory_order_relaxed); } | |
94a86be0 BK |
985 | |
986 | template<typename _ITp> | |
036e0d4f | 987 | inline void |
0e4974d6 JW |
988 | atomic_init(volatile atomic<_ITp>* __a, _ITp __i) noexcept |
989 | { __a->store(__i, memory_order_relaxed); } | |
d466a7e2 | 990 | |
50ce8d3d | 991 | template<typename _ITp> |
afd88205 | 992 | inline void |
bdc05efb PC |
993 | atomic_store_explicit(atomic<_ITp>* __a, _ITp __i, |
994 | memory_order __m) noexcept | |
50ce8d3d BK |
995 | { __a->store(__i, __m); } |
996 | ||
94a86be0 BK |
997 | template<typename _ITp> |
998 | inline void | |
036e0d4f | 999 | atomic_store_explicit(volatile atomic<_ITp>* __a, _ITp __i, |
bdc05efb | 1000 | memory_order __m) noexcept |
94a86be0 BK |
1001 | { __a->store(__i, __m); } |
1002 | ||
50ce8d3d BK |
1003 | template<typename _ITp> |
1004 | inline _ITp | |
bdc05efb | 1005 | atomic_load_explicit(const atomic<_ITp>* __a, memory_order __m) noexcept |
afd88205 | 1006 | { return __a->load(__m); } |
50ce8d3d | 1007 | |
94a86be0 BK |
1008 | template<typename _ITp> |
1009 | inline _ITp | |
036e0d4f | 1010 | atomic_load_explicit(const volatile atomic<_ITp>* __a, |
bdc05efb | 1011 | memory_order __m) noexcept |
94a86be0 BK |
1012 | { return __a->load(__m); } |
1013 | ||
50ce8d3d | 1014 | template<typename _ITp> |
afd88205 | 1015 | inline _ITp |
036e0d4f | 1016 | atomic_exchange_explicit(atomic<_ITp>* __a, _ITp __i, |
bdc05efb | 1017 | memory_order __m) noexcept |
afd88205 | 1018 | { return __a->exchange(__i, __m); } |
50ce8d3d | 1019 | |
94a86be0 BK |
1020 | template<typename _ITp> |
1021 | inline _ITp | |
036e0d4f | 1022 | atomic_exchange_explicit(volatile atomic<_ITp>* __a, _ITp __i, |
bdc05efb | 1023 | memory_order __m) noexcept |
94a86be0 BK |
1024 | { return __a->exchange(__i, __m); } |
1025 | ||
50ce8d3d | 1026 | template<typename _ITp> |
afd88205 | 1027 | inline bool |
036e0d4f | 1028 | atomic_compare_exchange_weak_explicit(atomic<_ITp>* __a, |
afd88205 | 1029 | _ITp* __i1, _ITp __i2, |
bdc05efb PC |
1030 | memory_order __m1, |
1031 | memory_order __m2) noexcept | |
50ce8d3d | 1032 | { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); } |
d466a7e2 | 1033 | |
94a86be0 BK |
1034 | template<typename _ITp> |
1035 | inline bool | |
036e0d4f | 1036 | atomic_compare_exchange_weak_explicit(volatile atomic<_ITp>* __a, |
94a86be0 | 1037 | _ITp* __i1, _ITp __i2, |
bdc05efb PC |
1038 | memory_order __m1, |
1039 | memory_order __m2) noexcept | |
94a86be0 BK |
1040 | { return __a->compare_exchange_weak(*__i1, __i2, __m1, __m2); } |
1041 | ||
50ce8d3d | 1042 | template<typename _ITp> |
afd88205 | 1043 | inline bool |
036e0d4f | 1044 | atomic_compare_exchange_strong_explicit(atomic<_ITp>* __a, |
afd88205 BK |
1045 | _ITp* __i1, _ITp __i2, |
1046 | memory_order __m1, | |
bdc05efb | 1047 | memory_order __m2) noexcept |
50ce8d3d BK |
1048 | { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); } |
1049 | ||
94a86be0 BK |
1050 | template<typename _ITp> |
1051 | inline bool | |
036e0d4f | 1052 | atomic_compare_exchange_strong_explicit(volatile atomic<_ITp>* __a, |
94a86be0 BK |
1053 | _ITp* __i1, _ITp __i2, |
1054 | memory_order __m1, | |
bdc05efb | 1055 | memory_order __m2) noexcept |
94a86be0 BK |
1056 | { return __a->compare_exchange_strong(*__i1, __i2, __m1, __m2); } |
1057 | ||
d466a7e2 | 1058 | |
50ce8d3d | 1059 | template<typename _ITp> |
afd88205 | 1060 | inline void |
bdc05efb | 1061 | atomic_store(atomic<_ITp>* __a, _ITp __i) noexcept |
50ce8d3d | 1062 | { atomic_store_explicit(__a, __i, memory_order_seq_cst); } |
d466a7e2 | 1063 | |
94a86be0 BK |
1064 | template<typename _ITp> |
1065 | inline void | |
bdc05efb | 1066 | atomic_store(volatile atomic<_ITp>* __a, _ITp __i) noexcept |
94a86be0 BK |
1067 | { atomic_store_explicit(__a, __i, memory_order_seq_cst); } |
1068 | ||
50ce8d3d | 1069 | template<typename _ITp> |
afd88205 | 1070 | inline _ITp |
bdc05efb | 1071 | atomic_load(const atomic<_ITp>* __a) noexcept |
50ce8d3d | 1072 | { return atomic_load_explicit(__a, memory_order_seq_cst); } |
d466a7e2 | 1073 | |
94a86be0 BK |
1074 | template<typename _ITp> |
1075 | inline _ITp | |
bdc05efb | 1076 | atomic_load(const volatile atomic<_ITp>* __a) noexcept |
94a86be0 BK |
1077 | { return atomic_load_explicit(__a, memory_order_seq_cst); } |
1078 | ||
50ce8d3d | 1079 | template<typename _ITp> |
afd88205 | 1080 | inline _ITp |
bdc05efb | 1081 | atomic_exchange(atomic<_ITp>* __a, _ITp __i) noexcept |
50ce8d3d | 1082 | { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); } |
d466a7e2 | 1083 | |
94a86be0 BK |
1084 | template<typename _ITp> |
1085 | inline _ITp | |
bdc05efb | 1086 | atomic_exchange(volatile atomic<_ITp>* __a, _ITp __i) noexcept |
94a86be0 BK |
1087 | { return atomic_exchange_explicit(__a, __i, memory_order_seq_cst); } |
1088 | ||
50ce8d3d | 1089 | template<typename _ITp> |
afd88205 | 1090 | inline bool |
036e0d4f | 1091 | atomic_compare_exchange_weak(atomic<_ITp>* __a, |
bdc05efb | 1092 | _ITp* __i1, _ITp __i2) noexcept |
afd88205 BK |
1093 | { |
1094 | return atomic_compare_exchange_weak_explicit(__a, __i1, __i2, | |
50ce8d3d | 1095 | memory_order_seq_cst, |
afd88205 | 1096 | memory_order_seq_cst); |
d466a7e2 BK |
1097 | } |
1098 | ||
94a86be0 BK |
1099 | template<typename _ITp> |
1100 | inline bool | |
036e0d4f | 1101 | atomic_compare_exchange_weak(volatile atomic<_ITp>* __a, |
bdc05efb | 1102 | _ITp* __i1, _ITp __i2) noexcept |
94a86be0 BK |
1103 | { |
1104 | return atomic_compare_exchange_weak_explicit(__a, __i1, __i2, | |
1105 | memory_order_seq_cst, | |
1106 | memory_order_seq_cst); | |
1107 | } | |
1108 | ||
50ce8d3d | 1109 | template<typename _ITp> |
afd88205 | 1110 | inline bool |
036e0d4f | 1111 | atomic_compare_exchange_strong(atomic<_ITp>* __a, |
bdc05efb | 1112 | _ITp* __i1, _ITp __i2) noexcept |
afd88205 BK |
1113 | { |
1114 | return atomic_compare_exchange_strong_explicit(__a, __i1, __i2, | |
50ce8d3d | 1115 | memory_order_seq_cst, |
afd88205 | 1116 | memory_order_seq_cst); |
d466a7e2 BK |
1117 | } |
1118 | ||
94a86be0 BK |
1119 | template<typename _ITp> |
1120 | inline bool | |
036e0d4f | 1121 | atomic_compare_exchange_strong(volatile atomic<_ITp>* __a, |
bdc05efb | 1122 | _ITp* __i1, _ITp __i2) noexcept |
94a86be0 BK |
1123 | { |
1124 | return atomic_compare_exchange_strong_explicit(__a, __i1, __i2, | |
1125 | memory_order_seq_cst, | |
1126 | memory_order_seq_cst); | |
1127 | } | |
1128 | ||
036e0d4f BK |
1129 | // Function templates for atomic_integral operations only, using |
1130 | // __atomic_base. Template argument should be constricted to | |
1131 | // intergral types as specified in the standard, excluding address | |
1132 | // types. | |
1133 | template<typename _ITp> | |
1134 | inline _ITp | |
1135 | atomic_fetch_add_explicit(__atomic_base<_ITp>* __a, _ITp __i, | |
bdc05efb | 1136 | memory_order __m) noexcept |
036e0d4f BK |
1137 | { return __a->fetch_add(__i, __m); } |
1138 | ||
1139 | template<typename _ITp> | |
1140 | inline _ITp | |
1141 | atomic_fetch_add_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i, | |
bdc05efb | 1142 | memory_order __m) noexcept |
036e0d4f BK |
1143 | { return __a->fetch_add(__i, __m); } |
1144 | ||
1145 | template<typename _ITp> | |
1146 | inline _ITp | |
1147 | atomic_fetch_sub_explicit(__atomic_base<_ITp>* __a, _ITp __i, | |
bdc05efb | 1148 | memory_order __m) noexcept |
036e0d4f BK |
1149 | { return __a->fetch_sub(__i, __m); } |
1150 | ||
1151 | template<typename _ITp> | |
1152 | inline _ITp | |
1153 | atomic_fetch_sub_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i, | |
bdc05efb | 1154 | memory_order __m) noexcept |
036e0d4f BK |
1155 | { return __a->fetch_sub(__i, __m); } |
1156 | ||
1157 | template<typename _ITp> | |
1158 | inline _ITp | |
1159 | atomic_fetch_and_explicit(__atomic_base<_ITp>* __a, _ITp __i, | |
bdc05efb | 1160 | memory_order __m) noexcept |
036e0d4f BK |
1161 | { return __a->fetch_and(__i, __m); } |
1162 | ||
1163 | template<typename _ITp> | |
1164 | inline _ITp | |
1165 | atomic_fetch_and_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i, | |
bdc05efb | 1166 | memory_order __m) noexcept |
036e0d4f BK |
1167 | { return __a->fetch_and(__i, __m); } |
1168 | ||
1169 | template<typename _ITp> | |
1170 | inline _ITp | |
1171 | atomic_fetch_or_explicit(__atomic_base<_ITp>* __a, _ITp __i, | |
bdc05efb | 1172 | memory_order __m) noexcept |
036e0d4f BK |
1173 | { return __a->fetch_or(__i, __m); } |
1174 | ||
1175 | template<typename _ITp> | |
1176 | inline _ITp | |
1177 | atomic_fetch_or_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i, | |
bdc05efb | 1178 | memory_order __m) noexcept |
036e0d4f BK |
1179 | { return __a->fetch_or(__i, __m); } |
1180 | ||
1181 | template<typename _ITp> | |
1182 | inline _ITp | |
1183 | atomic_fetch_xor_explicit(__atomic_base<_ITp>* __a, _ITp __i, | |
bdc05efb | 1184 | memory_order __m) noexcept |
036e0d4f BK |
1185 | { return __a->fetch_xor(__i, __m); } |
1186 | ||
1187 | template<typename _ITp> | |
1188 | inline _ITp | |
1189 | atomic_fetch_xor_explicit(volatile __atomic_base<_ITp>* __a, _ITp __i, | |
bdc05efb | 1190 | memory_order __m) noexcept |
036e0d4f BK |
1191 | { return __a->fetch_xor(__i, __m); } |
1192 | ||
50ce8d3d | 1193 | template<typename _ITp> |
afd88205 | 1194 | inline _ITp |
bdc05efb | 1195 | atomic_fetch_add(__atomic_base<_ITp>* __a, _ITp __i) noexcept |
50ce8d3d BK |
1196 | { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); } |
1197 | ||
94a86be0 BK |
1198 | template<typename _ITp> |
1199 | inline _ITp | |
bdc05efb | 1200 | atomic_fetch_add(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept |
94a86be0 BK |
1201 | { return atomic_fetch_add_explicit(__a, __i, memory_order_seq_cst); } |
1202 | ||
50ce8d3d | 1203 | template<typename _ITp> |
afd88205 | 1204 | inline _ITp |
bdc05efb | 1205 | atomic_fetch_sub(__atomic_base<_ITp>* __a, _ITp __i) noexcept |
50ce8d3d BK |
1206 | { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); } |
1207 | ||
94a86be0 BK |
1208 | template<typename _ITp> |
1209 | inline _ITp | |
bdc05efb | 1210 | atomic_fetch_sub(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept |
94a86be0 BK |
1211 | { return atomic_fetch_sub_explicit(__a, __i, memory_order_seq_cst); } |
1212 | ||
50ce8d3d | 1213 | template<typename _ITp> |
afd88205 | 1214 | inline _ITp |
bdc05efb | 1215 | atomic_fetch_and(__atomic_base<_ITp>* __a, _ITp __i) noexcept |
50ce8d3d BK |
1216 | { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); } |
1217 | ||
94a86be0 BK |
1218 | template<typename _ITp> |
1219 | inline _ITp | |
bdc05efb | 1220 | atomic_fetch_and(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept |
94a86be0 BK |
1221 | { return atomic_fetch_and_explicit(__a, __i, memory_order_seq_cst); } |
1222 | ||
50ce8d3d | 1223 | template<typename _ITp> |
afd88205 | 1224 | inline _ITp |
bdc05efb | 1225 | atomic_fetch_or(__atomic_base<_ITp>* __a, _ITp __i) noexcept |
50ce8d3d BK |
1226 | { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); } |
1227 | ||
94a86be0 BK |
1228 | template<typename _ITp> |
1229 | inline _ITp | |
bdc05efb | 1230 | atomic_fetch_or(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept |
94a86be0 BK |
1231 | { return atomic_fetch_or_explicit(__a, __i, memory_order_seq_cst); } |
1232 | ||
50ce8d3d | 1233 | template<typename _ITp> |
afd88205 | 1234 | inline _ITp |
bdc05efb | 1235 | atomic_fetch_xor(__atomic_base<_ITp>* __a, _ITp __i) noexcept |
50ce8d3d | 1236 | { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); } |
d466a7e2 | 1237 | |
94a86be0 BK |
1238 | template<typename _ITp> |
1239 | inline _ITp | |
bdc05efb | 1240 | atomic_fetch_xor(volatile __atomic_base<_ITp>* __a, _ITp __i) noexcept |
94a86be0 BK |
1241 | { return atomic_fetch_xor_explicit(__a, __i, memory_order_seq_cst); } |
1242 | ||
036e0d4f BK |
1243 | |
1244 | // Partial specializations for pointers. | |
1245 | template<typename _ITp> | |
1246 | inline _ITp* | |
1247 | atomic_fetch_add_explicit(atomic<_ITp*>* __a, ptrdiff_t __d, | |
bdc05efb | 1248 | memory_order __m) noexcept |
036e0d4f BK |
1249 | { return __a->fetch_add(__d, __m); } |
1250 | ||
1251 | template<typename _ITp> | |
1252 | inline _ITp* | |
1253 | atomic_fetch_add_explicit(volatile atomic<_ITp*>* __a, ptrdiff_t __d, | |
bdc05efb | 1254 | memory_order __m) noexcept |
036e0d4f BK |
1255 | { return __a->fetch_add(__d, __m); } |
1256 | ||
1257 | template<typename _ITp> | |
1258 | inline _ITp* | |
bdc05efb | 1259 | atomic_fetch_add(volatile atomic<_ITp*>* __a, ptrdiff_t __d) noexcept |
036e0d4f BK |
1260 | { return __a->fetch_add(__d); } |
1261 | ||
1262 | template<typename _ITp> | |
1263 | inline _ITp* | |
bdc05efb | 1264 | atomic_fetch_add(atomic<_ITp*>* __a, ptrdiff_t __d) noexcept |
036e0d4f BK |
1265 | { return __a->fetch_add(__d); } |
1266 | ||
1267 | template<typename _ITp> | |
1268 | inline _ITp* | |
1269 | atomic_fetch_sub_explicit(volatile atomic<_ITp*>* __a, | |
bdc05efb | 1270 | ptrdiff_t __d, memory_order __m) noexcept |
036e0d4f BK |
1271 | { return __a->fetch_sub(__d, __m); } |
1272 | ||
1273 | template<typename _ITp> | |
1274 | inline _ITp* | |
1275 | atomic_fetch_sub_explicit(atomic<_ITp*>* __a, ptrdiff_t __d, | |
bdc05efb | 1276 | memory_order __m) noexcept |
036e0d4f BK |
1277 | { return __a->fetch_sub(__d, __m); } |
1278 | ||
1279 | template<typename _ITp> | |
1280 | inline _ITp* | |
bdc05efb | 1281 | atomic_fetch_sub(volatile atomic<_ITp*>* __a, ptrdiff_t __d) noexcept |
036e0d4f BK |
1282 | { return __a->fetch_sub(__d); } |
1283 | ||
1284 | template<typename _ITp> | |
1285 | inline _ITp* | |
bdc05efb | 1286 | atomic_fetch_sub(atomic<_ITp*>* __a, ptrdiff_t __d) noexcept |
036e0d4f | 1287 | { return __a->fetch_sub(__d); } |
5b9daa7e BK |
1288 | // @} group atomics |
1289 | ||
12ffa228 BK |
1290 | _GLIBCXX_END_NAMESPACE_VERSION |
1291 | } // namespace | |
d466a7e2 | 1292 | |
709def90 PC |
1293 | #endif // C++11 |
1294 | ||
1295 | #endif // _GLIBCXX_ATOMIC |