blob: dfca76b1626cbaaa8199b30110a6655a384a3ec4 [file] [log] [blame]
Howard Hinnant8f73c632010-09-27 21:17:381// -*- C++ -*-
2//===--------------------------- atomic -----------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_ATOMIC
12#define _LIBCPP_ATOMIC
13
14/*
15 atomic synopsis
16
17namespace std
18{
19
JF Bastien08511cd2016-03-25 15:48:2120// feature test macro
21
22#define __cpp_lib_atomic_is_always_lock_free // as specified by SG10
23
Howard Hinnant8f73c632010-09-27 21:17:3824// order and consistency
25
26typedef enum memory_order
27{
Howard Hinnantd1176e22010-09-28 17:13:3828 memory_order_relaxed,
29 memory_order_consume, // load-consume
30 memory_order_acquire, // load-acquire
31 memory_order_release, // store-release
32 memory_order_acq_rel, // store-release load-acquire
33 memory_order_seq_cst // store-release load-acquire
Howard Hinnant8f73c632010-09-27 21:17:3834} memory_order;
35
Howard Hinnant300c67a2012-04-11 20:14:2136template <class T> T kill_dependency(T y) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:3837
38// lock-free property
39
Howard Hinnant7b9d6a82013-01-21 20:39:4140#define ATOMIC_BOOL_LOCK_FREE unspecified
Howard Hinnant8f73c632010-09-27 21:17:3841#define ATOMIC_CHAR_LOCK_FREE unspecified
42#define ATOMIC_CHAR16_T_LOCK_FREE unspecified
43#define ATOMIC_CHAR32_T_LOCK_FREE unspecified
44#define ATOMIC_WCHAR_T_LOCK_FREE unspecified
45#define ATOMIC_SHORT_LOCK_FREE unspecified
46#define ATOMIC_INT_LOCK_FREE unspecified
47#define ATOMIC_LONG_LOCK_FREE unspecified
48#define ATOMIC_LLONG_LOCK_FREE unspecified
Howard Hinnant7b9d6a82013-01-21 20:39:4149#define ATOMIC_POINTER_LOCK_FREE unspecified
Howard Hinnant8f73c632010-09-27 21:17:3850
Howard Hinnant8f73c632010-09-27 21:17:3851// flag type and operations
52
53typedef struct atomic_flag
54{
Howard Hinnant300c67a2012-04-11 20:14:2155 bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
56 bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
57 void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
58 void clear(memory_order m = memory_order_seq_cst) noexcept;
59 atomic_flag() noexcept = default;
Howard Hinnant8f73c632010-09-27 21:17:3860 atomic_flag(const atomic_flag&) = delete;
61 atomic_flag& operator=(const atomic_flag&) = delete;
62 atomic_flag& operator=(const atomic_flag&) volatile = delete;
63} atomic_flag;
64
Howard Hinnant4777bf22010-12-06 23:10:0865bool
Howard Hinnant300c67a2012-04-11 20:14:2166 atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0867
68bool
Howard Hinnant300c67a2012-04-11 20:14:2169 atomic_flag_test_and_set(atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0870
71bool
72 atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
Howard Hinnant300c67a2012-04-11 20:14:2173 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0874
75bool
Howard Hinnant300c67a2012-04-11 20:14:2176 atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0877
78void
Howard Hinnant300c67a2012-04-11 20:14:2179 atomic_flag_clear(volatile atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0880
81void
Howard Hinnant300c67a2012-04-11 20:14:2182 atomic_flag_clear(atomic_flag* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0883
84void
Howard Hinnant300c67a2012-04-11 20:14:2185 atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:0886
87void
Howard Hinnant300c67a2012-04-11 20:14:2188 atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:3889
90#define ATOMIC_FLAG_INIT see below
Howard Hinnante7385012010-10-19 16:51:1891#define ATOMIC_VAR_INIT(value) see below
Howard Hinnant8f73c632010-09-27 21:17:3892
Howard Hinnant8f73c632010-09-27 21:17:3893template <class T>
94struct atomic
95{
JF Bastien08511cd2016-03-25 15:48:2196 static constexpr bool is_always_lock_free;
Howard Hinnant300c67a2012-04-11 20:14:2197 bool is_lock_free() const volatile noexcept;
98 bool is_lock_free() const noexcept;
99 void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
100 void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
101 T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
102 T load(memory_order m = memory_order_seq_cst) const noexcept;
103 operator T() const volatile noexcept;
104 operator T() const noexcept;
105 T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
106 T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08107 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21108 memory_order s, memory_order f) volatile noexcept;
109 bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08110 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21111 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08112 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21113 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08114 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21115 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08116 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21117 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08118 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21119 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08120 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21121 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38122
Howard Hinnant300c67a2012-04-11 20:14:21123 atomic() noexcept = default;
124 constexpr atomic(T desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38125 atomic(const atomic&) = delete;
126 atomic& operator=(const atomic&) = delete;
127 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnant300c67a2012-04-11 20:14:21128 T operator=(T) volatile noexcept;
129 T operator=(T) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38130};
131
132template <>
Howard Hinnant4777bf22010-12-06 23:10:08133struct atomic<integral>
Howard Hinnant8f73c632010-09-27 21:17:38134{
JF Bastien08511cd2016-03-25 15:48:21135 static constexpr bool is_always_lock_free;
Howard Hinnant300c67a2012-04-11 20:14:21136 bool is_lock_free() const volatile noexcept;
137 bool is_lock_free() const noexcept;
138 void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
139 void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
140 integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
141 integral load(memory_order m = memory_order_seq_cst) const noexcept;
142 operator integral() const volatile noexcept;
143 operator integral() const noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08144 integral exchange(integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21145 memory_order m = memory_order_seq_cst) volatile noexcept;
146 integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08147 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21148 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08149 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21150 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08151 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21152 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08153 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21154 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08155 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21156 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08157 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21158 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08159 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21160 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08161 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnant300c67a2012-04-11 20:14:21162 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38163
Howard Hinnant4777bf22010-12-06 23:10:08164 integral
Howard Hinnant300c67a2012-04-11 20:14:21165 fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
166 integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08167 integral
Howard Hinnant300c67a2012-04-11 20:14:21168 fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
169 integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08170 integral
Howard Hinnant300c67a2012-04-11 20:14:21171 fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
172 integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08173 integral
Howard Hinnant300c67a2012-04-11 20:14:21174 fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
175 integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08176 integral
Howard Hinnant300c67a2012-04-11 20:14:21177 fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
178 integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38179
Howard Hinnant300c67a2012-04-11 20:14:21180 atomic() noexcept = default;
181 constexpr atomic(integral desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38182 atomic(const atomic&) = delete;
183 atomic& operator=(const atomic&) = delete;
184 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnant300c67a2012-04-11 20:14:21185 integral operator=(integral desr) volatile noexcept;
186 integral operator=(integral desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38187
Howard Hinnant300c67a2012-04-11 20:14:21188 integral operator++(int) volatile noexcept;
189 integral operator++(int) noexcept;
190 integral operator--(int) volatile noexcept;
191 integral operator--(int) noexcept;
192 integral operator++() volatile noexcept;
193 integral operator++() noexcept;
194 integral operator--() volatile noexcept;
195 integral operator--() noexcept;
196 integral operator+=(integral op) volatile noexcept;
197 integral operator+=(integral op) noexcept;
198 integral operator-=(integral op) volatile noexcept;
199 integral operator-=(integral op) noexcept;
200 integral operator&=(integral op) volatile noexcept;
201 integral operator&=(integral op) noexcept;
202 integral operator|=(integral op) volatile noexcept;
203 integral operator|=(integral op) noexcept;
204 integral operator^=(integral op) volatile noexcept;
205 integral operator^=(integral op) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38206};
207
208template <class T>
209struct atomic<T*>
Howard Hinnant8f73c632010-09-27 21:17:38210{
JF Bastien08511cd2016-03-25 15:48:21211 static constexpr bool is_always_lock_free;
Howard Hinnant300c67a2012-04-11 20:14:21212 bool is_lock_free() const volatile noexcept;
213 bool is_lock_free() const noexcept;
214 void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
215 void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
216 T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
217 T* load(memory_order m = memory_order_seq_cst) const noexcept;
218 operator T*() const volatile noexcept;
219 operator T*() const noexcept;
220 T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
221 T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08222 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21223 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08224 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21225 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08226 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21227 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08228 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21229 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08230 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21231 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08232 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21233 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08234 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21235 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08236 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnant300c67a2012-04-11 20:14:21237 memory_order m = memory_order_seq_cst) noexcept;
238 T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
239 T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
240 T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
241 T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08242
Howard Hinnant300c67a2012-04-11 20:14:21243 atomic() noexcept = default;
244 constexpr atomic(T* desr) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38245 atomic(const atomic&) = delete;
246 atomic& operator=(const atomic&) = delete;
247 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnant4777bf22010-12-06 23:10:08248
Howard Hinnant300c67a2012-04-11 20:14:21249 T* operator=(T*) volatile noexcept;
250 T* operator=(T*) noexcept;
251 T* operator++(int) volatile noexcept;
252 T* operator++(int) noexcept;
253 T* operator--(int) volatile noexcept;
254 T* operator--(int) noexcept;
255 T* operator++() volatile noexcept;
256 T* operator++() noexcept;
257 T* operator--() volatile noexcept;
258 T* operator--() noexcept;
259 T* operator+=(ptrdiff_t op) volatile noexcept;
260 T* operator+=(ptrdiff_t op) noexcept;
261 T* operator-=(ptrdiff_t op) volatile noexcept;
262 T* operator-=(ptrdiff_t op) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38263};
264
Howard Hinnant4777bf22010-12-06 23:10:08265
266template <class T>
267 bool
Howard Hinnant300c67a2012-04-11 20:14:21268 atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08269
270template <class T>
271 bool
Howard Hinnant300c67a2012-04-11 20:14:21272 atomic_is_lock_free(const atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08273
274template <class T>
275 void
Howard Hinnant300c67a2012-04-11 20:14:21276 atomic_init(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08277
278template <class T>
279 void
Howard Hinnant300c67a2012-04-11 20:14:21280 atomic_init(atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08281
282template <class T>
283 void
Howard Hinnant300c67a2012-04-11 20:14:21284 atomic_store(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08285
286template <class T>
287 void
Howard Hinnant300c67a2012-04-11 20:14:21288 atomic_store(atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08289
290template <class T>
291 void
Howard Hinnant300c67a2012-04-11 20:14:21292 atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08293
294template <class T>
295 void
Howard Hinnant300c67a2012-04-11 20:14:21296 atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08297
298template <class T>
299 T
Howard Hinnant300c67a2012-04-11 20:14:21300 atomic_load(const volatile atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08301
302template <class T>
303 T
Howard Hinnant300c67a2012-04-11 20:14:21304 atomic_load(const atomic<T>* obj) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08305
306template <class T>
307 T
Howard Hinnant300c67a2012-04-11 20:14:21308 atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08309
310template <class T>
311 T
Howard Hinnant300c67a2012-04-11 20:14:21312 atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08313
314template <class T>
315 T
Howard Hinnant300c67a2012-04-11 20:14:21316 atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08317
318template <class T>
319 T
Howard Hinnant300c67a2012-04-11 20:14:21320 atomic_exchange(atomic<T>* obj, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08321
322template <class T>
323 T
Howard Hinnant300c67a2012-04-11 20:14:21324 atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08325
326template <class T>
327 T
Howard Hinnant300c67a2012-04-11 20:14:21328 atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08329
330template <class T>
331 bool
Howard Hinnant300c67a2012-04-11 20:14:21332 atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08333
334template <class T>
335 bool
Howard Hinnant300c67a2012-04-11 20:14:21336 atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08337
338template <class T>
339 bool
Howard Hinnant300c67a2012-04-11 20:14:21340 atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08341
342template <class T>
343 bool
Howard Hinnant300c67a2012-04-11 20:14:21344 atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08345
346template <class T>
347 bool
348 atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
349 T desr,
Howard Hinnant300c67a2012-04-11 20:14:21350 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08351
352template <class T>
353 bool
354 atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21355 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08356
357template <class T>
358 bool
359 atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
360 T* expc, T desr,
Howard Hinnant300c67a2012-04-11 20:14:21361 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08362
363template <class T>
364 bool
365 atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
366 T desr,
Howard Hinnant300c67a2012-04-11 20:14:21367 memory_order s, memory_order f) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08368
369template <class Integral>
370 Integral
Howard Hinnant300c67a2012-04-11 20:14:21371 atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08372
373template <class Integral>
374 Integral
Howard Hinnant300c67a2012-04-11 20:14:21375 atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08376
377template <class Integral>
378 Integral
379 atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21380 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08381template <class Integral>
382 Integral
383 atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21384 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08385template <class Integral>
386 Integral
Howard Hinnant300c67a2012-04-11 20:14:21387 atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08388
389template <class Integral>
390 Integral
Howard Hinnant300c67a2012-04-11 20:14:21391 atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08392
393template <class Integral>
394 Integral
395 atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21396 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08397template <class Integral>
398 Integral
399 atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21400 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08401template <class Integral>
402 Integral
Howard Hinnant300c67a2012-04-11 20:14:21403 atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08404
405template <class Integral>
406 Integral
Howard Hinnant300c67a2012-04-11 20:14:21407 atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08408
409template <class Integral>
410 Integral
411 atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21412 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08413template <class Integral>
414 Integral
415 atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21416 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08417template <class Integral>
418 Integral
Howard Hinnant300c67a2012-04-11 20:14:21419 atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08420
421template <class Integral>
422 Integral
Howard Hinnant300c67a2012-04-11 20:14:21423 atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08424
425template <class Integral>
426 Integral
427 atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21428 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08429template <class Integral>
430 Integral
431 atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21432 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08433template <class Integral>
434 Integral
Howard Hinnant300c67a2012-04-11 20:14:21435 atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08436
437template <class Integral>
438 Integral
Howard Hinnant300c67a2012-04-11 20:14:21439 atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08440
441template <class Integral>
442 Integral
443 atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21444 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08445template <class Integral>
446 Integral
447 atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnant300c67a2012-04-11 20:14:21448 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08449
450template <class T>
451 T*
Howard Hinnant300c67a2012-04-11 20:14:21452 atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08453
454template <class T>
455 T*
Howard Hinnant300c67a2012-04-11 20:14:21456 atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08457
458template <class T>
459 T*
460 atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
Howard Hinnant300c67a2012-04-11 20:14:21461 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08462template <class T>
463 T*
Howard Hinnant300c67a2012-04-11 20:14:21464 atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08465
466template <class T>
467 T*
Howard Hinnant300c67a2012-04-11 20:14:21468 atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08469
470template <class T>
471 T*
Howard Hinnant300c67a2012-04-11 20:14:21472 atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08473
474template <class T>
475 T*
476 atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
Howard Hinnant300c67a2012-04-11 20:14:21477 memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08478template <class T>
479 T*
Howard Hinnant300c67a2012-04-11 20:14:21480 atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
Howard Hinnant4777bf22010-12-06 23:10:08481
482// Atomics for standard typedef types
483
Howard Hinnant6ae47052013-01-04 18:58:50484typedef atomic<bool> atomic_bool;
Howard Hinnant4777bf22010-12-06 23:10:08485typedef atomic<char> atomic_char;
486typedef atomic<signed char> atomic_schar;
487typedef atomic<unsigned char> atomic_uchar;
488typedef atomic<short> atomic_short;
489typedef atomic<unsigned short> atomic_ushort;
490typedef atomic<int> atomic_int;
491typedef atomic<unsigned int> atomic_uint;
492typedef atomic<long> atomic_long;
493typedef atomic<unsigned long> atomic_ulong;
494typedef atomic<long long> atomic_llong;
495typedef atomic<unsigned long long> atomic_ullong;
496typedef atomic<char16_t> atomic_char16_t;
497typedef atomic<char32_t> atomic_char32_t;
498typedef atomic<wchar_t> atomic_wchar_t;
499
500typedef atomic<int_least8_t> atomic_int_least8_t;
501typedef atomic<uint_least8_t> atomic_uint_least8_t;
502typedef atomic<int_least16_t> atomic_int_least16_t;
503typedef atomic<uint_least16_t> atomic_uint_least16_t;
504typedef atomic<int_least32_t> atomic_int_least32_t;
505typedef atomic<uint_least32_t> atomic_uint_least32_t;
506typedef atomic<int_least64_t> atomic_int_least64_t;
507typedef atomic<uint_least64_t> atomic_uint_least64_t;
508
509typedef atomic<int_fast8_t> atomic_int_fast8_t;
510typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
511typedef atomic<int_fast16_t> atomic_int_fast16_t;
512typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
513typedef atomic<int_fast32_t> atomic_int_fast32_t;
514typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
515typedef atomic<int_fast64_t> atomic_int_fast64_t;
516typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
517
Marshall Clowca894502016-06-30 15:28:38518typedef atomic<int8_t> atomic_int8_t;
519typedef atomic<uint8_t> atomic_uint8_t;
520typedef atomic<int16_t> atomic_int16_t;
521typedef atomic<uint16_t> atomic_uint16_t;
522typedef atomic<int32_t> atomic_int32_t;
523typedef atomic<uint32_t> atomic_uint32_t;
524typedef atomic<int64_t> atomic_int64_t;
525typedef atomic<uint64_t> atomic_uint64_t;
526
Howard Hinnant4777bf22010-12-06 23:10:08527typedef atomic<intptr_t> atomic_intptr_t;
528typedef atomic<uintptr_t> atomic_uintptr_t;
529typedef atomic<size_t> atomic_size_t;
530typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
531typedef atomic<intmax_t> atomic_intmax_t;
532typedef atomic<uintmax_t> atomic_uintmax_t;
533
Howard Hinnant8f73c632010-09-27 21:17:38534// fences
535
Howard Hinnant300c67a2012-04-11 20:14:21536void atomic_thread_fence(memory_order m) noexcept;
537void atomic_signal_fence(memory_order m) noexcept;
Howard Hinnant8f73c632010-09-27 21:17:38538
539} // std
540
541*/
542
543#include <__config>
Howard Hinnant4777bf22010-12-06 23:10:08544#include <cstddef>
545#include <cstdint>
546#include <type_traits>
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
JF Bastien08511cd2016-03-25 15:48:21562#if _LIBCPP_STD_VER > 14
JF Bastien08511cd2016-03-25 15:48:21563# define __cpp_lib_atomic_is_always_lock_free 201603L
564#endif
565
Eric Fiselier5ed76752017-01-13 23:45:39566#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
567 _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \
568 __m == memory_order_acquire || \
569 __m == memory_order_acq_rel, \
570 "memory order argument to atomic operation is invalid")
571
572#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
573 _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \
574 __m == memory_order_acq_rel, \
575 "memory order argument to atomic operation is invalid")
576
577#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
578 _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \
579 __f == memory_order_acq_rel, \
580 "memory order argument to atomic operation is invalid")
581
Howard Hinnant8f73c632010-09-27 21:17:38582_LIBCPP_BEGIN_NAMESPACE_STD
583
Howard Hinnantd1176e22010-09-28 17:13:38584typedef enum memory_order
585{
586 memory_order_relaxed, memory_order_consume, memory_order_acquire,
587 memory_order_release, memory_order_acq_rel, memory_order_seq_cst
588} memory_order;
589
Eric Fiselier00f4a492015-08-19 17:21:46590#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
Dan Alberte8b42322014-08-09 23:51:51591namespace __gcc_atomic {
Marshall Clowe4220212015-01-11 06:15:59592template <typename _Tp>
Dan Alberte8b42322014-08-09 23:51:51593struct __gcc_atomic_t {
Eric Fiseliere39f4b92015-12-15 00:32:21594
595#if _GNUC_VER >= 501
596 static_assert(is_trivially_copyable<_Tp>::value,
597 "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
598#endif
599
Eric Fiseliera4ae16b2015-10-14 08:36:22600 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8c570322016-11-18 06:42:17601#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera4ae16b2015-10-14 08:36:22602 __gcc_atomic_t() _NOEXCEPT = default;
603#else
604 __gcc_atomic_t() _NOEXCEPT : __a_value() {}
Eric Fiselier8c570322016-11-18 06:42:17605#endif // _LIBCPP_CXX03_LANG
Eric Fiselier26edd802015-07-14 17:50:27606 _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT
607 : __a_value(value) {}
Marshall Clowe4220212015-01-11 06:15:59608 _Tp __a_value;
Dan Alberte8b42322014-08-09 23:51:51609};
610#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>
611
Marshall Clowe4220212015-01-11 06:15:59612template <typename _Tp> _Tp __create();
Dan Alberte8b42322014-08-09 23:51:51613
Marshall Clowe4220212015-01-11 06:15:59614template <typename _Tp, typename _Td>
615typename enable_if<sizeof(_Tp()->__a_value = __create<_Td>()), char>::type
Dan Alberte8b42322014-08-09 23:51:51616 __test_atomic_assignable(int);
Marshall Clowe4220212015-01-11 06:15:59617template <typename _Tp, typename _Up>
Dan Alberte8b42322014-08-09 23:51:51618__two __test_atomic_assignable(...);
619
Marshall Clowe4220212015-01-11 06:15:59620template <typename _Tp, typename _Td>
Dan Alberte8b42322014-08-09 23:51:51621struct __can_assign {
622 static const bool value =
Marshall Clowe4220212015-01-11 06:15:59623 sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char);
Dan Alberte8b42322014-08-09 23:51:51624};
625
Eric Fiseliera4ae16b2015-10-14 08:36:22626static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51627 // Avoid switch statement to make this a constexpr.
628 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
629 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
630 (__order == memory_order_release ? __ATOMIC_RELEASE:
631 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
632 (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
633 __ATOMIC_CONSUME))));
634}
635
Eric Fiseliera4ae16b2015-10-14 08:36:22636static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
Dan Albertc1017382015-01-06 18:39:37637 // Avoid switch statement to make this a constexpr.
638 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
639 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
640 (__order == memory_order_release ? __ATOMIC_RELAXED:
641 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
642 (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE:
643 __ATOMIC_CONSUME))));
644}
645
Dan Alberte8b42322014-08-09 23:51:51646} // namespace __gcc_atomic
647
648template <typename _Tp>
649static inline
650typename enable_if<
651 __gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value>::type
652__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
653 __a->__a_value = __val;
654}
655
656template <typename _Tp>
657static inline
658typename enable_if<
659 !__gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value &&
660 __gcc_atomic::__can_assign< _Atomic(_Tp)*, _Tp>::value>::type
661__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
662 // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
663 // the default operator= in an object is not volatile, a byte-by-byte copy
664 // is required.
665 volatile char* to = reinterpret_cast<volatile char*>(&__a->__a_value);
666 volatile char* end = to + sizeof(_Tp);
667 char* from = reinterpret_cast<char*>(&__val);
668 while (to != end) {
669 *to++ = *from++;
670 }
671}
672
673template <typename _Tp>
674static inline void __c11_atomic_init(_Atomic(_Tp)* __a, _Tp __val) {
675 __a->__a_value = __val;
676}
677
678static inline void __c11_atomic_thread_fence(memory_order __order) {
679 __atomic_thread_fence(__gcc_atomic::__to_gcc_order(__order));
680}
681
682static inline void __c11_atomic_signal_fence(memory_order __order) {
683 __atomic_signal_fence(__gcc_atomic::__to_gcc_order(__order));
684}
685
Dan Alberte8b42322014-08-09 23:51:51686template <typename _Tp>
687static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a, _Tp __val,
688 memory_order __order) {
689 return __atomic_store(&__a->__a_value, &__val,
690 __gcc_atomic::__to_gcc_order(__order));
691}
692
693template <typename _Tp>
694static inline void __c11_atomic_store(_Atomic(_Tp)* __a, _Tp __val,
695 memory_order __order) {
Dan Albertc1017382015-01-06 18:39:37696 __atomic_store(&__a->__a_value, &__val,
697 __gcc_atomic::__to_gcc_order(__order));
Dan Alberte8b42322014-08-09 23:51:51698}
699
700template <typename _Tp>
701static inline _Tp __c11_atomic_load(volatile _Atomic(_Tp)* __a,
702 memory_order __order) {
703 _Tp __ret;
704 __atomic_load(&__a->__a_value, &__ret,
705 __gcc_atomic::__to_gcc_order(__order));
706 return __ret;
707}
708
709template <typename _Tp>
710static inline _Tp __c11_atomic_load(_Atomic(_Tp)* __a, memory_order __order) {
711 _Tp __ret;
712 __atomic_load(&__a->__a_value, &__ret,
713 __gcc_atomic::__to_gcc_order(__order));
714 return __ret;
715}
716
717template <typename _Tp>
718static inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a,
719 _Tp __value, memory_order __order) {
720 _Tp __ret;
721 __atomic_exchange(&__a->__a_value, &__value, &__ret,
722 __gcc_atomic::__to_gcc_order(__order));
723 return __ret;
724}
725
726template <typename _Tp>
727static inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value,
728 memory_order __order) {
729 _Tp __ret;
730 __atomic_exchange(&__a->__a_value, &__value, &__ret,
731 __gcc_atomic::__to_gcc_order(__order));
732 return __ret;
733}
734
735template <typename _Tp>
736static inline bool __c11_atomic_compare_exchange_strong(
737 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
738 memory_order __success, memory_order __failure) {
739 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
740 false,
741 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37742 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51743}
744
745template <typename _Tp>
746static inline bool __c11_atomic_compare_exchange_strong(
747 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
748 memory_order __failure) {
749 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
750 false,
751 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37752 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51753}
754
755template <typename _Tp>
756static inline bool __c11_atomic_compare_exchange_weak(
757 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
758 memory_order __success, memory_order __failure) {
759 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
760 true,
761 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37762 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51763}
764
765template <typename _Tp>
766static inline bool __c11_atomic_compare_exchange_weak(
767 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
768 memory_order __failure) {
769 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
770 true,
771 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37772 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51773}
774
775template <typename _Tp>
776struct __skip_amt { enum {value = 1}; };
777
778template <typename _Tp>
779struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
780
781// FIXME: Haven't figured out what the spec says about using arrays with
782// atomic_fetch_add. Force a failure rather than creating bad behavior.
783template <typename _Tp>
784struct __skip_amt<_Tp[]> { };
785template <typename _Tp, int n>
786struct __skip_amt<_Tp[n]> { };
787
788template <typename _Tp, typename _Td>
789static inline _Tp __c11_atomic_fetch_add(volatile _Atomic(_Tp)* __a,
790 _Td __delta, memory_order __order) {
791 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
792 __gcc_atomic::__to_gcc_order(__order));
793}
794
795template <typename _Tp, typename _Td>
796static inline _Tp __c11_atomic_fetch_add(_Atomic(_Tp)* __a, _Td __delta,
797 memory_order __order) {
798 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
799 __gcc_atomic::__to_gcc_order(__order));
800}
801
802template <typename _Tp, typename _Td>
803static inline _Tp __c11_atomic_fetch_sub(volatile _Atomic(_Tp)* __a,
804 _Td __delta, memory_order __order) {
805 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
806 __gcc_atomic::__to_gcc_order(__order));
807}
808
809template <typename _Tp, typename _Td>
810static inline _Tp __c11_atomic_fetch_sub(_Atomic(_Tp)* __a, _Td __delta,
811 memory_order __order) {
812 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
813 __gcc_atomic::__to_gcc_order(__order));
814}
815
816template <typename _Tp>
817static inline _Tp __c11_atomic_fetch_and(volatile _Atomic(_Tp)* __a,
818 _Tp __pattern, memory_order __order) {
819 return __atomic_fetch_and(&__a->__a_value, __pattern,
820 __gcc_atomic::__to_gcc_order(__order));
821}
822
823template <typename _Tp>
824static inline _Tp __c11_atomic_fetch_and(_Atomic(_Tp)* __a,
825 _Tp __pattern, memory_order __order) {
826 return __atomic_fetch_and(&__a->__a_value, __pattern,
827 __gcc_atomic::__to_gcc_order(__order));
828}
829
830template <typename _Tp>
831static inline _Tp __c11_atomic_fetch_or(volatile _Atomic(_Tp)* __a,
832 _Tp __pattern, memory_order __order) {
833 return __atomic_fetch_or(&__a->__a_value, __pattern,
834 __gcc_atomic::__to_gcc_order(__order));
835}
836
837template <typename _Tp>
838static inline _Tp __c11_atomic_fetch_or(_Atomic(_Tp)* __a, _Tp __pattern,
839 memory_order __order) {
840 return __atomic_fetch_or(&__a->__a_value, __pattern,
841 __gcc_atomic::__to_gcc_order(__order));
842}
843
844template <typename _Tp>
845static inline _Tp __c11_atomic_fetch_xor(volatile _Atomic(_Tp)* __a,
846 _Tp __pattern, memory_order __order) {
847 return __atomic_fetch_xor(&__a->__a_value, __pattern,
848 __gcc_atomic::__to_gcc_order(__order));
849}
850
851template <typename _Tp>
852static inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern,
853 memory_order __order) {
854 return __atomic_fetch_xor(&__a->__a_value, __pattern,
855 __gcc_atomic::__to_gcc_order(__order));
856}
Eric Fiselier00f4a492015-08-19 17:21:46857#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP
Dan Alberte8b42322014-08-09 23:51:51858
Howard Hinnantd1176e22010-09-28 17:13:38859template <class _Tp>
860inline _LIBCPP_INLINE_VISIBILITY
861_Tp
Howard Hinnant300c67a2012-04-11 20:14:21862kill_dependency(_Tp __y) _NOEXCEPT
Howard Hinnantd1176e22010-09-28 17:13:38863{
864 return __y;
865}
Howard Hinnant8f73c632010-09-27 21:17:38866
Eric Fiseliera67beb72017-04-20 23:22:46867#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)
868# define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE
869# define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE
870# define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
871# define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
872# define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
873# define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE
874# define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE
875# define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE
876# define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE
877# define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE
878#else
879# define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
880# define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
881# define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
882# define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
883# define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
884# define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
885# define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
886# define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
887# define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
888# define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
889#endif
JF Bastien08511cd2016-03-25 15:48:21890
Howard Hinnant91e2f262010-12-07 20:46:14891// general atomic<T>
892
893template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
894struct __atomic_base // false
895{
Howard Hinnant7eb9f1e2012-09-16 20:33:09896 mutable _Atomic(_Tp) __a_;
Howard Hinnant91e2f262010-12-07 20:46:14897
JF Bastien08511cd2016-03-25 15:48:21898#if defined(__cpp_lib_atomic_is_always_lock_free)
899 static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0);
900#endif
901
Howard Hinnant91e2f262010-12-07 20:46:14902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21903 bool is_lock_free() const volatile _NOEXCEPT
Eric Fiselier7726a342015-06-13 00:23:07904 {
Eric Fiselier00f4a492015-08-19 17:21:46905#if defined(_LIBCPP_HAS_C_ATOMIC_IMP)
Eric Fiselier7726a342015-06-13 00:23:07906 return __c11_atomic_is_lock_free(sizeof(_Tp));
907#else
908 return __atomic_is_lock_free(sizeof(_Tp), 0);
909#endif
910 }
Howard Hinnant91e2f262010-12-07 20:46:14911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21912 bool is_lock_free() const _NOEXCEPT
Eric Fiselier7726a342015-06-13 00:23:07913 {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();}
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) volatile _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 void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39920 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Richard Smith6186c7f2012-04-11 18:55:46921 {__c11_atomic_store(&__a_, __d, __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 volatile _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 _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39928 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Richard Smith6186c7f2012-04-11 18:55:46929 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21931 operator _Tp() const volatile _NOEXCEPT {return load();}
Howard Hinnant91e2f262010-12-07 20:46:14932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21933 operator _Tp() const _NOEXCEPT {return load();}
Howard Hinnant91e2f262010-12-07 20:46:14934 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21935 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46936 {return __c11_atomic_exchange(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21938 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46939 {return __c11_atomic_exchange(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14940 _LIBCPP_INLINE_VISIBILITY
941 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21942 memory_order __s, memory_order __f) volatile _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39943 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46944 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14945 _LIBCPP_INLINE_VISIBILITY
946 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21947 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39948 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46949 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14950 _LIBCPP_INLINE_VISIBILITY
951 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21952 memory_order __s, memory_order __f) volatile _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39953 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46954 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14955 _LIBCPP_INLINE_VISIBILITY
956 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21957 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39958 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46959 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
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) volatile _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_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21966 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46967 {return __c11_atomic_compare_exchange_weak(&__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) volatile _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 _LIBCPP_INLINE_VISIBILITY
973 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21974 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46975 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14976
977 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8c570322016-11-18 06:42:17978#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:43979 __atomic_base() _NOEXCEPT = default;
980#else
981 __atomic_base() _NOEXCEPT : __a_() {}
Eric Fiselier8c570322016-11-18 06:42:17982#endif // _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:43983
Howard Hinnant91e2f262010-12-07 20:46:14984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21985 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
Eric Fiselier8eb066a2017-01-06 20:58:25986#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant91e2f262010-12-07 20:46:14987 __atomic_base(const __atomic_base&) = delete;
988 __atomic_base& operator=(const __atomic_base&) = delete;
989 __atomic_base& operator=(const __atomic_base&) volatile = delete;
Eric Fiselier8eb066a2017-01-06 20:58:25990#else
Howard Hinnant770d1c42010-12-08 17:20:28991private:
992 __atomic_base(const __atomic_base&);
993 __atomic_base& operator=(const __atomic_base&);
994 __atomic_base& operator=(const __atomic_base&) volatile;
Eric Fiselier8eb066a2017-01-06 20:58:25995#endif
Howard Hinnant91e2f262010-12-07 20:46:14996};
997
JF Bastien08511cd2016-03-25 15:48:21998#if defined(__cpp_lib_atomic_is_always_lock_free)
999template <class _Tp, bool __b>
1000_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
1001#endif
1002
Howard Hinnant91e2f262010-12-07 20:46:141003// atomic<Integral>
1004
1005template <class _Tp>
1006struct __atomic_base<_Tp, true>
1007 : public __atomic_base<_Tp, false>
1008{
1009 typedef __atomic_base<_Tp, false> __base;
1010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431011 __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141012 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211013 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant91e2f262010-12-07 20:46:141014
1015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211016 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461017 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211019 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461020 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211022 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461023 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211025 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461026 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211028 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461029 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211031 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461032 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141033 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211034 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461035 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211037 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461038 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211040 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461041 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211043 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461044 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141045
1046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211047 _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_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_add(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:141050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211051 _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:141052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211053 _Tp operator--(int) _NOEXCEPT {return fetch_sub(_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_add(_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_add(_Tp(1)) + _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:141058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211059 _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:141060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211061 _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
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_add(__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_add(__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_sub(__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_sub(__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_and(__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_and(__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_or(__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_or(__op) | __op;}
Howard Hinnant91e2f262010-12-07 20:46:141078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211079 _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant91e2f262010-12-07 20:46:141080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211081 _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant91e2f262010-12-07 20:46:141082};
1083
1084// atomic<T>
1085
1086template <class _Tp>
1087struct atomic
1088 : public __atomic_base<_Tp>
1089{
1090 typedef __atomic_base<_Tp> __base;
1091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431092 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211094 _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnantd2f6afb2010-12-07 23:24:411095
1096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211097 _Tp operator=(_Tp __d) volatile _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411098 {__base::store(__d); return __d;}
1099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211100 _Tp operator=(_Tp __d) _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411101 {__base::store(__d); return __d;}
Howard Hinnant91e2f262010-12-07 20:46:141102};
1103
1104// atomic<T*>
1105
1106template <class _Tp>
1107struct atomic<_Tp*>
1108 : public __atomic_base<_Tp*>
1109{
Howard Hinnantd2f6afb2010-12-07 23:24:411110 typedef __atomic_base<_Tp*> __base;
Howard Hinnant91e2f262010-12-07 20:46:141111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431112 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211114 _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant91e2f262010-12-07 20:46:141115
1116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211117 _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411118 {__base::store(__d); return __d;}
1119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211120 _Tp* operator=(_Tp* __d) _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411121 {__base::store(__d); return __d;}
1122
1123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91e2f262010-12-07 20:46:141124 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnant300c67a2012-04-11 20:14:211125 volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461126 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211128 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461129 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141130 _LIBCPP_INLINE_VISIBILITY
1131 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnant300c67a2012-04-11 20:14:211132 volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461133 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211135 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461136 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141137
1138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211139 _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
Howard Hinnant91e2f262010-12-07 20:46:141140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211141 _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);}
Howard Hinnant91e2f262010-12-07 20:46:141142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211143 _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant91e2f262010-12-07 20:46:141144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211145 _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant91e2f262010-12-07 20:46:141146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211147 _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant91e2f262010-12-07 20:46:141148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211149 _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant91e2f262010-12-07 20:46:141150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211151 _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant91e2f262010-12-07 20:46:141152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211153 _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
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_add(__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_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211159 _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211161 _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141162};
Howard Hinnant4777bf22010-12-06 23:10:081163
1164// atomic_is_lock_free
1165
1166template <class _Tp>
1167inline _LIBCPP_INLINE_VISIBILITY
1168bool
Howard Hinnant300c67a2012-04-11 20:14:211169atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081170{
Howard Hinnant91e2f262010-12-07 20:46:141171 return __o->is_lock_free();
Howard Hinnant4777bf22010-12-06 23:10:081172}
1173
1174template <class _Tp>
1175inline _LIBCPP_INLINE_VISIBILITY
1176bool
Howard Hinnant300c67a2012-04-11 20:14:211177atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081178{
Howard Hinnant91e2f262010-12-07 20:46:141179 return __o->is_lock_free();
Howard Hinnant4777bf22010-12-06 23:10:081180}
1181
1182// atomic_init
1183
1184template <class _Tp>
1185inline _LIBCPP_INLINE_VISIBILITY
1186void
Howard Hinnant300c67a2012-04-11 20:14:211187atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081188{
Richard Smith6186c7f2012-04-11 18:55:461189 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant4777bf22010-12-06 23:10:081190}
1191
1192template <class _Tp>
1193inline _LIBCPP_INLINE_VISIBILITY
1194void
Howard Hinnant300c67a2012-04-11 20:14:211195atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081196{
Richard Smith6186c7f2012-04-11 18:55:461197 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant4777bf22010-12-06 23:10:081198}
1199
1200// atomic_store
1201
1202template <class _Tp>
1203inline _LIBCPP_INLINE_VISIBILITY
1204void
Howard Hinnant300c67a2012-04-11 20:14:211205atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081206{
Howard Hinnant91e2f262010-12-07 20:46:141207 __o->store(__d);
Howard Hinnant4777bf22010-12-06 23:10:081208}
1209
1210template <class _Tp>
1211inline _LIBCPP_INLINE_VISIBILITY
1212void
Howard Hinnant300c67a2012-04-11 20:14:211213atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081214{
Howard Hinnant91e2f262010-12-07 20:46:141215 __o->store(__d);
Howard Hinnant4777bf22010-12-06 23:10:081216}
1217
1218// atomic_store_explicit
1219
1220template <class _Tp>
1221inline _LIBCPP_INLINE_VISIBILITY
1222void
Howard Hinnant300c67a2012-04-11 20:14:211223atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391224 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081225{
Howard Hinnant91e2f262010-12-07 20:46:141226 __o->store(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081227}
1228
1229template <class _Tp>
1230inline _LIBCPP_INLINE_VISIBILITY
1231void
Howard Hinnant300c67a2012-04-11 20:14:211232atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391233 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081234{
Howard Hinnant91e2f262010-12-07 20:46:141235 __o->store(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081236}
1237
1238// atomic_load
1239
1240template <class _Tp>
1241inline _LIBCPP_INLINE_VISIBILITY
1242_Tp
Howard Hinnant300c67a2012-04-11 20:14:211243atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081244{
Howard Hinnant91e2f262010-12-07 20:46:141245 return __o->load();
Howard Hinnant4777bf22010-12-06 23:10:081246}
1247
1248template <class _Tp>
1249inline _LIBCPP_INLINE_VISIBILITY
1250_Tp
Howard Hinnant300c67a2012-04-11 20:14:211251atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081252{
Howard Hinnant91e2f262010-12-07 20:46:141253 return __o->load();
Howard Hinnant4777bf22010-12-06 23:10:081254}
1255
1256// atomic_load_explicit
1257
1258template <class _Tp>
1259inline _LIBCPP_INLINE_VISIBILITY
1260_Tp
Howard Hinnant300c67a2012-04-11 20:14:211261atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391262 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081263{
Howard Hinnant91e2f262010-12-07 20:46:141264 return __o->load(__m);
Howard Hinnant4777bf22010-12-06 23:10:081265}
1266
1267template <class _Tp>
1268inline _LIBCPP_INLINE_VISIBILITY
1269_Tp
Howard Hinnant300c67a2012-04-11 20:14:211270atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391271 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081272{
Howard Hinnant91e2f262010-12-07 20:46:141273 return __o->load(__m);
Howard Hinnant4777bf22010-12-06 23:10:081274}
1275
1276// atomic_exchange
1277
1278template <class _Tp>
1279inline _LIBCPP_INLINE_VISIBILITY
1280_Tp
Howard Hinnant300c67a2012-04-11 20:14:211281atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081282{
Howard Hinnant91e2f262010-12-07 20:46:141283 return __o->exchange(__d);
Howard Hinnant4777bf22010-12-06 23:10:081284}
1285
1286template <class _Tp>
1287inline _LIBCPP_INLINE_VISIBILITY
1288_Tp
Howard Hinnant300c67a2012-04-11 20:14:211289atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081290{
Howard Hinnant91e2f262010-12-07 20:46:141291 return __o->exchange(__d);
Howard Hinnant4777bf22010-12-06 23:10:081292}
1293
1294// atomic_exchange_explicit
1295
1296template <class _Tp>
1297inline _LIBCPP_INLINE_VISIBILITY
1298_Tp
Howard Hinnant300c67a2012-04-11 20:14:211299atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081300{
Howard Hinnant91e2f262010-12-07 20:46:141301 return __o->exchange(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081302}
1303
1304template <class _Tp>
1305inline _LIBCPP_INLINE_VISIBILITY
1306_Tp
Howard Hinnant300c67a2012-04-11 20:14:211307atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081308{
Howard Hinnant91e2f262010-12-07 20:46:141309 return __o->exchange(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081310}
1311
1312// atomic_compare_exchange_weak
1313
1314template <class _Tp>
1315inline _LIBCPP_INLINE_VISIBILITY
1316bool
Howard Hinnant300c67a2012-04-11 20:14:211317atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081318{
Howard Hinnant91e2f262010-12-07 20:46:141319 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081320}
1321
1322template <class _Tp>
1323inline _LIBCPP_INLINE_VISIBILITY
1324bool
Howard Hinnant300c67a2012-04-11 20:14:211325atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081326{
Howard Hinnant91e2f262010-12-07 20:46:141327 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081328}
1329
1330// atomic_compare_exchange_strong
1331
1332template <class _Tp>
1333inline _LIBCPP_INLINE_VISIBILITY
1334bool
Howard Hinnant300c67a2012-04-11 20:14:211335atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081336{
Howard Hinnant91e2f262010-12-07 20:46:141337 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081338}
1339
1340template <class _Tp>
1341inline _LIBCPP_INLINE_VISIBILITY
1342bool
Howard Hinnant300c67a2012-04-11 20:14:211343atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081344{
Howard Hinnant91e2f262010-12-07 20:46:141345 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081346}
1347
1348// atomic_compare_exchange_weak_explicit
1349
1350template <class _Tp>
1351inline _LIBCPP_INLINE_VISIBILITY
1352bool
1353atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
1354 _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211355 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391356 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081357{
Howard Hinnant91e2f262010-12-07 20:46:141358 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081359}
1360
1361template <class _Tp>
1362inline _LIBCPP_INLINE_VISIBILITY
1363bool
1364atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211365 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391366 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081367{
Howard Hinnant91e2f262010-12-07 20:46:141368 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081369}
1370
1371// atomic_compare_exchange_strong_explicit
1372
1373template <class _Tp>
1374inline _LIBCPP_INLINE_VISIBILITY
1375bool
1376atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
1377 _Tp* __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211378 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391379 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081380{
Howard Hinnant91e2f262010-12-07 20:46:141381 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081382}
1383
1384template <class _Tp>
1385inline _LIBCPP_INLINE_VISIBILITY
1386bool
1387atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
1388 _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211389 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391390 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081391{
Howard Hinnant91e2f262010-12-07 20:46:141392 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081393}
1394
Howard Hinnant91e2f262010-12-07 20:46:141395// atomic_fetch_add
Howard Hinnant4777bf22010-12-06 23:10:081396
1397template <class _Tp>
Howard Hinnant91e2f262010-12-07 20:46:141398inline _LIBCPP_INLINE_VISIBILITY
1399typename enable_if
1400<
1401 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1402 _Tp
1403>::type
Howard Hinnant300c67a2012-04-11 20:14:211404atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081405{
Howard Hinnant91e2f262010-12-07 20:46:141406 return __o->fetch_add(__op);
1407}
Howard Hinnant4777bf22010-12-06 23:10:081408
Howard Hinnant91e2f262010-12-07 20:46:141409template <class _Tp>
1410inline _LIBCPP_INLINE_VISIBILITY
1411typename enable_if
1412<
1413 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1414 _Tp
1415>::type
Howard Hinnant300c67a2012-04-11 20:14:211416atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141417{
1418 return __o->fetch_add(__op);
1419}
Howard Hinnant4777bf22010-12-06 23:10:081420
Howard Hinnant91e2f262010-12-07 20:46:141421template <class _Tp>
1422inline _LIBCPP_INLINE_VISIBILITY
1423_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211424atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141425{
1426 return __o->fetch_add(__op);
1427}
1428
1429template <class _Tp>
1430inline _LIBCPP_INLINE_VISIBILITY
1431_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211432atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141433{
1434 return __o->fetch_add(__op);
1435}
1436
1437// atomic_fetch_add_explicit
1438
1439template <class _Tp>
1440inline _LIBCPP_INLINE_VISIBILITY
1441typename enable_if
1442<
1443 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1444 _Tp
1445>::type
Howard Hinnant300c67a2012-04-11 20:14:211446atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141447{
1448 return __o->fetch_add(__op, __m);
1449}
1450
1451template <class _Tp>
1452inline _LIBCPP_INLINE_VISIBILITY
1453typename enable_if
1454<
1455 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1456 _Tp
1457>::type
Howard Hinnant300c67a2012-04-11 20:14:211458atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141459{
1460 return __o->fetch_add(__op, __m);
1461}
1462
1463template <class _Tp>
1464inline _LIBCPP_INLINE_VISIBILITY
1465_Tp*
1466atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnant300c67a2012-04-11 20:14:211467 memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141468{
1469 return __o->fetch_add(__op, __m);
1470}
1471
1472template <class _Tp>
1473inline _LIBCPP_INLINE_VISIBILITY
1474_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211475atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141476{
1477 return __o->fetch_add(__op, __m);
1478}
1479
1480// atomic_fetch_sub
1481
1482template <class _Tp>
1483inline _LIBCPP_INLINE_VISIBILITY
1484typename enable_if
1485<
1486 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1487 _Tp
1488>::type
Howard Hinnant300c67a2012-04-11 20:14:211489atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141490{
1491 return __o->fetch_sub(__op);
1492}
1493
1494template <class _Tp>
1495inline _LIBCPP_INLINE_VISIBILITY
1496typename enable_if
1497<
1498 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1499 _Tp
1500>::type
Howard Hinnant300c67a2012-04-11 20:14:211501atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141502{
1503 return __o->fetch_sub(__op);
1504}
1505
1506template <class _Tp>
1507inline _LIBCPP_INLINE_VISIBILITY
1508_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211509atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141510{
1511 return __o->fetch_sub(__op);
1512}
1513
1514template <class _Tp>
1515inline _LIBCPP_INLINE_VISIBILITY
1516_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211517atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141518{
1519 return __o->fetch_sub(__op);
1520}
1521
1522// atomic_fetch_sub_explicit
1523
1524template <class _Tp>
1525inline _LIBCPP_INLINE_VISIBILITY
1526typename enable_if
1527<
1528 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1529 _Tp
1530>::type
Howard Hinnant300c67a2012-04-11 20:14:211531atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141532{
1533 return __o->fetch_sub(__op, __m);
1534}
1535
1536template <class _Tp>
1537inline _LIBCPP_INLINE_VISIBILITY
1538typename enable_if
1539<
1540 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1541 _Tp
1542>::type
Howard Hinnant300c67a2012-04-11 20:14:211543atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141544{
1545 return __o->fetch_sub(__op, __m);
1546}
1547
1548template <class _Tp>
1549inline _LIBCPP_INLINE_VISIBILITY
1550_Tp*
1551atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnant300c67a2012-04-11 20:14:211552 memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141553{
1554 return __o->fetch_sub(__op, __m);
1555}
1556
1557template <class _Tp>
1558inline _LIBCPP_INLINE_VISIBILITY
1559_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211560atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141561{
1562 return __o->fetch_sub(__op, __m);
1563}
1564
1565// atomic_fetch_and
1566
1567template <class _Tp>
1568inline _LIBCPP_INLINE_VISIBILITY
1569typename enable_if
1570<
1571 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1572 _Tp
1573>::type
Howard Hinnant300c67a2012-04-11 20:14:211574atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141575{
1576 return __o->fetch_and(__op);
1577}
1578
1579template <class _Tp>
1580inline _LIBCPP_INLINE_VISIBILITY
1581typename enable_if
1582<
1583 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1584 _Tp
1585>::type
Howard Hinnant300c67a2012-04-11 20:14:211586atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141587{
1588 return __o->fetch_and(__op);
1589}
1590
1591// atomic_fetch_and_explicit
1592
1593template <class _Tp>
1594inline _LIBCPP_INLINE_VISIBILITY
1595typename enable_if
1596<
1597 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1598 _Tp
1599>::type
Howard Hinnant300c67a2012-04-11 20:14:211600atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141601{
1602 return __o->fetch_and(__op, __m);
1603}
1604
1605template <class _Tp>
1606inline _LIBCPP_INLINE_VISIBILITY
1607typename enable_if
1608<
1609 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1610 _Tp
1611>::type
Howard Hinnant300c67a2012-04-11 20:14:211612atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141613{
1614 return __o->fetch_and(__op, __m);
1615}
1616
1617// atomic_fetch_or
1618
1619template <class _Tp>
1620inline _LIBCPP_INLINE_VISIBILITY
1621typename enable_if
1622<
1623 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1624 _Tp
1625>::type
Howard Hinnant300c67a2012-04-11 20:14:211626atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141627{
1628 return __o->fetch_or(__op);
1629}
1630
1631template <class _Tp>
1632inline _LIBCPP_INLINE_VISIBILITY
1633typename enable_if
1634<
1635 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1636 _Tp
1637>::type
Howard Hinnant300c67a2012-04-11 20:14:211638atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141639{
1640 return __o->fetch_or(__op);
1641}
1642
1643// atomic_fetch_or_explicit
1644
1645template <class _Tp>
1646inline _LIBCPP_INLINE_VISIBILITY
1647typename enable_if
1648<
1649 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1650 _Tp
1651>::type
Howard Hinnant300c67a2012-04-11 20:14:211652atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141653{
1654 return __o->fetch_or(__op, __m);
1655}
1656
1657template <class _Tp>
1658inline _LIBCPP_INLINE_VISIBILITY
1659typename enable_if
1660<
1661 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1662 _Tp
1663>::type
Howard Hinnant300c67a2012-04-11 20:14:211664atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141665{
1666 return __o->fetch_or(__op, __m);
1667}
1668
1669// atomic_fetch_xor
1670
1671template <class _Tp>
1672inline _LIBCPP_INLINE_VISIBILITY
1673typename enable_if
1674<
1675 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1676 _Tp
1677>::type
Howard Hinnant300c67a2012-04-11 20:14:211678atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141679{
1680 return __o->fetch_xor(__op);
1681}
1682
1683template <class _Tp>
1684inline _LIBCPP_INLINE_VISIBILITY
1685typename enable_if
1686<
1687 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1688 _Tp
1689>::type
Howard Hinnant300c67a2012-04-11 20:14:211690atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141691{
1692 return __o->fetch_xor(__op);
1693}
1694
1695// atomic_fetch_xor_explicit
1696
1697template <class _Tp>
1698inline _LIBCPP_INLINE_VISIBILITY
1699typename enable_if
1700<
1701 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1702 _Tp
1703>::type
Howard Hinnant300c67a2012-04-11 20:14:211704atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141705{
1706 return __o->fetch_xor(__op, __m);
1707}
1708
1709template <class _Tp>
1710inline _LIBCPP_INLINE_VISIBILITY
1711typename enable_if
1712<
1713 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1714 _Tp
1715>::type
Howard Hinnant300c67a2012-04-11 20:14:211716atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141717{
1718 return __o->fetch_xor(__op, __m);
1719}
Howard Hinnant4777bf22010-12-06 23:10:081720
Howard Hinnant770d1c42010-12-08 17:20:281721// flag type and operations
1722
1723typedef struct atomic_flag
1724{
David Chisnall83b2c842011-12-19 11:44:201725 _Atomic(bool) __a_;
Howard Hinnant770d1c42010-12-08 17:20:281726
1727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211728 bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461729 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211731 bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461732 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211734 void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461735 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211737 void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461738 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281739
1740 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8c570322016-11-18 06:42:171741#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:431742 atomic_flag() _NOEXCEPT = default;
1743#else
1744 atomic_flag() _NOEXCEPT : __a_() {}
Eric Fiselier8c570322016-11-18 06:42:171745#endif // _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:431746
Marshall Clow727ed612018-04-25 14:27:291747 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Eric Fiselier219406e2016-05-03 02:12:261748 atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
Howard Hinnant770d1c42010-12-08 17:20:281749
Eric Fiselier8eb066a2017-01-06 20:58:251750#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant770d1c42010-12-08 17:20:281751 atomic_flag(const atomic_flag&) = delete;
1752 atomic_flag& operator=(const atomic_flag&) = delete;
1753 atomic_flag& operator=(const atomic_flag&) volatile = delete;
Eric Fiselier8eb066a2017-01-06 20:58:251754#else
Howard Hinnant770d1c42010-12-08 17:20:281755private:
1756 atomic_flag(const atomic_flag&);
1757 atomic_flag& operator=(const atomic_flag&);
1758 atomic_flag& operator=(const atomic_flag&) volatile;
Eric Fiselier8eb066a2017-01-06 20:58:251759#endif
Howard Hinnant770d1c42010-12-08 17:20:281760} atomic_flag;
1761
1762inline _LIBCPP_INLINE_VISIBILITY
1763bool
Howard Hinnant300c67a2012-04-11 20:14:211764atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281765{
1766 return __o->test_and_set();
1767}
1768
1769inline _LIBCPP_INLINE_VISIBILITY
1770bool
Howard Hinnant300c67a2012-04-11 20:14:211771atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281772{
1773 return __o->test_and_set();
1774}
1775
1776inline _LIBCPP_INLINE_VISIBILITY
1777bool
Howard Hinnant300c67a2012-04-11 20:14:211778atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281779{
1780 return __o->test_and_set(__m);
1781}
1782
1783inline _LIBCPP_INLINE_VISIBILITY
1784bool
Howard Hinnant300c67a2012-04-11 20:14:211785atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281786{
1787 return __o->test_and_set(__m);
1788}
1789
1790inline _LIBCPP_INLINE_VISIBILITY
1791void
Howard Hinnant300c67a2012-04-11 20:14:211792atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281793{
1794 __o->clear();
1795}
1796
1797inline _LIBCPP_INLINE_VISIBILITY
1798void
Howard Hinnant300c67a2012-04-11 20:14:211799atomic_flag_clear(atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281800{
1801 __o->clear();
1802}
1803
1804inline _LIBCPP_INLINE_VISIBILITY
1805void
Howard Hinnant300c67a2012-04-11 20:14:211806atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281807{
1808 __o->clear(__m);
1809}
1810
1811inline _LIBCPP_INLINE_VISIBILITY
1812void
Howard Hinnant300c67a2012-04-11 20:14:211813atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281814{
1815 __o->clear(__m);
1816}
1817
1818// fences
1819
1820inline _LIBCPP_INLINE_VISIBILITY
1821void
Howard Hinnant300c67a2012-04-11 20:14:211822atomic_thread_fence(memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281823{
Richard Smith6186c7f2012-04-11 18:55:461824 __c11_atomic_thread_fence(__m);
Howard Hinnant770d1c42010-12-08 17:20:281825}
1826
1827inline _LIBCPP_INLINE_VISIBILITY
1828void
Howard Hinnant300c67a2012-04-11 20:14:211829atomic_signal_fence(memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281830{
Richard Smith6186c7f2012-04-11 18:55:461831 __c11_atomic_signal_fence(__m);
Howard Hinnant770d1c42010-12-08 17:20:281832}
1833
Howard Hinnantd2f6afb2010-12-07 23:24:411834// Atomics for standard typedef types
1835
Howard Hinnant6ae47052013-01-04 18:58:501836typedef atomic<bool> atomic_bool;
Howard Hinnantd2f6afb2010-12-07 23:24:411837typedef atomic<char> atomic_char;
1838typedef atomic<signed char> atomic_schar;
1839typedef atomic<unsigned char> atomic_uchar;
1840typedef atomic<short> atomic_short;
1841typedef atomic<unsigned short> atomic_ushort;
1842typedef atomic<int> atomic_int;
1843typedef atomic<unsigned int> atomic_uint;
1844typedef atomic<long> atomic_long;
1845typedef atomic<unsigned long> atomic_ulong;
1846typedef atomic<long long> atomic_llong;
1847typedef atomic<unsigned long long> atomic_ullong;
1848typedef atomic<char16_t> atomic_char16_t;
1849typedef atomic<char32_t> atomic_char32_t;
1850typedef atomic<wchar_t> atomic_wchar_t;
1851
1852typedef atomic<int_least8_t> atomic_int_least8_t;
1853typedef atomic<uint_least8_t> atomic_uint_least8_t;
1854typedef atomic<int_least16_t> atomic_int_least16_t;
1855typedef atomic<uint_least16_t> atomic_uint_least16_t;
1856typedef atomic<int_least32_t> atomic_int_least32_t;
1857typedef atomic<uint_least32_t> atomic_uint_least32_t;
1858typedef atomic<int_least64_t> atomic_int_least64_t;
1859typedef atomic<uint_least64_t> atomic_uint_least64_t;
1860
1861typedef atomic<int_fast8_t> atomic_int_fast8_t;
1862typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
1863typedef atomic<int_fast16_t> atomic_int_fast16_t;
1864typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1865typedef atomic<int_fast32_t> atomic_int_fast32_t;
1866typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1867typedef atomic<int_fast64_t> atomic_int_fast64_t;
1868typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1869
Marshall Clowca894502016-06-30 15:28:381870typedef atomic< int8_t> atomic_int8_t;
1871typedef atomic<uint8_t> atomic_uint8_t;
1872typedef atomic< int16_t> atomic_int16_t;
1873typedef atomic<uint16_t> atomic_uint16_t;
1874typedef atomic< int32_t> atomic_int32_t;
1875typedef atomic<uint32_t> atomic_uint32_t;
1876typedef atomic< int64_t> atomic_int64_t;
1877typedef atomic<uint64_t> atomic_uint64_t;
1878
Howard Hinnantd2f6afb2010-12-07 23:24:411879typedef atomic<intptr_t> atomic_intptr_t;
1880typedef atomic<uintptr_t> atomic_uintptr_t;
1881typedef atomic<size_t> atomic_size_t;
1882typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1883typedef atomic<intmax_t> atomic_intmax_t;
1884typedef atomic<uintmax_t> atomic_uintmax_t;
1885
Howard Hinnant767ae2b2010-09-29 21:20:031886#define ATOMIC_FLAG_INIT {false}
Howard Hinnant611fdaf2010-10-04 18:52:541887#define ATOMIC_VAR_INIT(__v) {__v}
1888
Howard Hinnant8f73c632010-09-27 21:17:381889_LIBCPP_END_NAMESPACE_STD
1890
Howard Hinnant8f73c632010-09-27 21:17:381891#endif // _LIBCPP_ATOMIC