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