blob: 60057f1ebe331750b4011d5a1bacb5ba63fec786 [file] [log] [blame]
Howard Hinnant8f73c632010-09-27 21:17:381// -*- C++ -*-
2//===--------------------------- atomic -----------------------------------===//
3//
Chandler Carruth4abbf7d2019-01-19 08:50:564// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnant8f73c632010-09-27 21:17:387//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_ATOMIC
11#define _LIBCPP_ATOMIC
12
13/*
14 atomic synopsis
15
16namespace std
17{
18
JF Bastien08511cd2016-03-25 15:48:2119// feature test macro
20
21#define __cpp_lib_atomic_is_always_lock_free // as specified by SG10
22
Howard Hinnant8f73c632010-09-27 21:17:3823// order and consistency
24
25typedef enum memory_order
26{
Howard Hinnantd1176e22010-09-28 17:13:3827 memory_order_relaxed,
28 memory_order_consume, // load-consume
29 memory_order_acquire, // load-acquire
30 memory_order_release, // store-release
31 memory_order_acq_rel, // store-release load-acquire
32 memory_order_seq_cst // store-release load-acquire
Howard Hinnant8f73c632010-09-27 21:17:3833} memory_order;
34
Howard Hinnant300c67a2012-04-11 20:14:2135template <class T> T kill_dependency(T y) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:3836
37// lock-free property
38
Howard Hinnant7b9d6a82013-01-21 20:39:4139#define ATOMIC_BOOL_LOCK_FREE unspecified
Howard Hinnant8f73c632010-09-27 21:17:3840#define ATOMIC_CHAR_LOCK_FREE unspecified
41#define ATOMIC_CHAR16_T_LOCK_FREE unspecified
42#define ATOMIC_CHAR32_T_LOCK_FREE unspecified
43#define ATOMIC_WCHAR_T_LOCK_FREE unspecified
44#define ATOMIC_SHORT_LOCK_FREE unspecified
45#define ATOMIC_INT_LOCK_FREE unspecified
46#define ATOMIC_LONG_LOCK_FREE unspecified
47#define ATOMIC_LLONG_LOCK_FREE unspecified
Howard Hinnant7b9d6a82013-01-21 20:39:4148#define ATOMIC_POINTER_LOCK_FREE unspecified
Howard Hinnant8f73c632010-09-27 21:17:3849
Howard Hinnant8f73c632010-09-27 21:17:3850// flag type and operations
51
52typedef struct atomic_flag
53{
Howard Hinnant300c67a2012-04-11 20:14:2154 bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
55 bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
56 void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
57 void clear(memory_order m = memory_order_seq_cst) noexcept;
58 atomic_flag() noexcept = default;
Howard Hinnant8f73c632010-09-27 21:17:3859 atomic_flag(const atomic_flag&) = delete;
60 atomic_flag& operator=(const atomic_flag&) = delete;
61 atomic_flag& operator=(const atomic_flag&) volatile = delete;
62} atomic_flag;
63
Howard Hinnant4777bf22010-12-06 23:10:0864bool
Howard Hinnant300c67a2012-04-11 20:14:2165 atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0866
67bool
Howard Hinnant300c67a2012-04-11 20:14:2168 atomic_flag_test_and_set(atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0869
70bool
71 atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
Howard Hinnant300c67a2012-04-11 20:14:2172 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0873
74bool
Howard Hinnant300c67a2012-04-11 20:14:2175 atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0876
77void
Howard Hinnant300c67a2012-04-11 20:14:2178 atomic_flag_clear(volatile atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0879
80void
Howard Hinnant300c67a2012-04-11 20:14:2181 atomic_flag_clear(atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0882
83void
Howard Hinnant300c67a2012-04-11 20:14:2184 atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0885
86void
Howard Hinnant300c67a2012-04-11 20:14:2187 atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:3888
89#define ATOMIC_FLAG_INIT see below
Howard Hinnante7385012010-10-19 16:51:1890#define ATOMIC_VAR_INIT(value) see below
Howard Hinnant8f73c632010-09-27 21:17:3891
Howard Hinnant8f73c632010-09-27 21:17:3892template <class T>
93struct atomic
94{
JF Bastien08511cd2016-03-25 15:48:2195 static constexpr bool is_always_lock_free;
Howard Hinnant300c67a2012-04-11 20:14:2196 bool is_lock_free() const volatile noexcept;
97 bool is_lock_free() const noexcept;
98 void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
99 void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
100 T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
101 T load(memory_order m = memory_order_seq_cst) const noexcept;
102 operator T() const volatile noexcept;
103 operator T() const noexcept;
104 T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
105 T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08106 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21107 memory_order s, memory_order f) volatile noexcept;
108 bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08109 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21110 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08111 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21112 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08113 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21114 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08115 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21116 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08117 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21118 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08119 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21120 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38121
Howard Hinnant300c67a2012-04-11 20:14:21122 atomic() noexcept = default;
123 constexpr atomic(T desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38124 atomic(const atomic&) = delete;
125 atomic& operator=(const atomic&) = delete;
126 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnant300c67a2012-04-11 20:14:21127 T operator=(T) volatile noexcept;
128 T operator=(T) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38129};
130
131template <>
Howard Hinnant4777bf22010-12-06 23:10:08132struct atomic<integral>
Howard Hinnant8f73c632010-09-27 21:17:38133{
JF Bastien08511cd2016-03-25 15:48:21134 static constexpr bool is_always_lock_free;
Howard Hinnant300c67a2012-04-11 20:14:21135 bool is_lock_free() const volatile noexcept;
136 bool is_lock_free() const noexcept;
137 void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
138 void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
139 integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
140 integral load(memory_order m = memory_order_seq_cst) const noexcept;
141 operator integral() const volatile noexcept;
142 operator integral() const noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08143 integral exchange(integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21144 memory_order m = memory_order_seq_cst) volatile noexcept;
145 integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08146 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21147 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08148 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21149 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08150 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21151 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08152 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21153 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08154 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21155 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08156 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21157 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08158 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21159 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08160 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21161 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38162
Howard Hinnant4777bf22010-12-06 23:10:08163 integral
Howard Hinnant300c67a2012-04-11 20:14:21164 fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
165 integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08166 integral
Howard Hinnant300c67a2012-04-11 20:14:21167 fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
168 integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08169 integral
Howard Hinnant300c67a2012-04-11 20:14:21170 fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
171 integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08172 integral
Howard Hinnant300c67a2012-04-11 20:14:21173 fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
174 integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08175 integral
Howard Hinnant300c67a2012-04-11 20:14:21176 fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
177 integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38178
Howard Hinnant300c67a2012-04-11 20:14:21179 atomic() noexcept = default;
180 constexpr atomic(integral desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38181 atomic(const atomic&) = delete;
182 atomic& operator=(const atomic&) = delete;
183 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnant300c67a2012-04-11 20:14:21184 integral operator=(integral desr) volatile noexcept;
185 integral operator=(integral desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38186
Howard Hinnant300c67a2012-04-11 20:14:21187 integral operator++(int) volatile noexcept;
188 integral operator++(int) noexcept;
189 integral operator--(int) volatile noexcept;
190 integral operator--(int) noexcept;
191 integral operator++() volatile noexcept;
192 integral operator++() noexcept;
193 integral operator--() volatile noexcept;
194 integral operator--() noexcept;
195 integral operator+=(integral op) volatile noexcept;
196 integral operator+=(integral op) noexcept;
197 integral operator-=(integral op) volatile noexcept;
198 integral operator-=(integral op) noexcept;
199 integral operator&=(integral op) volatile noexcept;
200 integral operator&=(integral op) noexcept;
201 integral operator|=(integral op) volatile noexcept;
202 integral operator|=(integral op) noexcept;
203 integral operator^=(integral op) volatile noexcept;
204 integral operator^=(integral op) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38205};
206
207template <class T>
208struct atomic<T*>
Howard Hinnant8f73c632010-09-27 21:17:38209{
JF Bastien08511cd2016-03-25 15:48:21210 static constexpr bool is_always_lock_free;
Howard Hinnant300c67a2012-04-11 20:14:21211 bool is_lock_free() const volatile noexcept;
212 bool is_lock_free() const noexcept;
213 void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
214 void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
215 T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
216 T* load(memory_order m = memory_order_seq_cst) const noexcept;
217 operator T*() const volatile noexcept;
218 operator T*() const noexcept;
219 T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
220 T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08221 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21222 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08223 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21224 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08225 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21226 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08227 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21228 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08229 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21230 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08231 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21232 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08233 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21234 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08235 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21236 memory_order m = memory_order_seq_cst) noexcept;
237 T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
238 T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
239 T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
240 T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08241
Howard Hinnant300c67a2012-04-11 20:14:21242 atomic() noexcept = default;
243 constexpr atomic(T* desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38244 atomic(const atomic&) = delete;
245 atomic& operator=(const atomic&) = delete;
246 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnant4777bf22010-12-06 23:10:08247
Howard Hinnant300c67a2012-04-11 20:14:21248 T* operator=(T*) volatile noexcept;
249 T* operator=(T*) noexcept;
250 T* operator++(int) volatile noexcept;
251 T* operator++(int) noexcept;
252 T* operator--(int) volatile noexcept;
253 T* operator--(int) noexcept;
254 T* operator++() volatile noexcept;
255 T* operator++() noexcept;
256 T* operator--() volatile noexcept;
257 T* operator--() noexcept;
258 T* operator+=(ptrdiff_t op) volatile noexcept;
259 T* operator+=(ptrdiff_t op) noexcept;
260 T* operator-=(ptrdiff_t op) volatile noexcept;
261 T* operator-=(ptrdiff_t op) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38262};
263
Howard Hinnant4777bf22010-12-06 23:10:08264
265template <class T>
266 bool
Howard Hinnant300c67a2012-04-11 20:14:21267 atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08268
269template <class T>
270 bool
Howard Hinnant300c67a2012-04-11 20:14:21271 atomic_is_lock_free(const atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08272
273template <class T>
274 void
Howard Hinnant300c67a2012-04-11 20:14:21275 atomic_init(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08276
277template <class T>
278 void
Howard Hinnant300c67a2012-04-11 20:14:21279 atomic_init(atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08280
281template <class T>
282 void
Howard Hinnant300c67a2012-04-11 20:14:21283 atomic_store(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08284
285template <class T>
286 void
Howard Hinnant300c67a2012-04-11 20:14:21287 atomic_store(atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08288
289template <class T>
290 void
Howard Hinnant300c67a2012-04-11 20:14:21291 atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08292
293template <class T>
294 void
Howard Hinnant300c67a2012-04-11 20:14:21295 atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08296
297template <class T>
298 T
Howard Hinnant300c67a2012-04-11 20:14:21299 atomic_load(const volatile atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08300
301template <class T>
302 T
Howard Hinnant300c67a2012-04-11 20:14:21303 atomic_load(const atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08304
305template <class T>
306 T
Howard Hinnant300c67a2012-04-11 20:14:21307 atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08308
309template <class T>
310 T
Howard Hinnant300c67a2012-04-11 20:14:21311 atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08312
313template <class T>
314 T
Howard Hinnant300c67a2012-04-11 20:14:21315 atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08316
317template <class T>
318 T
Howard Hinnant300c67a2012-04-11 20:14:21319 atomic_exchange(atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08320
321template <class T>
322 T
Howard Hinnant300c67a2012-04-11 20:14:21323 atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08324
325template <class T>
326 T
Howard Hinnant300c67a2012-04-11 20:14:21327 atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08328
329template <class T>
330 bool
Howard Hinnant300c67a2012-04-11 20:14:21331 atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08332
333template <class T>
334 bool
Howard Hinnant300c67a2012-04-11 20:14:21335 atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08336
337template <class T>
338 bool
Howard Hinnant300c67a2012-04-11 20:14:21339 atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08340
341template <class T>
342 bool
Howard Hinnant300c67a2012-04-11 20:14:21343 atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08344
345template <class T>
346 bool
347 atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
348 T desr,
Howard Hinnant300c67a2012-04-11 20:14:21349 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08350
351template <class T>
352 bool
353 atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21354 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08355
356template <class T>
357 bool
358 atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
359 T* expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21360 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08361
362template <class T>
363 bool
364 atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
365 T desr,
Howard Hinnant300c67a2012-04-11 20:14:21366 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08367
368template <class Integral>
369 Integral
Howard Hinnant300c67a2012-04-11 20:14:21370 atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08371
372template <class Integral>
373 Integral
Howard Hinnant300c67a2012-04-11 20:14:21374 atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08375
376template <class Integral>
377 Integral
378 atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21379 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08380template <class Integral>
381 Integral
382 atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21383 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08384template <class Integral>
385 Integral
Howard Hinnant300c67a2012-04-11 20:14:21386 atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08387
388template <class Integral>
389 Integral
Howard Hinnant300c67a2012-04-11 20:14:21390 atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08391
392template <class Integral>
393 Integral
394 atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21395 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08396template <class Integral>
397 Integral
398 atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21399 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08400template <class Integral>
401 Integral
Howard Hinnant300c67a2012-04-11 20:14:21402 atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08403
404template <class Integral>
405 Integral
Howard Hinnant300c67a2012-04-11 20:14:21406 atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08407
408template <class Integral>
409 Integral
410 atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21411 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08412template <class Integral>
413 Integral
414 atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21415 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08416template <class Integral>
417 Integral
Howard Hinnant300c67a2012-04-11 20:14:21418 atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08419
420template <class Integral>
421 Integral
Howard Hinnant300c67a2012-04-11 20:14:21422 atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08423
424template <class Integral>
425 Integral
426 atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21427 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08428template <class Integral>
429 Integral
430 atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21431 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08432template <class Integral>
433 Integral
Howard Hinnant300c67a2012-04-11 20:14:21434 atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08435
436template <class Integral>
437 Integral
Howard Hinnant300c67a2012-04-11 20:14:21438 atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08439
440template <class Integral>
441 Integral
442 atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21443 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08444template <class Integral>
445 Integral
446 atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21447 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08448
449template <class T>
450 T*
Howard Hinnant300c67a2012-04-11 20:14:21451 atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08452
453template <class T>
454 T*
Howard Hinnant300c67a2012-04-11 20:14:21455 atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08456
457template <class T>
458 T*
459 atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
Howard Hinnant300c67a2012-04-11 20:14:21460 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08461template <class T>
462 T*
Howard Hinnant300c67a2012-04-11 20:14:21463 atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08464
465template <class T>
466 T*
Howard Hinnant300c67a2012-04-11 20:14:21467 atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08468
469template <class T>
470 T*
Howard Hinnant300c67a2012-04-11 20:14:21471 atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08472
473template <class T>
474 T*
475 atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
Howard Hinnant300c67a2012-04-11 20:14:21476 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08477template <class T>
478 T*
Howard Hinnant300c67a2012-04-11 20:14:21479 atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08480
481// Atomics for standard typedef types
482
Howard Hinnant6ae47052013-01-04 18:58:50483typedef atomic<bool> atomic_bool;
Howard Hinnant4777bf22010-12-06 23:10:08484typedef atomic<char> atomic_char;
485typedef atomic<signed char> atomic_schar;
486typedef atomic<unsigned char> atomic_uchar;
487typedef atomic<short> atomic_short;
488typedef atomic<unsigned short> atomic_ushort;
489typedef atomic<int> atomic_int;
490typedef atomic<unsigned int> atomic_uint;
491typedef atomic<long> atomic_long;
492typedef atomic<unsigned long> atomic_ulong;
493typedef atomic<long long> atomic_llong;
494typedef atomic<unsigned long long> atomic_ullong;
495typedef atomic<char16_t> atomic_char16_t;
496typedef atomic<char32_t> atomic_char32_t;
497typedef atomic<wchar_t> atomic_wchar_t;
498
499typedef atomic<int_least8_t> atomic_int_least8_t;
500typedef atomic<uint_least8_t> atomic_uint_least8_t;
501typedef atomic<int_least16_t> atomic_int_least16_t;
502typedef atomic<uint_least16_t> atomic_uint_least16_t;
503typedef atomic<int_least32_t> atomic_int_least32_t;
504typedef atomic<uint_least32_t> atomic_uint_least32_t;
505typedef atomic<int_least64_t> atomic_int_least64_t;
506typedef atomic<uint_least64_t> atomic_uint_least64_t;
507
508typedef atomic<int_fast8_t> atomic_int_fast8_t;
509typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
510typedef atomic<int_fast16_t> atomic_int_fast16_t;
511typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
512typedef atomic<int_fast32_t> atomic_int_fast32_t;
513typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
514typedef atomic<int_fast64_t> atomic_int_fast64_t;
515typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
516
Marshall Clowca894502016-06-30 15:28:38517typedef atomic<int8_t> atomic_int8_t;
518typedef atomic<uint8_t> atomic_uint8_t;
519typedef atomic<int16_t> atomic_int16_t;
520typedef atomic<uint16_t> atomic_uint16_t;
521typedef atomic<int32_t> atomic_int32_t;
522typedef atomic<uint32_t> atomic_uint32_t;
523typedef atomic<int64_t> atomic_int64_t;
524typedef atomic<uint64_t> atomic_uint64_t;
525
Howard Hinnant4777bf22010-12-06 23:10:08526typedef atomic<intptr_t> atomic_intptr_t;
527typedef atomic<uintptr_t> atomic_uintptr_t;
528typedef atomic<size_t> atomic_size_t;
529typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
530typedef atomic<intmax_t> atomic_intmax_t;
531typedef atomic<uintmax_t> atomic_uintmax_t;
532
Howard Hinnant8f73c632010-09-27 21:17:38533// fences
534
Howard Hinnant300c67a2012-04-11 20:14:21535void atomic_thread_fence(memory_order m) noexcept;
536void atomic_signal_fence(memory_order m) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38537
538} // std
539
540*/
541
542#include <__config>
Howard Hinnant4777bf22010-12-06 23:10:08543#include <cstddef>
544#include <cstdint>
545#include <type_traits>
Marshall Clowe3973fd2018-09-12 19:41:40546#include <version>
Howard Hinnant8f73c632010-09-27 21:17:38547
Howard Hinnant08e17472011-10-17 20:05:10548#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant8f73c632010-09-27 21:17:38549#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10550#endif
Howard Hinnant8f73c632010-09-27 21:17:38551
Jonathan Roelofs8d86b2e2014-09-05 19:45:05552#ifdef _LIBCPP_HAS_NO_THREADS
553#error <atomic> is not supported on this single threaded system
Eric Fiselier00f4a492015-08-19 17:21:46554#endif
555#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
556#error <atomic> is not implemented
557#endif
Volodymyr Sapsai6c03a7a2018-05-15 22:38:31558#ifdef kill_dependency
559#error C++ standard library is incompatible with <stdatomic.h>
560#endif
Jonathan Roelofs8d86b2e2014-09-05 19:45:05561
Eric Fiselier5ed76752017-01-13 23:45:39562#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
563 _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \
564 __m == memory_order_acquire || \
565 __m == memory_order_acq_rel, \
566 "memory order argument to atomic operation is invalid")
567
568#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
569 _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \
570 __m == memory_order_acq_rel, \
571 "memory order argument to atomic operation is invalid")
572
573#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
574 _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \
575 __f == memory_order_acq_rel, \
576 "memory order argument to atomic operation is invalid")
577
Howard Hinnant8f73c632010-09-27 21:17:38578_LIBCPP_BEGIN_NAMESPACE_STD
579
Howard Hinnantd1176e22010-09-28 17:13:38580typedef enum memory_order
581{
582 memory_order_relaxed, memory_order_consume, memory_order_acquire,
583 memory_order_release, memory_order_acq_rel, memory_order_seq_cst
584} memory_order;
585
Eric Fiselier00f4a492015-08-19 17:21:46586#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
Dan Alberte8b42322014-08-09 23:51:51587namespace __gcc_atomic {
Marshall Clowe4220212015-01-11 06:15:59588template <typename _Tp>
Dan Alberte8b42322014-08-09 23:51:51589struct __gcc_atomic_t {
Eric Fiseliere39f4b92015-12-15 00:32:21590
591#if _GNUC_VER >= 501
592 static_assert(is_trivially_copyable<_Tp>::value,
593 "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
594#endif
595
Eric Fiseliera4ae16b2015-10-14 08:36:22596 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8c570322016-11-18 06:42:17597#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera4ae16b2015-10-14 08:36:22598 __gcc_atomic_t() _NOEXCEPT = default;
599#else
600 __gcc_atomic_t() _NOEXCEPT : __a_value() {}
Eric Fiselier8c570322016-11-18 06:42:17601#endif // _LIBCPP_CXX03_LANG
Eric Fiselier26edd802015-07-14 17:50:27602 _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT
603 : __a_value(value) {}
Marshall Clowe4220212015-01-11 06:15:59604 _Tp __a_value;
Dan Alberte8b42322014-08-09 23:51:51605};
606#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>
607
Marshall Clowe4220212015-01-11 06:15:59608template <typename _Tp> _Tp __create();
Dan Alberte8b42322014-08-09 23:51:51609
Marshall Clowe4220212015-01-11 06:15:59610template <typename _Tp, typename _Td>
611typename enable_if<sizeof(_Tp()->__a_value = __create<_Td>()), char>::type
Dan Alberte8b42322014-08-09 23:51:51612 __test_atomic_assignable(int);
Marshall Clowe4220212015-01-11 06:15:59613template <typename _Tp, typename _Up>
Dan Alberte8b42322014-08-09 23:51:51614__two __test_atomic_assignable(...);
615
Marshall Clowe4220212015-01-11 06:15:59616template <typename _Tp, typename _Td>
Dan Alberte8b42322014-08-09 23:51:51617struct __can_assign {
618 static const bool value =
Marshall Clowe4220212015-01-11 06:15:59619 sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char);
Dan Alberte8b42322014-08-09 23:51:51620};
621
Eric Fiseliera4ae16b2015-10-14 08:36:22622static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51623 // Avoid switch statement to make this a constexpr.
624 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
625 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
626 (__order == memory_order_release ? __ATOMIC_RELEASE:
627 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
628 (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
629 __ATOMIC_CONSUME))));
630}
631
Eric Fiseliera4ae16b2015-10-14 08:36:22632static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
Dan Albertc1017382015-01-06 18:39:37633 // Avoid switch statement to make this a constexpr.
634 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
635 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
636 (__order == memory_order_release ? __ATOMIC_RELAXED:
637 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
638 (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE:
639 __ATOMIC_CONSUME))));
640}
641
Dan Alberte8b42322014-08-09 23:51:51642} // namespace __gcc_atomic
643
644template <typename _Tp>
645static inline
646typename enable_if<
647 __gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value>::type
JF Bastien4b722942018-05-26 19:44:45648__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
Dan Alberte8b42322014-08-09 23:51:51649 __a->__a_value = __val;
650}
651
652template <typename _Tp>
653static inline
654typename enable_if<
655 !__gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value &&
656 __gcc_atomic::__can_assign< _Atomic(_Tp)*, _Tp>::value>::type
JF Bastien4b722942018-05-26 19:44:45657__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
Dan Alberte8b42322014-08-09 23:51:51658 // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
659 // the default operator= in an object is not volatile, a byte-by-byte copy
660 // is required.
661 volatile char* to = reinterpret_cast<volatile char*>(&__a->__a_value);
662 volatile char* end = to + sizeof(_Tp);
663 char* from = reinterpret_cast<char*>(&__val);
664 while (to != end) {
665 *to++ = *from++;
666 }
667}
668
669template <typename _Tp>
JF Bastien4b722942018-05-26 19:44:45670static inline void __c11_atomic_init(_Atomic(_Tp)* __a, _Tp __val) {
Dan Alberte8b42322014-08-09 23:51:51671 __a->__a_value = __val;
672}
673
674static inline void __c11_atomic_thread_fence(memory_order __order) {
675 __atomic_thread_fence(__gcc_atomic::__to_gcc_order(__order));
676}
677
678static inline void __c11_atomic_signal_fence(memory_order __order) {
679 __atomic_signal_fence(__gcc_atomic::__to_gcc_order(__order));
680}
681
Dan Alberte8b42322014-08-09 23:51:51682template <typename _Tp>
683static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a, _Tp __val,
JF Bastien4b722942018-05-26 19:44:45684 memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51685 return __atomic_store(&__a->__a_value, &__val,
686 __gcc_atomic::__to_gcc_order(__order));
687}
688
689template <typename _Tp>
690static inline void __c11_atomic_store(_Atomic(_Tp)* __a, _Tp __val,
JF Bastien4b722942018-05-26 19:44:45691 memory_order __order) {
Dan Albertc1017382015-01-06 18:39:37692 __atomic_store(&__a->__a_value, &__val,
693 __gcc_atomic::__to_gcc_order(__order));
Dan Alberte8b42322014-08-09 23:51:51694}
695
696template <typename _Tp>
JF Bastien8d476cd2018-06-01 18:02:53697static inline _Tp __c11_atomic_load(const volatile _Atomic(_Tp)* __a,
JF Bastien4b722942018-05-26 19:44:45698 memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51699 _Tp __ret;
700 __atomic_load(&__a->__a_value, &__ret,
701 __gcc_atomic::__to_gcc_order(__order));
702 return __ret;
703}
704
705template <typename _Tp>
JF Bastien8d476cd2018-06-01 18:02:53706static inline _Tp __c11_atomic_load(const _Atomic(_Tp)* __a, memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51707 _Tp __ret;
708 __atomic_load(&__a->__a_value, &__ret,
709 __gcc_atomic::__to_gcc_order(__order));
710 return __ret;
711}
712
713template <typename _Tp>
714static inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a,
JF Bastien4b722942018-05-26 19:44:45715 _Tp __value, memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51716 _Tp __ret;
717 __atomic_exchange(&__a->__a_value, &__value, &__ret,
718 __gcc_atomic::__to_gcc_order(__order));
719 return __ret;
720}
721
722template <typename _Tp>
723static inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value,
JF Bastien4b722942018-05-26 19:44:45724 memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51725 _Tp __ret;
726 __atomic_exchange(&__a->__a_value, &__value, &__ret,
727 __gcc_atomic::__to_gcc_order(__order));
728 return __ret;
729}
730
731template <typename _Tp>
732static inline bool __c11_atomic_compare_exchange_strong(
733 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
JF Bastien4b722942018-05-26 19:44:45734 memory_order __success, memory_order __failure) {
Dan Alberte8b42322014-08-09 23:51:51735 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
736 false,
737 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37738 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51739}
740
741template <typename _Tp>
742static inline bool __c11_atomic_compare_exchange_strong(
743 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
JF Bastien4b722942018-05-26 19:44:45744 memory_order __failure) {
Dan Alberte8b42322014-08-09 23:51:51745 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
746 false,
747 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37748 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51749}
750
751template <typename _Tp>
752static inline bool __c11_atomic_compare_exchange_weak(
753 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
JF Bastien4b722942018-05-26 19:44:45754 memory_order __success, memory_order __failure) {
Dan Alberte8b42322014-08-09 23:51:51755 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
756 true,
757 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37758 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51759}
760
761template <typename _Tp>
762static inline bool __c11_atomic_compare_exchange_weak(
763 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
JF Bastien4b722942018-05-26 19:44:45764 memory_order __failure) {
Dan Alberte8b42322014-08-09 23:51:51765 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
766 true,
767 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37768 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51769}
770
771template <typename _Tp>
772struct __skip_amt { enum {value = 1}; };
773
774template <typename _Tp>
775struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
776
777// FIXME: Haven't figured out what the spec says about using arrays with
778// atomic_fetch_add. Force a failure rather than creating bad behavior.
779template <typename _Tp>
780struct __skip_amt<_Tp[]> { };
781template <typename _Tp, int n>
782struct __skip_amt<_Tp[n]> { };
783
784template <typename _Tp, typename _Td>
785static inline _Tp __c11_atomic_fetch_add(volatile _Atomic(_Tp)* __a,
JF Bastien4b722942018-05-26 19:44:45786 _Td __delta, memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51787 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
788 __gcc_atomic::__to_gcc_order(__order));
789}
790
791template <typename _Tp, typename _Td>
792static inline _Tp __c11_atomic_fetch_add(_Atomic(_Tp)* __a, _Td __delta,
JF Bastien4b722942018-05-26 19:44:45793 memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51794 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
795 __gcc_atomic::__to_gcc_order(__order));
796}
797
798template <typename _Tp, typename _Td>
799static inline _Tp __c11_atomic_fetch_sub(volatile _Atomic(_Tp)* __a,
JF Bastien4b722942018-05-26 19:44:45800 _Td __delta, memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51801 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
802 __gcc_atomic::__to_gcc_order(__order));
803}
804
805template <typename _Tp, typename _Td>
806static inline _Tp __c11_atomic_fetch_sub(_Atomic(_Tp)* __a, _Td __delta,
JF Bastien4b722942018-05-26 19:44:45807 memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51808 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
809 __gcc_atomic::__to_gcc_order(__order));
810}
811
812template <typename _Tp>
813static inline _Tp __c11_atomic_fetch_and(volatile _Atomic(_Tp)* __a,
JF Bastien4b722942018-05-26 19:44:45814 _Tp __pattern, memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51815 return __atomic_fetch_and(&__a->__a_value, __pattern,
816 __gcc_atomic::__to_gcc_order(__order));
817}
818
819template <typename _Tp>
820static inline _Tp __c11_atomic_fetch_and(_Atomic(_Tp)* __a,
JF Bastien4b722942018-05-26 19:44:45821 _Tp __pattern, memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51822 return __atomic_fetch_and(&__a->__a_value, __pattern,
823 __gcc_atomic::__to_gcc_order(__order));
824}
825
826template <typename _Tp>
827static inline _Tp __c11_atomic_fetch_or(volatile _Atomic(_Tp)* __a,
JF Bastien4b722942018-05-26 19:44:45828 _Tp __pattern, memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51829 return __atomic_fetch_or(&__a->__a_value, __pattern,
830 __gcc_atomic::__to_gcc_order(__order));
831}
832
833template <typename _Tp>
834static inline _Tp __c11_atomic_fetch_or(_Atomic(_Tp)* __a, _Tp __pattern,
JF Bastien4b722942018-05-26 19:44:45835 memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51836 return __atomic_fetch_or(&__a->__a_value, __pattern,
837 __gcc_atomic::__to_gcc_order(__order));
838}
839
840template <typename _Tp>
841static inline _Tp __c11_atomic_fetch_xor(volatile _Atomic(_Tp)* __a,
JF Bastien4b722942018-05-26 19:44:45842 _Tp __pattern, memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51843 return __atomic_fetch_xor(&__a->__a_value, __pattern,
844 __gcc_atomic::__to_gcc_order(__order));
845}
846
847template <typename _Tp>
848static inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern,
JF Bastien4b722942018-05-26 19:44:45849 memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51850 return __atomic_fetch_xor(&__a->__a_value, __pattern,
851 __gcc_atomic::__to_gcc_order(__order));
852}
Eric Fiselier00f4a492015-08-19 17:21:46853#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP
Dan Alberte8b42322014-08-09 23:51:51854
Howard Hinnantd1176e22010-09-28 17:13:38855template <class _Tp>
856inline _LIBCPP_INLINE_VISIBILITY
857_Tp
Howard Hinnant300c67a2012-04-11 20:14:21858kill_dependency(_Tp __y) _NOEXCEPT
Howard Hinnantd1176e22010-09-28 17:13:38859{
860 return __y;
861}
Howard Hinnant8f73c632010-09-27 21:17:38862
Eric Fiseliera67beb72017-04-20 23:22:46863#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)
864# define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE
865# define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE
866# define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
867# define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
868# define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
869# define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE
870# define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE
871# define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE
872# define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE
873# define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE
874#else
875# define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
876# define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
877# define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
878# define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
879# define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
880# define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
881# define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
882# define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
883# define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
884# define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
885#endif
JF Bastien08511cd2016-03-25 15:48:21886
Howard Hinnant91e2f262010-12-07 20:46:14887// general atomic<T>
888
889template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
890struct __atomic_base // false
891{
Howard Hinnant7eb9f1e2012-09-16 20:33:09892 mutable _Atomic(_Tp) __a_;
Howard Hinnant91e2f262010-12-07 20:46:14893
JF Bastien08511cd2016-03-25 15:48:21894#if defined(__cpp_lib_atomic_is_always_lock_free)
895 static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0);
896#endif
897
Howard Hinnant91e2f262010-12-07 20:46:14898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21899 bool is_lock_free() const volatile _NOEXCEPT
Eric Fiselier7726a342015-06-13 00:23:07900 {
Eric Fiselier00f4a492015-08-19 17:21:46901#if defined(_LIBCPP_HAS_C_ATOMIC_IMP)
Eric Fiselier7726a342015-06-13 00:23:07902 return __c11_atomic_is_lock_free(sizeof(_Tp));
903#else
904 return __atomic_is_lock_free(sizeof(_Tp), 0);
905#endif
906 }
Howard Hinnant91e2f262010-12-07 20:46:14907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21908 bool is_lock_free() const _NOEXCEPT
Eric Fiselier7726a342015-06-13 00:23:07909 {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();}
Howard Hinnant91e2f262010-12-07 20:46:14910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21911 void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39912 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Richard Smith6186c7f2012-04-11 18:55:46913 {__c11_atomic_store(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21915 void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39916 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Richard Smith6186c7f2012-04-11 18:55:46917 {__c11_atomic_store(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21919 _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39920 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Richard Smith6186c7f2012-04-11 18:55:46921 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21923 _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39924 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Richard Smith6186c7f2012-04-11 18:55:46925 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21927 operator _Tp() const volatile _NOEXCEPT {return load();}
Howard Hinnant91e2f262010-12-07 20:46:14928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21929 operator _Tp() const _NOEXCEPT {return load();}
Howard Hinnant91e2f262010-12-07 20:46:14930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21931 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46932 {return __c11_atomic_exchange(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21934 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46935 {return __c11_atomic_exchange(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14936 _LIBCPP_INLINE_VISIBILITY
937 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21938 memory_order __s, memory_order __f) volatile _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39939 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46940 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14941 _LIBCPP_INLINE_VISIBILITY
942 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21943 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39944 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46945 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14946 _LIBCPP_INLINE_VISIBILITY
947 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21948 memory_order __s, memory_order __f) volatile _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39949 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46950 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14951 _LIBCPP_INLINE_VISIBILITY
952 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21953 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39954 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46955 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14956 _LIBCPP_INLINE_VISIBILITY
957 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21958 memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46959 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14960 _LIBCPP_INLINE_VISIBILITY
961 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21962 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46963 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14964 _LIBCPP_INLINE_VISIBILITY
965 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21966 memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46967 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14968 _LIBCPP_INLINE_VISIBILITY
969 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21970 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46971 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14972
973 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8c570322016-11-18 06:42:17974#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:43975 __atomic_base() _NOEXCEPT = default;
976#else
977 __atomic_base() _NOEXCEPT : __a_() {}
Eric Fiselier8c570322016-11-18 06:42:17978#endif // _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:43979
Howard Hinnant91e2f262010-12-07 20:46:14980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21981 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
Eric Fiselier8eb066a2017-01-06 20:58:25982#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant91e2f262010-12-07 20:46:14983 __atomic_base(const __atomic_base&) = delete;
984 __atomic_base& operator=(const __atomic_base&) = delete;
985 __atomic_base& operator=(const __atomic_base&) volatile = delete;
Eric Fiselier8eb066a2017-01-06 20:58:25986#else
Howard Hinnant770d1c42010-12-08 17:20:28987private:
988 __atomic_base(const __atomic_base&);
989 __atomic_base& operator=(const __atomic_base&);
990 __atomic_base& operator=(const __atomic_base&) volatile;
Eric Fiselier8eb066a2017-01-06 20:58:25991#endif
Howard Hinnant91e2f262010-12-07 20:46:14992};
993
JF Bastien08511cd2016-03-25 15:48:21994#if defined(__cpp_lib_atomic_is_always_lock_free)
995template <class _Tp, bool __b>
996_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
997#endif
998
Howard Hinnant91e2f262010-12-07 20:46:14999// atomic<Integral>
1000
1001template <class _Tp>
1002struct __atomic_base<_Tp, true>
1003 : public __atomic_base<_Tp, false>
1004{
1005 typedef __atomic_base<_Tp, false> __base;
1006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431007 __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211009 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant91e2f262010-12-07 20:46:141010
1011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211012 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461013 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211015 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461016 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211018 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461019 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211021 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461022 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211024 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461025 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141026 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211027 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461028 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211030 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461031 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211033 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461034 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211036 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461037 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211039 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461040 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141041
1042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211043 _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:141044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211045 _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:141046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211047 _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:141048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211049 _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:141050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211051 _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:141052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211053 _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:141054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211055 _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:141056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211057 _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:141058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211059 _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211061 _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211063 _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211065 _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211067 _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
Howard Hinnant91e2f262010-12-07 20:46:141068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211069 _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;}
Howard Hinnant91e2f262010-12-07 20:46:141070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211071 _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
Howard Hinnant91e2f262010-12-07 20:46:141072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211073 _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;}
Howard Hinnant91e2f262010-12-07 20:46:141074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211075 _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant91e2f262010-12-07 20:46:141076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211077 _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant91e2f262010-12-07 20:46:141078};
1079
1080// atomic<T>
1081
1082template <class _Tp>
1083struct atomic
1084 : public __atomic_base<_Tp>
1085{
1086 typedef __atomic_base<_Tp> __base;
1087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431088 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211090 _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnantd2f6afb2010-12-07 23:24:411091
1092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211093 _Tp operator=(_Tp __d) volatile _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411094 {__base::store(__d); return __d;}
1095 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211096 _Tp operator=(_Tp __d) _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411097 {__base::store(__d); return __d;}
Howard Hinnant91e2f262010-12-07 20:46:141098};
1099
1100// atomic<T*>
1101
1102template <class _Tp>
1103struct atomic<_Tp*>
1104 : public __atomic_base<_Tp*>
1105{
Howard Hinnantd2f6afb2010-12-07 23:24:411106 typedef __atomic_base<_Tp*> __base;
Howard Hinnant91e2f262010-12-07 20:46:141107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431108 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211110 _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant91e2f262010-12-07 20:46:141111
1112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211113 _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411114 {__base::store(__d); return __d;}
1115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211116 _Tp* operator=(_Tp* __d) _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411117 {__base::store(__d); return __d;}
1118
1119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91e2f262010-12-07 20:46:141120 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnant300c67a2012-04-11 20:14:211121 volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461122 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211124 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461125 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141126 _LIBCPP_INLINE_VISIBILITY
1127 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnant300c67a2012-04-11 20:14:211128 volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461129 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211131 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461132 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141133
1134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211135 _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
Howard Hinnant91e2f262010-12-07 20:46:141136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211137 _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);}
Howard Hinnant91e2f262010-12-07 20:46:141138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211139 _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant91e2f262010-12-07 20:46:141140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211141 _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant91e2f262010-12-07 20:46:141142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211143 _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant91e2f262010-12-07 20:46:141144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211145 _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant91e2f262010-12-07 20:46:141146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211147 _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant91e2f262010-12-07 20:46:141148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211149 _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant91e2f262010-12-07 20:46:141150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211151 _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211153 _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211155 _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211157 _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141158};
Howard Hinnant4777bf22010-12-06 23:10:081159
1160// atomic_is_lock_free
1161
1162template <class _Tp>
1163inline _LIBCPP_INLINE_VISIBILITY
1164bool
Howard Hinnant300c67a2012-04-11 20:14:211165atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081166{
Howard Hinnant91e2f262010-12-07 20:46:141167 return __o->is_lock_free();
Howard Hinnant4777bf22010-12-06 23:10:081168}
1169
1170template <class _Tp>
1171inline _LIBCPP_INLINE_VISIBILITY
1172bool
Howard Hinnant300c67a2012-04-11 20:14:211173atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081174{
Howard Hinnant91e2f262010-12-07 20:46:141175 return __o->is_lock_free();
Howard Hinnant4777bf22010-12-06 23:10:081176}
1177
1178// atomic_init
1179
1180template <class _Tp>
1181inline _LIBCPP_INLINE_VISIBILITY
1182void
Howard Hinnant300c67a2012-04-11 20:14:211183atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081184{
Richard Smith6186c7f2012-04-11 18:55:461185 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant4777bf22010-12-06 23:10:081186}
1187
1188template <class _Tp>
1189inline _LIBCPP_INLINE_VISIBILITY
1190void
Howard Hinnant300c67a2012-04-11 20:14:211191atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081192{
Richard Smith6186c7f2012-04-11 18:55:461193 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant4777bf22010-12-06 23:10:081194}
1195
1196// atomic_store
1197
1198template <class _Tp>
1199inline _LIBCPP_INLINE_VISIBILITY
1200void
Howard Hinnant300c67a2012-04-11 20:14:211201atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081202{
Howard Hinnant91e2f262010-12-07 20:46:141203 __o->store(__d);
Howard Hinnant4777bf22010-12-06 23:10:081204}
1205
1206template <class _Tp>
1207inline _LIBCPP_INLINE_VISIBILITY
1208void
Howard Hinnant300c67a2012-04-11 20:14:211209atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081210{
Howard Hinnant91e2f262010-12-07 20:46:141211 __o->store(__d);
Howard Hinnant4777bf22010-12-06 23:10:081212}
1213
1214// atomic_store_explicit
1215
1216template <class _Tp>
1217inline _LIBCPP_INLINE_VISIBILITY
1218void
Howard Hinnant300c67a2012-04-11 20:14:211219atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391220 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081221{
Howard Hinnant91e2f262010-12-07 20:46:141222 __o->store(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081223}
1224
1225template <class _Tp>
1226inline _LIBCPP_INLINE_VISIBILITY
1227void
Howard Hinnant300c67a2012-04-11 20:14:211228atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391229 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081230{
Howard Hinnant91e2f262010-12-07 20:46:141231 __o->store(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081232}
1233
1234// atomic_load
1235
1236template <class _Tp>
1237inline _LIBCPP_INLINE_VISIBILITY
1238_Tp
Howard Hinnant300c67a2012-04-11 20:14:211239atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081240{
Howard Hinnant91e2f262010-12-07 20:46:141241 return __o->load();
Howard Hinnant4777bf22010-12-06 23:10:081242}
1243
1244template <class _Tp>
1245inline _LIBCPP_INLINE_VISIBILITY
1246_Tp
Howard Hinnant300c67a2012-04-11 20:14:211247atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081248{
Howard Hinnant91e2f262010-12-07 20:46:141249 return __o->load();
Howard Hinnant4777bf22010-12-06 23:10:081250}
1251
1252// atomic_load_explicit
1253
1254template <class _Tp>
1255inline _LIBCPP_INLINE_VISIBILITY
1256_Tp
Howard Hinnant300c67a2012-04-11 20:14:211257atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391258 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081259{
Howard Hinnant91e2f262010-12-07 20:46:141260 return __o->load(__m);
Howard Hinnant4777bf22010-12-06 23:10:081261}
1262
1263template <class _Tp>
1264inline _LIBCPP_INLINE_VISIBILITY
1265_Tp
Howard Hinnant300c67a2012-04-11 20:14:211266atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391267 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081268{
Howard Hinnant91e2f262010-12-07 20:46:141269 return __o->load(__m);
Howard Hinnant4777bf22010-12-06 23:10:081270}
1271
1272// atomic_exchange
1273
1274template <class _Tp>
1275inline _LIBCPP_INLINE_VISIBILITY
1276_Tp
Howard Hinnant300c67a2012-04-11 20:14:211277atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081278{
Howard Hinnant91e2f262010-12-07 20:46:141279 return __o->exchange(__d);
Howard Hinnant4777bf22010-12-06 23:10:081280}
1281
1282template <class _Tp>
1283inline _LIBCPP_INLINE_VISIBILITY
1284_Tp
Howard Hinnant300c67a2012-04-11 20:14:211285atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081286{
Howard Hinnant91e2f262010-12-07 20:46:141287 return __o->exchange(__d);
Howard Hinnant4777bf22010-12-06 23:10:081288}
1289
1290// atomic_exchange_explicit
1291
1292template <class _Tp>
1293inline _LIBCPP_INLINE_VISIBILITY
1294_Tp
Howard Hinnant300c67a2012-04-11 20:14:211295atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081296{
Howard Hinnant91e2f262010-12-07 20:46:141297 return __o->exchange(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081298}
1299
1300template <class _Tp>
1301inline _LIBCPP_INLINE_VISIBILITY
1302_Tp
Howard Hinnant300c67a2012-04-11 20:14:211303atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081304{
Howard Hinnant91e2f262010-12-07 20:46:141305 return __o->exchange(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081306}
1307
1308// atomic_compare_exchange_weak
1309
1310template <class _Tp>
1311inline _LIBCPP_INLINE_VISIBILITY
1312bool
Howard Hinnant300c67a2012-04-11 20:14:211313atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081314{
Howard Hinnant91e2f262010-12-07 20:46:141315 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081316}
1317
1318template <class _Tp>
1319inline _LIBCPP_INLINE_VISIBILITY
1320bool
Howard Hinnant300c67a2012-04-11 20:14:211321atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081322{
Howard Hinnant91e2f262010-12-07 20:46:141323 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081324}
1325
1326// atomic_compare_exchange_strong
1327
1328template <class _Tp>
1329inline _LIBCPP_INLINE_VISIBILITY
1330bool
Howard Hinnant300c67a2012-04-11 20:14:211331atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081332{
Howard Hinnant91e2f262010-12-07 20:46:141333 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081334}
1335
1336template <class _Tp>
1337inline _LIBCPP_INLINE_VISIBILITY
1338bool
Howard Hinnant300c67a2012-04-11 20:14:211339atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081340{
Howard Hinnant91e2f262010-12-07 20:46:141341 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081342}
1343
1344// atomic_compare_exchange_weak_explicit
1345
1346template <class _Tp>
1347inline _LIBCPP_INLINE_VISIBILITY
1348bool
1349atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
1350 _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211351 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391352 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081353{
Howard Hinnant91e2f262010-12-07 20:46:141354 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081355}
1356
1357template <class _Tp>
1358inline _LIBCPP_INLINE_VISIBILITY
1359bool
1360atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211361 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391362 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081363{
Howard Hinnant91e2f262010-12-07 20:46:141364 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081365}
1366
1367// atomic_compare_exchange_strong_explicit
1368
1369template <class _Tp>
1370inline _LIBCPP_INLINE_VISIBILITY
1371bool
1372atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
1373 _Tp* __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211374 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391375 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081376{
Howard Hinnant91e2f262010-12-07 20:46:141377 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081378}
1379
1380template <class _Tp>
1381inline _LIBCPP_INLINE_VISIBILITY
1382bool
1383atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
1384 _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211385 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391386 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081387{
Howard Hinnant91e2f262010-12-07 20:46:141388 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081389}
1390
Howard Hinnant91e2f262010-12-07 20:46:141391// atomic_fetch_add
Howard Hinnant4777bf22010-12-06 23:10:081392
1393template <class _Tp>
Howard Hinnant91e2f262010-12-07 20:46:141394inline _LIBCPP_INLINE_VISIBILITY
1395typename enable_if
1396<
1397 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1398 _Tp
1399>::type
Howard Hinnant300c67a2012-04-11 20:14:211400atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081401{
Howard Hinnant91e2f262010-12-07 20:46:141402 return __o->fetch_add(__op);
1403}
Howard Hinnant4777bf22010-12-06 23:10:081404
Howard Hinnant91e2f262010-12-07 20:46:141405template <class _Tp>
1406inline _LIBCPP_INLINE_VISIBILITY
1407typename enable_if
1408<
1409 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1410 _Tp
1411>::type
Howard Hinnant300c67a2012-04-11 20:14:211412atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141413{
1414 return __o->fetch_add(__op);
1415}
Howard Hinnant4777bf22010-12-06 23:10:081416
Howard Hinnant91e2f262010-12-07 20:46:141417template <class _Tp>
1418inline _LIBCPP_INLINE_VISIBILITY
1419_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211420atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141421{
1422 return __o->fetch_add(__op);
1423}
1424
1425template <class _Tp>
1426inline _LIBCPP_INLINE_VISIBILITY
1427_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211428atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141429{
1430 return __o->fetch_add(__op);
1431}
1432
1433// atomic_fetch_add_explicit
1434
1435template <class _Tp>
1436inline _LIBCPP_INLINE_VISIBILITY
1437typename enable_if
1438<
1439 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1440 _Tp
1441>::type
Howard Hinnant300c67a2012-04-11 20:14:211442atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141443{
1444 return __o->fetch_add(__op, __m);
1445}
1446
1447template <class _Tp>
1448inline _LIBCPP_INLINE_VISIBILITY
1449typename enable_if
1450<
1451 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1452 _Tp
1453>::type
Howard Hinnant300c67a2012-04-11 20:14:211454atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141455{
1456 return __o->fetch_add(__op, __m);
1457}
1458
1459template <class _Tp>
1460inline _LIBCPP_INLINE_VISIBILITY
1461_Tp*
1462atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnant300c67a2012-04-11 20:14:211463 memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141464{
1465 return __o->fetch_add(__op, __m);
1466}
1467
1468template <class _Tp>
1469inline _LIBCPP_INLINE_VISIBILITY
1470_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211471atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141472{
1473 return __o->fetch_add(__op, __m);
1474}
1475
1476// atomic_fetch_sub
1477
1478template <class _Tp>
1479inline _LIBCPP_INLINE_VISIBILITY
1480typename enable_if
1481<
1482 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1483 _Tp
1484>::type
Howard Hinnant300c67a2012-04-11 20:14:211485atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141486{
1487 return __o->fetch_sub(__op);
1488}
1489
1490template <class _Tp>
1491inline _LIBCPP_INLINE_VISIBILITY
1492typename enable_if
1493<
1494 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1495 _Tp
1496>::type
Howard Hinnant300c67a2012-04-11 20:14:211497atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141498{
1499 return __o->fetch_sub(__op);
1500}
1501
1502template <class _Tp>
1503inline _LIBCPP_INLINE_VISIBILITY
1504_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211505atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141506{
1507 return __o->fetch_sub(__op);
1508}
1509
1510template <class _Tp>
1511inline _LIBCPP_INLINE_VISIBILITY
1512_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211513atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141514{
1515 return __o->fetch_sub(__op);
1516}
1517
1518// atomic_fetch_sub_explicit
1519
1520template <class _Tp>
1521inline _LIBCPP_INLINE_VISIBILITY
1522typename enable_if
1523<
1524 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1525 _Tp
1526>::type
Howard Hinnant300c67a2012-04-11 20:14:211527atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141528{
1529 return __o->fetch_sub(__op, __m);
1530}
1531
1532template <class _Tp>
1533inline _LIBCPP_INLINE_VISIBILITY
1534typename enable_if
1535<
1536 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1537 _Tp
1538>::type
Howard Hinnant300c67a2012-04-11 20:14:211539atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141540{
1541 return __o->fetch_sub(__op, __m);
1542}
1543
1544template <class _Tp>
1545inline _LIBCPP_INLINE_VISIBILITY
1546_Tp*
1547atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnant300c67a2012-04-11 20:14:211548 memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141549{
1550 return __o->fetch_sub(__op, __m);
1551}
1552
1553template <class _Tp>
1554inline _LIBCPP_INLINE_VISIBILITY
1555_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211556atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141557{
1558 return __o->fetch_sub(__op, __m);
1559}
1560
1561// atomic_fetch_and
1562
1563template <class _Tp>
1564inline _LIBCPP_INLINE_VISIBILITY
1565typename enable_if
1566<
1567 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1568 _Tp
1569>::type
Howard Hinnant300c67a2012-04-11 20:14:211570atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141571{
1572 return __o->fetch_and(__op);
1573}
1574
1575template <class _Tp>
1576inline _LIBCPP_INLINE_VISIBILITY
1577typename enable_if
1578<
1579 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1580 _Tp
1581>::type
Howard Hinnant300c67a2012-04-11 20:14:211582atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141583{
1584 return __o->fetch_and(__op);
1585}
1586
1587// atomic_fetch_and_explicit
1588
1589template <class _Tp>
1590inline _LIBCPP_INLINE_VISIBILITY
1591typename enable_if
1592<
1593 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1594 _Tp
1595>::type
Howard Hinnant300c67a2012-04-11 20:14:211596atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141597{
1598 return __o->fetch_and(__op, __m);
1599}
1600
1601template <class _Tp>
1602inline _LIBCPP_INLINE_VISIBILITY
1603typename enable_if
1604<
1605 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1606 _Tp
1607>::type
Howard Hinnant300c67a2012-04-11 20:14:211608atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141609{
1610 return __o->fetch_and(__op, __m);
1611}
1612
1613// atomic_fetch_or
1614
1615template <class _Tp>
1616inline _LIBCPP_INLINE_VISIBILITY
1617typename enable_if
1618<
1619 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1620 _Tp
1621>::type
Howard Hinnant300c67a2012-04-11 20:14:211622atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141623{
1624 return __o->fetch_or(__op);
1625}
1626
1627template <class _Tp>
1628inline _LIBCPP_INLINE_VISIBILITY
1629typename enable_if
1630<
1631 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1632 _Tp
1633>::type
Howard Hinnant300c67a2012-04-11 20:14:211634atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141635{
1636 return __o->fetch_or(__op);
1637}
1638
1639// atomic_fetch_or_explicit
1640
1641template <class _Tp>
1642inline _LIBCPP_INLINE_VISIBILITY
1643typename enable_if
1644<
1645 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1646 _Tp
1647>::type
Howard Hinnant300c67a2012-04-11 20:14:211648atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141649{
1650 return __o->fetch_or(__op, __m);
1651}
1652
1653template <class _Tp>
1654inline _LIBCPP_INLINE_VISIBILITY
1655typename enable_if
1656<
1657 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1658 _Tp
1659>::type
Howard Hinnant300c67a2012-04-11 20:14:211660atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141661{
1662 return __o->fetch_or(__op, __m);
1663}
1664
1665// atomic_fetch_xor
1666
1667template <class _Tp>
1668inline _LIBCPP_INLINE_VISIBILITY
1669typename enable_if
1670<
1671 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1672 _Tp
1673>::type
Howard Hinnant300c67a2012-04-11 20:14:211674atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141675{
1676 return __o->fetch_xor(__op);
1677}
1678
1679template <class _Tp>
1680inline _LIBCPP_INLINE_VISIBILITY
1681typename enable_if
1682<
1683 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1684 _Tp
1685>::type
Howard Hinnant300c67a2012-04-11 20:14:211686atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141687{
1688 return __o->fetch_xor(__op);
1689}
1690
1691// atomic_fetch_xor_explicit
1692
1693template <class _Tp>
1694inline _LIBCPP_INLINE_VISIBILITY
1695typename enable_if
1696<
1697 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1698 _Tp
1699>::type
Howard Hinnant300c67a2012-04-11 20:14:211700atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141701{
1702 return __o->fetch_xor(__op, __m);
1703}
1704
1705template <class _Tp>
1706inline _LIBCPP_INLINE_VISIBILITY
1707typename enable_if
1708<
1709 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1710 _Tp
1711>::type
Howard Hinnant300c67a2012-04-11 20:14:211712atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141713{
1714 return __o->fetch_xor(__op, __m);
1715}
Howard Hinnant4777bf22010-12-06 23:10:081716
Howard Hinnant770d1c42010-12-08 17:20:281717// flag type and operations
1718
1719typedef struct atomic_flag
1720{
David Chisnall83b2c842011-12-19 11:44:201721 _Atomic(bool) __a_;
Howard Hinnant770d1c42010-12-08 17:20:281722
1723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211724 bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461725 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211727 bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461728 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281729 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211730 void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461731 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211733 void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461734 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281735
1736 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8c570322016-11-18 06:42:171737#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:431738 atomic_flag() _NOEXCEPT = default;
1739#else
1740 atomic_flag() _NOEXCEPT : __a_() {}
Eric Fiselier8c570322016-11-18 06:42:171741#endif // _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:431742
Marshall Clow727ed612018-04-25 14:27:291743 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Eric Fiselier219406e2016-05-03 02:12:261744 atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
Howard Hinnant770d1c42010-12-08 17:20:281745
Eric Fiselier8eb066a2017-01-06 20:58:251746#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant770d1c42010-12-08 17:20:281747 atomic_flag(const atomic_flag&) = delete;
1748 atomic_flag& operator=(const atomic_flag&) = delete;
1749 atomic_flag& operator=(const atomic_flag&) volatile = delete;
Eric Fiselier8eb066a2017-01-06 20:58:251750#else
Howard Hinnant770d1c42010-12-08 17:20:281751private:
1752 atomic_flag(const atomic_flag&);
1753 atomic_flag& operator=(const atomic_flag&);
1754 atomic_flag& operator=(const atomic_flag&) volatile;
Eric Fiselier8eb066a2017-01-06 20:58:251755#endif
Howard Hinnant770d1c42010-12-08 17:20:281756} atomic_flag;
1757
1758inline _LIBCPP_INLINE_VISIBILITY
1759bool
Howard Hinnant300c67a2012-04-11 20:14:211760atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281761{
1762 return __o->test_and_set();
1763}
1764
1765inline _LIBCPP_INLINE_VISIBILITY
1766bool
Howard Hinnant300c67a2012-04-11 20:14:211767atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281768{
1769 return __o->test_and_set();
1770}
1771
1772inline _LIBCPP_INLINE_VISIBILITY
1773bool
Howard Hinnant300c67a2012-04-11 20:14:211774atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281775{
1776 return __o->test_and_set(__m);
1777}
1778
1779inline _LIBCPP_INLINE_VISIBILITY
1780bool
Howard Hinnant300c67a2012-04-11 20:14:211781atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281782{
1783 return __o->test_and_set(__m);
1784}
1785
1786inline _LIBCPP_INLINE_VISIBILITY
1787void
Howard Hinnant300c67a2012-04-11 20:14:211788atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281789{
1790 __o->clear();
1791}
1792
1793inline _LIBCPP_INLINE_VISIBILITY
1794void
Howard Hinnant300c67a2012-04-11 20:14:211795atomic_flag_clear(atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281796{
1797 __o->clear();
1798}
1799
1800inline _LIBCPP_INLINE_VISIBILITY
1801void
Howard Hinnant300c67a2012-04-11 20:14:211802atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281803{
1804 __o->clear(__m);
1805}
1806
1807inline _LIBCPP_INLINE_VISIBILITY
1808void
Howard Hinnant300c67a2012-04-11 20:14:211809atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281810{
1811 __o->clear(__m);
1812}
1813
1814// fences
1815
1816inline _LIBCPP_INLINE_VISIBILITY
1817void
Howard Hinnant300c67a2012-04-11 20:14:211818atomic_thread_fence(memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281819{
Richard Smith6186c7f2012-04-11 18:55:461820 __c11_atomic_thread_fence(__m);
Howard Hinnant770d1c42010-12-08 17:20:281821}
1822
1823inline _LIBCPP_INLINE_VISIBILITY
1824void
Howard Hinnant300c67a2012-04-11 20:14:211825atomic_signal_fence(memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281826{
Richard Smith6186c7f2012-04-11 18:55:461827 __c11_atomic_signal_fence(__m);
Howard Hinnant770d1c42010-12-08 17:20:281828}
1829
Howard Hinnantd2f6afb2010-12-07 23:24:411830// Atomics for standard typedef types
1831
Howard Hinnant6ae47052013-01-04 18:58:501832typedef atomic<bool> atomic_bool;
Howard Hinnantd2f6afb2010-12-07 23:24:411833typedef atomic<char> atomic_char;
1834typedef atomic<signed char> atomic_schar;
1835typedef atomic<unsigned char> atomic_uchar;
1836typedef atomic<short> atomic_short;
1837typedef atomic<unsigned short> atomic_ushort;
1838typedef atomic<int> atomic_int;
1839typedef atomic<unsigned int> atomic_uint;
1840typedef atomic<long> atomic_long;
1841typedef atomic<unsigned long> atomic_ulong;
1842typedef atomic<long long> atomic_llong;
1843typedef atomic<unsigned long long> atomic_ullong;
1844typedef atomic<char16_t> atomic_char16_t;
1845typedef atomic<char32_t> atomic_char32_t;
1846typedef atomic<wchar_t> atomic_wchar_t;
1847
1848typedef atomic<int_least8_t> atomic_int_least8_t;
1849typedef atomic<uint_least8_t> atomic_uint_least8_t;
1850typedef atomic<int_least16_t> atomic_int_least16_t;
1851typedef atomic<uint_least16_t> atomic_uint_least16_t;
1852typedef atomic<int_least32_t> atomic_int_least32_t;
1853typedef atomic<uint_least32_t> atomic_uint_least32_t;
1854typedef atomic<int_least64_t> atomic_int_least64_t;
1855typedef atomic<uint_least64_t> atomic_uint_least64_t;
1856
1857typedef atomic<int_fast8_t> atomic_int_fast8_t;
1858typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
1859typedef atomic<int_fast16_t> atomic_int_fast16_t;
1860typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1861typedef atomic<int_fast32_t> atomic_int_fast32_t;
1862typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1863typedef atomic<int_fast64_t> atomic_int_fast64_t;
1864typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1865
Marshall Clowca894502016-06-30 15:28:381866typedef atomic< int8_t> atomic_int8_t;
1867typedef atomic<uint8_t> atomic_uint8_t;
1868typedef atomic< int16_t> atomic_int16_t;
1869typedef atomic<uint16_t> atomic_uint16_t;
1870typedef atomic< int32_t> atomic_int32_t;
1871typedef atomic<uint32_t> atomic_uint32_t;
1872typedef atomic< int64_t> atomic_int64_t;
1873typedef atomic<uint64_t> atomic_uint64_t;
1874
Howard Hinnantd2f6afb2010-12-07 23:24:411875typedef atomic<intptr_t> atomic_intptr_t;
1876typedef atomic<uintptr_t> atomic_uintptr_t;
1877typedef atomic<size_t> atomic_size_t;
1878typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1879typedef atomic<intmax_t> atomic_intmax_t;
1880typedef atomic<uintmax_t> atomic_uintmax_t;
1881
Howard Hinnant767ae2b2010-09-29 21:20:031882#define ATOMIC_FLAG_INIT {false}
Howard Hinnant611fdaf2010-10-04 18:52:541883#define ATOMIC_VAR_INIT(__v) {__v}
1884
Howard Hinnant8f73c632010-09-27 21:17:381885_LIBCPP_END_NAMESPACE_STD
1886
Howard Hinnant8f73c632010-09-27 21:17:381887#endif // _LIBCPP_ATOMIC