blob: f55e28ff5e92acb8288ba483b56195c9f5ae7404 [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
Jonathan Roelofs8d86b2e2014-09-05 19:45:05558
JF Bastien08511cd2016-03-25 15:48:21559#if _LIBCPP_STD_VER > 14
JF Bastien08511cd2016-03-25 15:48:21560# define __cpp_lib_atomic_is_always_lock_free 201603L
561#endif
562
Eric Fiselier5ed76752017-01-13 23:45:39563#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
564 _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \
565 __m == memory_order_acquire || \
566 __m == memory_order_acq_rel, \
567 "memory order argument to atomic operation is invalid")
568
569#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
570 _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \
571 __m == memory_order_acq_rel, \
572 "memory order argument to atomic operation is invalid")
573
574#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
575 _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \
576 __f == memory_order_acq_rel, \
577 "memory order argument to atomic operation is invalid")
578
Howard Hinnant8f73c632010-09-27 21:17:38579_LIBCPP_BEGIN_NAMESPACE_STD
580
Howard Hinnantd1176e22010-09-28 17:13:38581typedef enum memory_order
582{
583 memory_order_relaxed, memory_order_consume, memory_order_acquire,
584 memory_order_release, memory_order_acq_rel, memory_order_seq_cst
585} memory_order;
586
Eric Fiselier00f4a492015-08-19 17:21:46587#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
Dan Alberte8b42322014-08-09 23:51:51588namespace __gcc_atomic {
Marshall Clowe4220212015-01-11 06:15:59589template <typename _Tp>
Dan Alberte8b42322014-08-09 23:51:51590struct __gcc_atomic_t {
Eric Fiseliere39f4b92015-12-15 00:32:21591
592#if _GNUC_VER >= 501
593 static_assert(is_trivially_copyable<_Tp>::value,
594 "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
595#endif
596
Eric Fiseliera4ae16b2015-10-14 08:36:22597 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8c570322016-11-18 06:42:17598#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera4ae16b2015-10-14 08:36:22599 __gcc_atomic_t() _NOEXCEPT = default;
600#else
601 __gcc_atomic_t() _NOEXCEPT : __a_value() {}
Eric Fiselier8c570322016-11-18 06:42:17602#endif // _LIBCPP_CXX03_LANG
Eric Fiselier26edd802015-07-14 17:50:27603 _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT
604 : __a_value(value) {}
Marshall Clowe4220212015-01-11 06:15:59605 _Tp __a_value;
Dan Alberte8b42322014-08-09 23:51:51606};
607#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>
608
Marshall Clowe4220212015-01-11 06:15:59609template <typename _Tp> _Tp __create();
Dan Alberte8b42322014-08-09 23:51:51610
Marshall Clowe4220212015-01-11 06:15:59611template <typename _Tp, typename _Td>
612typename enable_if<sizeof(_Tp()->__a_value = __create<_Td>()), char>::type
Dan Alberte8b42322014-08-09 23:51:51613 __test_atomic_assignable(int);
Marshall Clowe4220212015-01-11 06:15:59614template <typename _Tp, typename _Up>
Dan Alberte8b42322014-08-09 23:51:51615__two __test_atomic_assignable(...);
616
Marshall Clowe4220212015-01-11 06:15:59617template <typename _Tp, typename _Td>
Dan Alberte8b42322014-08-09 23:51:51618struct __can_assign {
619 static const bool value =
Marshall Clowe4220212015-01-11 06:15:59620 sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char);
Dan Alberte8b42322014-08-09 23:51:51621};
622
Eric Fiseliera4ae16b2015-10-14 08:36:22623static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
Dan Alberte8b42322014-08-09 23:51:51624 // Avoid switch statement to make this a constexpr.
625 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
626 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
627 (__order == memory_order_release ? __ATOMIC_RELEASE:
628 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
629 (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
630 __ATOMIC_CONSUME))));
631}
632
Eric Fiseliera4ae16b2015-10-14 08:36:22633static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
Dan Albertc1017382015-01-06 18:39:37634 // Avoid switch statement to make this a constexpr.
635 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
636 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
637 (__order == memory_order_release ? __ATOMIC_RELAXED:
638 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
639 (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE:
640 __ATOMIC_CONSUME))));
641}
642
Dan Alberte8b42322014-08-09 23:51:51643} // namespace __gcc_atomic
644
645template <typename _Tp>
646static inline
647typename enable_if<
648 __gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value>::type
649__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
650 __a->__a_value = __val;
651}
652
653template <typename _Tp>
654static inline
655typename enable_if<
656 !__gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value &&
657 __gcc_atomic::__can_assign< _Atomic(_Tp)*, _Tp>::value>::type
658__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
659 // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
660 // the default operator= in an object is not volatile, a byte-by-byte copy
661 // is required.
662 volatile char* to = reinterpret_cast<volatile char*>(&__a->__a_value);
663 volatile char* end = to + sizeof(_Tp);
664 char* from = reinterpret_cast<char*>(&__val);
665 while (to != end) {
666 *to++ = *from++;
667 }
668}
669
670template <typename _Tp>
671static inline void __c11_atomic_init(_Atomic(_Tp)* __a, _Tp __val) {
672 __a->__a_value = __val;
673}
674
675static inline void __c11_atomic_thread_fence(memory_order __order) {
676 __atomic_thread_fence(__gcc_atomic::__to_gcc_order(__order));
677}
678
679static inline void __c11_atomic_signal_fence(memory_order __order) {
680 __atomic_signal_fence(__gcc_atomic::__to_gcc_order(__order));
681}
682
Dan Alberte8b42322014-08-09 23:51:51683template <typename _Tp>
684static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a, _Tp __val,
685 memory_order __order) {
686 return __atomic_store(&__a->__a_value, &__val,
687 __gcc_atomic::__to_gcc_order(__order));
688}
689
690template <typename _Tp>
691static inline void __c11_atomic_store(_Atomic(_Tp)* __a, _Tp __val,
692 memory_order __order) {
Dan Albertc1017382015-01-06 18:39:37693 __atomic_store(&__a->__a_value, &__val,
694 __gcc_atomic::__to_gcc_order(__order));
Dan Alberte8b42322014-08-09 23:51:51695}
696
697template <typename _Tp>
698static inline _Tp __c11_atomic_load(volatile _Atomic(_Tp)* __a,
699 memory_order __order) {
700 _Tp __ret;
701 __atomic_load(&__a->__a_value, &__ret,
702 __gcc_atomic::__to_gcc_order(__order));
703 return __ret;
704}
705
706template <typename _Tp>
707static inline _Tp __c11_atomic_load(_Atomic(_Tp)* __a, memory_order __order) {
708 _Tp __ret;
709 __atomic_load(&__a->__a_value, &__ret,
710 __gcc_atomic::__to_gcc_order(__order));
711 return __ret;
712}
713
714template <typename _Tp>
715static inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a,
716 _Tp __value, memory_order __order) {
717 _Tp __ret;
718 __atomic_exchange(&__a->__a_value, &__value, &__ret,
719 __gcc_atomic::__to_gcc_order(__order));
720 return __ret;
721}
722
723template <typename _Tp>
724static inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value,
725 memory_order __order) {
726 _Tp __ret;
727 __atomic_exchange(&__a->__a_value, &__value, &__ret,
728 __gcc_atomic::__to_gcc_order(__order));
729 return __ret;
730}
731
732template <typename _Tp>
733static inline bool __c11_atomic_compare_exchange_strong(
734 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
735 memory_order __success, memory_order __failure) {
736 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
737 false,
738 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37739 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51740}
741
742template <typename _Tp>
743static inline bool __c11_atomic_compare_exchange_strong(
744 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
745 memory_order __failure) {
746 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
747 false,
748 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37749 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51750}
751
752template <typename _Tp>
753static inline bool __c11_atomic_compare_exchange_weak(
754 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
755 memory_order __success, memory_order __failure) {
756 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
757 true,
758 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37759 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51760}
761
762template <typename _Tp>
763static inline bool __c11_atomic_compare_exchange_weak(
764 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
765 memory_order __failure) {
766 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
767 true,
768 __gcc_atomic::__to_gcc_order(__success),
Dan Albertc1017382015-01-06 18:39:37769 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Alberte8b42322014-08-09 23:51:51770}
771
772template <typename _Tp>
773struct __skip_amt { enum {value = 1}; };
774
775template <typename _Tp>
776struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
777
778// FIXME: Haven't figured out what the spec says about using arrays with
779// atomic_fetch_add. Force a failure rather than creating bad behavior.
780template <typename _Tp>
781struct __skip_amt<_Tp[]> { };
782template <typename _Tp, int n>
783struct __skip_amt<_Tp[n]> { };
784
785template <typename _Tp, typename _Td>
786static inline _Tp __c11_atomic_fetch_add(volatile _Atomic(_Tp)* __a,
787 _Td __delta, memory_order __order) {
788 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
789 __gcc_atomic::__to_gcc_order(__order));
790}
791
792template <typename _Tp, typename _Td>
793static inline _Tp __c11_atomic_fetch_add(_Atomic(_Tp)* __a, _Td __delta,
794 memory_order __order) {
795 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
796 __gcc_atomic::__to_gcc_order(__order));
797}
798
799template <typename _Tp, typename _Td>
800static inline _Tp __c11_atomic_fetch_sub(volatile _Atomic(_Tp)* __a,
801 _Td __delta, memory_order __order) {
802 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
803 __gcc_atomic::__to_gcc_order(__order));
804}
805
806template <typename _Tp, typename _Td>
807static inline _Tp __c11_atomic_fetch_sub(_Atomic(_Tp)* __a, _Td __delta,
808 memory_order __order) {
809 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
810 __gcc_atomic::__to_gcc_order(__order));
811}
812
813template <typename _Tp>
814static inline _Tp __c11_atomic_fetch_and(volatile _Atomic(_Tp)* __a,
815 _Tp __pattern, memory_order __order) {
816 return __atomic_fetch_and(&__a->__a_value, __pattern,
817 __gcc_atomic::__to_gcc_order(__order));
818}
819
820template <typename _Tp>
821static inline _Tp __c11_atomic_fetch_and(_Atomic(_Tp)* __a,
822 _Tp __pattern, memory_order __order) {
823 return __atomic_fetch_and(&__a->__a_value, __pattern,
824 __gcc_atomic::__to_gcc_order(__order));
825}
826
827template <typename _Tp>
828static inline _Tp __c11_atomic_fetch_or(volatile _Atomic(_Tp)* __a,
829 _Tp __pattern, memory_order __order) {
830 return __atomic_fetch_or(&__a->__a_value, __pattern,
831 __gcc_atomic::__to_gcc_order(__order));
832}
833
834template <typename _Tp>
835static inline _Tp __c11_atomic_fetch_or(_Atomic(_Tp)* __a, _Tp __pattern,
836 memory_order __order) {
837 return __atomic_fetch_or(&__a->__a_value, __pattern,
838 __gcc_atomic::__to_gcc_order(__order));
839}
840
841template <typename _Tp>
842static inline _Tp __c11_atomic_fetch_xor(volatile _Atomic(_Tp)* __a,
843 _Tp __pattern, memory_order __order) {
844 return __atomic_fetch_xor(&__a->__a_value, __pattern,
845 __gcc_atomic::__to_gcc_order(__order));
846}
847
848template <typename _Tp>
849static inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern,
850 memory_order __order) {
851 return __atomic_fetch_xor(&__a->__a_value, __pattern,
852 __gcc_atomic::__to_gcc_order(__order));
853}
Eric Fiselier00f4a492015-08-19 17:21:46854#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP
Dan Alberte8b42322014-08-09 23:51:51855
Howard Hinnantd1176e22010-09-28 17:13:38856template <class _Tp>
857inline _LIBCPP_INLINE_VISIBILITY
858_Tp
Howard Hinnant300c67a2012-04-11 20:14:21859kill_dependency(_Tp __y) _NOEXCEPT
Howard Hinnantd1176e22010-09-28 17:13:38860{
861 return __y;
862}
Howard Hinnant8f73c632010-09-27 21:17:38863
Eric Fiseliera67beb72017-04-20 23:22:46864#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)
865# define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE
866# define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE
867# define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
868# define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
869# define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
870# define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE
871# define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE
872# define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE
873# define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE
874# define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE
875#else
876# define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
877# define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
878# define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
879# define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
880# define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
881# define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
882# define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
883# define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
884# define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
885# define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
886#endif
JF Bastien08511cd2016-03-25 15:48:21887
Howard Hinnant91e2f262010-12-07 20:46:14888// general atomic<T>
889
890template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
891struct __atomic_base // false
892{
Howard Hinnant7eb9f1e2012-09-16 20:33:09893 mutable _Atomic(_Tp) __a_;
Howard Hinnant91e2f262010-12-07 20:46:14894
JF Bastien08511cd2016-03-25 15:48:21895#if defined(__cpp_lib_atomic_is_always_lock_free)
896 static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0);
897#endif
898
Howard Hinnant91e2f262010-12-07 20:46:14899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21900 bool is_lock_free() const volatile _NOEXCEPT
Eric Fiselier7726a342015-06-13 00:23:07901 {
Eric Fiselier00f4a492015-08-19 17:21:46902#if defined(_LIBCPP_HAS_C_ATOMIC_IMP)
Eric Fiselier7726a342015-06-13 00:23:07903 return __c11_atomic_is_lock_free(sizeof(_Tp));
904#else
905 return __atomic_is_lock_free(sizeof(_Tp), 0);
906#endif
907 }
Howard Hinnant91e2f262010-12-07 20:46:14908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21909 bool is_lock_free() const _NOEXCEPT
Eric Fiselier7726a342015-06-13 00:23:07910 {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();}
Howard Hinnant91e2f262010-12-07 20:46:14911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21912 void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39913 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Richard Smith6186c7f2012-04-11 18:55:46914 {__c11_atomic_store(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21916 void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39917 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Richard Smith6186c7f2012-04-11 18:55:46918 {__c11_atomic_store(&__a_, __d, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21920 _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39921 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Richard Smith6186c7f2012-04-11 18:55:46922 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21924 _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39925 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Richard Smith6186c7f2012-04-11 18:55:46926 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21928 operator _Tp() const volatile _NOEXCEPT {return load();}
Howard Hinnant91e2f262010-12-07 20:46:14929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21930 operator _Tp() const _NOEXCEPT {return load();}
Howard Hinnant91e2f262010-12-07 20:46:14931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21932 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46933 {return __c11_atomic_exchange(&__a_, __d, __m);}
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) _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
938 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21939 memory_order __s, memory_order __f) volatile _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39940 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46941 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14942 _LIBCPP_INLINE_VISIBILITY
943 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21944 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39945 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46946 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14947 _LIBCPP_INLINE_VISIBILITY
948 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21949 memory_order __s, memory_order __f) volatile _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39950 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46951 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14952 _LIBCPP_INLINE_VISIBILITY
953 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21954 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:39955 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith6186c7f2012-04-11 18:55:46956 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant91e2f262010-12-07 20:46:14957 _LIBCPP_INLINE_VISIBILITY
958 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21959 memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46960 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14961 _LIBCPP_INLINE_VISIBILITY
962 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21963 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46964 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14965 _LIBCPP_INLINE_VISIBILITY
966 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21967 memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46968 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14969 _LIBCPP_INLINE_VISIBILITY
970 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:21971 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:46972 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant91e2f262010-12-07 20:46:14973
974 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8c570322016-11-18 06:42:17975#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:43976 __atomic_base() _NOEXCEPT = default;
977#else
978 __atomic_base() _NOEXCEPT : __a_() {}
Eric Fiselier8c570322016-11-18 06:42:17979#endif // _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:43980
Howard Hinnant91e2f262010-12-07 20:46:14981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:21982 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
Eric Fiselier8eb066a2017-01-06 20:58:25983#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant91e2f262010-12-07 20:46:14984 __atomic_base(const __atomic_base&) = delete;
985 __atomic_base& operator=(const __atomic_base&) = delete;
986 __atomic_base& operator=(const __atomic_base&) volatile = delete;
Eric Fiselier8eb066a2017-01-06 20:58:25987#else
Howard Hinnant770d1c42010-12-08 17:20:28988private:
989 __atomic_base(const __atomic_base&);
990 __atomic_base& operator=(const __atomic_base&);
991 __atomic_base& operator=(const __atomic_base&) volatile;
Eric Fiselier8eb066a2017-01-06 20:58:25992#endif
Howard Hinnant91e2f262010-12-07 20:46:14993};
994
JF Bastien08511cd2016-03-25 15:48:21995#if defined(__cpp_lib_atomic_is_always_lock_free)
996template <class _Tp, bool __b>
997_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
998#endif
999
Howard Hinnant91e2f262010-12-07 20:46:141000// atomic<Integral>
1001
1002template <class _Tp>
1003struct __atomic_base<_Tp, true>
1004 : public __atomic_base<_Tp, false>
1005{
1006 typedef __atomic_base<_Tp, false> __base;
1007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431008 __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211010 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant91e2f262010-12-07 20:46:141011
1012 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211013 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461014 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211016 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _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_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461020 {return __c11_atomic_fetch_sub(&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) _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_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461026 {return __c11_atomic_fetch_and(&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) _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_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461032 {return __c11_atomic_fetch_or(&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) _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_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461038 {return __c11_atomic_fetch_xor(&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) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461041 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141042
1043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211044 _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:141045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211046 _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:141047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211048 _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:141049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211050 _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant91e2f262010-12-07 20:46:141051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211052 _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:141053 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211054 _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:141055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211056 _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:141057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211058 _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant91e2f262010-12-07 20:46:141059 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211060 _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141061 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211062 _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141063 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211064 _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211066 _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211068 _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
Howard Hinnant91e2f262010-12-07 20:46:141069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211070 _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;}
Howard Hinnant91e2f262010-12-07 20:46:141071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211072 _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
Howard Hinnant91e2f262010-12-07 20:46:141073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211074 _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;}
Howard Hinnant91e2f262010-12-07 20:46:141075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211076 _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant91e2f262010-12-07 20:46:141077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211078 _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant91e2f262010-12-07 20:46:141079};
1080
1081// atomic<T>
1082
1083template <class _Tp>
1084struct atomic
1085 : public __atomic_base<_Tp>
1086{
1087 typedef __atomic_base<_Tp> __base;
1088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431089 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211091 _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnantd2f6afb2010-12-07 23:24:411092
1093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211094 _Tp operator=(_Tp __d) volatile _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411095 {__base::store(__d); return __d;}
1096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211097 _Tp operator=(_Tp __d) _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411098 {__base::store(__d); return __d;}
Howard Hinnant91e2f262010-12-07 20:46:141099};
1100
1101// atomic<T*>
1102
1103template <class _Tp>
1104struct atomic<_Tp*>
1105 : public __atomic_base<_Tp*>
1106{
Howard Hinnantd2f6afb2010-12-07 23:24:411107 typedef __atomic_base<_Tp*> __base;
Howard Hinnant91e2f262010-12-07 20:46:141108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant74f4da72013-05-02 20:18:431109 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant91e2f262010-12-07 20:46:141110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211111 _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant91e2f262010-12-07 20:46:141112
1113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211114 _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411115 {__base::store(__d); return __d;}
1116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211117 _Tp* operator=(_Tp* __d) _NOEXCEPT
Howard Hinnantd2f6afb2010-12-07 23:24:411118 {__base::store(__d); return __d;}
1119
1120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91e2f262010-12-07 20:46:141121 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnant300c67a2012-04-11 20:14:211122 volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461123 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211125 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _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
1128 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnant300c67a2012-04-11 20:14:211129 volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461130 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211132 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461133 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant91e2f262010-12-07 20:46:141134
1135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211136 _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
Howard Hinnant91e2f262010-12-07 20:46:141137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211138 _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);}
Howard Hinnant91e2f262010-12-07 20:46:141139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211140 _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant91e2f262010-12-07 20:46:141141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211142 _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant91e2f262010-12-07 20:46:141143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211144 _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant91e2f262010-12-07 20:46:141145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211146 _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant91e2f262010-12-07 20:46:141147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211148 _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant91e2f262010-12-07 20:46:141149 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211150 _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant91e2f262010-12-07 20:46:141151 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211152 _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211154 _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant91e2f262010-12-07 20:46:141155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211156 _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211158 _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant91e2f262010-12-07 20:46:141159};
Howard Hinnant4777bf22010-12-06 23:10:081160
1161// atomic_is_lock_free
1162
1163template <class _Tp>
1164inline _LIBCPP_INLINE_VISIBILITY
1165bool
Howard Hinnant300c67a2012-04-11 20:14:211166atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081167{
Howard Hinnant91e2f262010-12-07 20:46:141168 return __o->is_lock_free();
Howard Hinnant4777bf22010-12-06 23:10:081169}
1170
1171template <class _Tp>
1172inline _LIBCPP_INLINE_VISIBILITY
1173bool
Howard Hinnant300c67a2012-04-11 20:14:211174atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081175{
Howard Hinnant91e2f262010-12-07 20:46:141176 return __o->is_lock_free();
Howard Hinnant4777bf22010-12-06 23:10:081177}
1178
1179// atomic_init
1180
1181template <class _Tp>
1182inline _LIBCPP_INLINE_VISIBILITY
1183void
Howard Hinnant300c67a2012-04-11 20:14:211184atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081185{
Richard Smith6186c7f2012-04-11 18:55:461186 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant4777bf22010-12-06 23:10:081187}
1188
1189template <class _Tp>
1190inline _LIBCPP_INLINE_VISIBILITY
1191void
Howard Hinnant300c67a2012-04-11 20:14:211192atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081193{
Richard Smith6186c7f2012-04-11 18:55:461194 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant4777bf22010-12-06 23:10:081195}
1196
1197// atomic_store
1198
1199template <class _Tp>
1200inline _LIBCPP_INLINE_VISIBILITY
1201void
Howard Hinnant300c67a2012-04-11 20:14:211202atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081203{
Howard Hinnant91e2f262010-12-07 20:46:141204 __o->store(__d);
Howard Hinnant4777bf22010-12-06 23:10:081205}
1206
1207template <class _Tp>
1208inline _LIBCPP_INLINE_VISIBILITY
1209void
Howard Hinnant300c67a2012-04-11 20:14:211210atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081211{
Howard Hinnant91e2f262010-12-07 20:46:141212 __o->store(__d);
Howard Hinnant4777bf22010-12-06 23:10:081213}
1214
1215// atomic_store_explicit
1216
1217template <class _Tp>
1218inline _LIBCPP_INLINE_VISIBILITY
1219void
Howard Hinnant300c67a2012-04-11 20:14:211220atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391221 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081222{
Howard Hinnant91e2f262010-12-07 20:46:141223 __o->store(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081224}
1225
1226template <class _Tp>
1227inline _LIBCPP_INLINE_VISIBILITY
1228void
Howard Hinnant300c67a2012-04-11 20:14:211229atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391230 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081231{
Howard Hinnant91e2f262010-12-07 20:46:141232 __o->store(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081233}
1234
1235// atomic_load
1236
1237template <class _Tp>
1238inline _LIBCPP_INLINE_VISIBILITY
1239_Tp
Howard Hinnant300c67a2012-04-11 20:14:211240atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081241{
Howard Hinnant91e2f262010-12-07 20:46:141242 return __o->load();
Howard Hinnant4777bf22010-12-06 23:10:081243}
1244
1245template <class _Tp>
1246inline _LIBCPP_INLINE_VISIBILITY
1247_Tp
Howard Hinnant300c67a2012-04-11 20:14:211248atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081249{
Howard Hinnant91e2f262010-12-07 20:46:141250 return __o->load();
Howard Hinnant4777bf22010-12-06 23:10:081251}
1252
1253// atomic_load_explicit
1254
1255template <class _Tp>
1256inline _LIBCPP_INLINE_VISIBILITY
1257_Tp
Howard Hinnant300c67a2012-04-11 20:14:211258atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391259 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081260{
Howard Hinnant91e2f262010-12-07 20:46:141261 return __o->load(__m);
Howard Hinnant4777bf22010-12-06 23:10:081262}
1263
1264template <class _Tp>
1265inline _LIBCPP_INLINE_VISIBILITY
1266_Tp
Howard Hinnant300c67a2012-04-11 20:14:211267atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391268 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Howard Hinnant4777bf22010-12-06 23:10:081269{
Howard Hinnant91e2f262010-12-07 20:46:141270 return __o->load(__m);
Howard Hinnant4777bf22010-12-06 23:10:081271}
1272
1273// atomic_exchange
1274
1275template <class _Tp>
1276inline _LIBCPP_INLINE_VISIBILITY
1277_Tp
Howard Hinnant300c67a2012-04-11 20:14:211278atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081279{
Howard Hinnant91e2f262010-12-07 20:46:141280 return __o->exchange(__d);
Howard Hinnant4777bf22010-12-06 23:10:081281}
1282
1283template <class _Tp>
1284inline _LIBCPP_INLINE_VISIBILITY
1285_Tp
Howard Hinnant300c67a2012-04-11 20:14:211286atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081287{
Howard Hinnant91e2f262010-12-07 20:46:141288 return __o->exchange(__d);
Howard Hinnant4777bf22010-12-06 23:10:081289}
1290
1291// atomic_exchange_explicit
1292
1293template <class _Tp>
1294inline _LIBCPP_INLINE_VISIBILITY
1295_Tp
Howard Hinnant300c67a2012-04-11 20:14:211296atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081297{
Howard Hinnant91e2f262010-12-07 20:46:141298 return __o->exchange(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081299}
1300
1301template <class _Tp>
1302inline _LIBCPP_INLINE_VISIBILITY
1303_Tp
Howard Hinnant300c67a2012-04-11 20:14:211304atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081305{
Howard Hinnant91e2f262010-12-07 20:46:141306 return __o->exchange(__d, __m);
Howard Hinnant4777bf22010-12-06 23:10:081307}
1308
1309// atomic_compare_exchange_weak
1310
1311template <class _Tp>
1312inline _LIBCPP_INLINE_VISIBILITY
1313bool
Howard Hinnant300c67a2012-04-11 20:14:211314atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081315{
Howard Hinnant91e2f262010-12-07 20:46:141316 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081317}
1318
1319template <class _Tp>
1320inline _LIBCPP_INLINE_VISIBILITY
1321bool
Howard Hinnant300c67a2012-04-11 20:14:211322atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081323{
Howard Hinnant91e2f262010-12-07 20:46:141324 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081325}
1326
1327// atomic_compare_exchange_strong
1328
1329template <class _Tp>
1330inline _LIBCPP_INLINE_VISIBILITY
1331bool
Howard Hinnant300c67a2012-04-11 20:14:211332atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081333{
Howard Hinnant91e2f262010-12-07 20:46:141334 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081335}
1336
1337template <class _Tp>
1338inline _LIBCPP_INLINE_VISIBILITY
1339bool
Howard Hinnant300c67a2012-04-11 20:14:211340atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081341{
Howard Hinnant91e2f262010-12-07 20:46:141342 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant4777bf22010-12-06 23:10:081343}
1344
1345// atomic_compare_exchange_weak_explicit
1346
1347template <class _Tp>
1348inline _LIBCPP_INLINE_VISIBILITY
1349bool
1350atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
1351 _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211352 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391353 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081354{
Howard Hinnant91e2f262010-12-07 20:46:141355 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081356}
1357
1358template <class _Tp>
1359inline _LIBCPP_INLINE_VISIBILITY
1360bool
1361atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211362 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391363 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081364{
Howard Hinnant91e2f262010-12-07 20:46:141365 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081366}
1367
1368// atomic_compare_exchange_strong_explicit
1369
1370template <class _Tp>
1371inline _LIBCPP_INLINE_VISIBILITY
1372bool
1373atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
1374 _Tp* __e, _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211375 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391376 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081377{
Howard Hinnant91e2f262010-12-07 20:46:141378 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081379}
1380
1381template <class _Tp>
1382inline _LIBCPP_INLINE_VISIBILITY
1383bool
1384atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
1385 _Tp __d,
Howard Hinnant300c67a2012-04-11 20:14:211386 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselier5ed76752017-01-13 23:45:391387 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant4777bf22010-12-06 23:10:081388{
Howard Hinnant91e2f262010-12-07 20:46:141389 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant4777bf22010-12-06 23:10:081390}
1391
Howard Hinnant91e2f262010-12-07 20:46:141392// atomic_fetch_add
Howard Hinnant4777bf22010-12-06 23:10:081393
1394template <class _Tp>
Howard Hinnant91e2f262010-12-07 20:46:141395inline _LIBCPP_INLINE_VISIBILITY
1396typename enable_if
1397<
1398 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1399 _Tp
1400>::type
Howard Hinnant300c67a2012-04-11 20:14:211401atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant4777bf22010-12-06 23:10:081402{
Howard Hinnant91e2f262010-12-07 20:46:141403 return __o->fetch_add(__op);
1404}
Howard Hinnant4777bf22010-12-06 23:10:081405
Howard Hinnant91e2f262010-12-07 20:46:141406template <class _Tp>
1407inline _LIBCPP_INLINE_VISIBILITY
1408typename enable_if
1409<
1410 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1411 _Tp
1412>::type
Howard Hinnant300c67a2012-04-11 20:14:211413atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141414{
1415 return __o->fetch_add(__op);
1416}
Howard Hinnant4777bf22010-12-06 23:10:081417
Howard Hinnant91e2f262010-12-07 20:46:141418template <class _Tp>
1419inline _LIBCPP_INLINE_VISIBILITY
1420_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211421atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141422{
1423 return __o->fetch_add(__op);
1424}
1425
1426template <class _Tp>
1427inline _LIBCPP_INLINE_VISIBILITY
1428_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211429atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141430{
1431 return __o->fetch_add(__op);
1432}
1433
1434// atomic_fetch_add_explicit
1435
1436template <class _Tp>
1437inline _LIBCPP_INLINE_VISIBILITY
1438typename enable_if
1439<
1440 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1441 _Tp
1442>::type
Howard Hinnant300c67a2012-04-11 20:14:211443atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141444{
1445 return __o->fetch_add(__op, __m);
1446}
1447
1448template <class _Tp>
1449inline _LIBCPP_INLINE_VISIBILITY
1450typename enable_if
1451<
1452 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1453 _Tp
1454>::type
Howard Hinnant300c67a2012-04-11 20:14:211455atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141456{
1457 return __o->fetch_add(__op, __m);
1458}
1459
1460template <class _Tp>
1461inline _LIBCPP_INLINE_VISIBILITY
1462_Tp*
1463atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnant300c67a2012-04-11 20:14:211464 memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141465{
1466 return __o->fetch_add(__op, __m);
1467}
1468
1469template <class _Tp>
1470inline _LIBCPP_INLINE_VISIBILITY
1471_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211472atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141473{
1474 return __o->fetch_add(__op, __m);
1475}
1476
1477// atomic_fetch_sub
1478
1479template <class _Tp>
1480inline _LIBCPP_INLINE_VISIBILITY
1481typename enable_if
1482<
1483 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1484 _Tp
1485>::type
Howard Hinnant300c67a2012-04-11 20:14:211486atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141487{
1488 return __o->fetch_sub(__op);
1489}
1490
1491template <class _Tp>
1492inline _LIBCPP_INLINE_VISIBILITY
1493typename enable_if
1494<
1495 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1496 _Tp
1497>::type
Howard Hinnant300c67a2012-04-11 20:14:211498atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141499{
1500 return __o->fetch_sub(__op);
1501}
1502
1503template <class _Tp>
1504inline _LIBCPP_INLINE_VISIBILITY
1505_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211506atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141507{
1508 return __o->fetch_sub(__op);
1509}
1510
1511template <class _Tp>
1512inline _LIBCPP_INLINE_VISIBILITY
1513_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211514atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141515{
1516 return __o->fetch_sub(__op);
1517}
1518
1519// atomic_fetch_sub_explicit
1520
1521template <class _Tp>
1522inline _LIBCPP_INLINE_VISIBILITY
1523typename enable_if
1524<
1525 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1526 _Tp
1527>::type
Howard Hinnant300c67a2012-04-11 20:14:211528atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141529{
1530 return __o->fetch_sub(__op, __m);
1531}
1532
1533template <class _Tp>
1534inline _LIBCPP_INLINE_VISIBILITY
1535typename enable_if
1536<
1537 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1538 _Tp
1539>::type
Howard Hinnant300c67a2012-04-11 20:14:211540atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141541{
1542 return __o->fetch_sub(__op, __m);
1543}
1544
1545template <class _Tp>
1546inline _LIBCPP_INLINE_VISIBILITY
1547_Tp*
1548atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnant300c67a2012-04-11 20:14:211549 memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141550{
1551 return __o->fetch_sub(__op, __m);
1552}
1553
1554template <class _Tp>
1555inline _LIBCPP_INLINE_VISIBILITY
1556_Tp*
Howard Hinnant300c67a2012-04-11 20:14:211557atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141558{
1559 return __o->fetch_sub(__op, __m);
1560}
1561
1562// atomic_fetch_and
1563
1564template <class _Tp>
1565inline _LIBCPP_INLINE_VISIBILITY
1566typename enable_if
1567<
1568 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1569 _Tp
1570>::type
Howard Hinnant300c67a2012-04-11 20:14:211571atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141572{
1573 return __o->fetch_and(__op);
1574}
1575
1576template <class _Tp>
1577inline _LIBCPP_INLINE_VISIBILITY
1578typename enable_if
1579<
1580 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1581 _Tp
1582>::type
Howard Hinnant300c67a2012-04-11 20:14:211583atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141584{
1585 return __o->fetch_and(__op);
1586}
1587
1588// atomic_fetch_and_explicit
1589
1590template <class _Tp>
1591inline _LIBCPP_INLINE_VISIBILITY
1592typename enable_if
1593<
1594 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1595 _Tp
1596>::type
Howard Hinnant300c67a2012-04-11 20:14:211597atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141598{
1599 return __o->fetch_and(__op, __m);
1600}
1601
1602template <class _Tp>
1603inline _LIBCPP_INLINE_VISIBILITY
1604typename enable_if
1605<
1606 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1607 _Tp
1608>::type
Howard Hinnant300c67a2012-04-11 20:14:211609atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141610{
1611 return __o->fetch_and(__op, __m);
1612}
1613
1614// atomic_fetch_or
1615
1616template <class _Tp>
1617inline _LIBCPP_INLINE_VISIBILITY
1618typename enable_if
1619<
1620 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1621 _Tp
1622>::type
Howard Hinnant300c67a2012-04-11 20:14:211623atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141624{
1625 return __o->fetch_or(__op);
1626}
1627
1628template <class _Tp>
1629inline _LIBCPP_INLINE_VISIBILITY
1630typename enable_if
1631<
1632 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1633 _Tp
1634>::type
Howard Hinnant300c67a2012-04-11 20:14:211635atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141636{
1637 return __o->fetch_or(__op);
1638}
1639
1640// atomic_fetch_or_explicit
1641
1642template <class _Tp>
1643inline _LIBCPP_INLINE_VISIBILITY
1644typename enable_if
1645<
1646 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1647 _Tp
1648>::type
Howard Hinnant300c67a2012-04-11 20:14:211649atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141650{
1651 return __o->fetch_or(__op, __m);
1652}
1653
1654template <class _Tp>
1655inline _LIBCPP_INLINE_VISIBILITY
1656typename enable_if
1657<
1658 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1659 _Tp
1660>::type
Howard Hinnant300c67a2012-04-11 20:14:211661atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141662{
1663 return __o->fetch_or(__op, __m);
1664}
1665
1666// atomic_fetch_xor
1667
1668template <class _Tp>
1669inline _LIBCPP_INLINE_VISIBILITY
1670typename enable_if
1671<
1672 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1673 _Tp
1674>::type
Howard Hinnant300c67a2012-04-11 20:14:211675atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141676{
1677 return __o->fetch_xor(__op);
1678}
1679
1680template <class _Tp>
1681inline _LIBCPP_INLINE_VISIBILITY
1682typename enable_if
1683<
1684 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1685 _Tp
1686>::type
Howard Hinnant300c67a2012-04-11 20:14:211687atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141688{
1689 return __o->fetch_xor(__op);
1690}
1691
1692// atomic_fetch_xor_explicit
1693
1694template <class _Tp>
1695inline _LIBCPP_INLINE_VISIBILITY
1696typename enable_if
1697<
1698 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1699 _Tp
1700>::type
Howard Hinnant300c67a2012-04-11 20:14:211701atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141702{
1703 return __o->fetch_xor(__op, __m);
1704}
1705
1706template <class _Tp>
1707inline _LIBCPP_INLINE_VISIBILITY
1708typename enable_if
1709<
1710 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1711 _Tp
1712>::type
Howard Hinnant300c67a2012-04-11 20:14:211713atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant91e2f262010-12-07 20:46:141714{
1715 return __o->fetch_xor(__op, __m);
1716}
Howard Hinnant4777bf22010-12-06 23:10:081717
Howard Hinnant770d1c42010-12-08 17:20:281718// flag type and operations
1719
1720typedef struct atomic_flag
1721{
David Chisnall83b2c842011-12-19 11:44:201722 _Atomic(bool) __a_;
Howard Hinnant770d1c42010-12-08 17:20:281723
1724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211725 bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461726 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant300c67a2012-04-11 20:14:211728 bool test_and_set(memory_order __m = memory_order_seq_cst) _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 void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461732 {__c11_atomic_store(&__a_, false, __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) _NOEXCEPT
Richard Smith6186c7f2012-04-11 18:55:461735 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant770d1c42010-12-08 17:20:281736
1737 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8c570322016-11-18 06:42:171738#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:431739 atomic_flag() _NOEXCEPT = default;
1740#else
1741 atomic_flag() _NOEXCEPT : __a_() {}
Eric Fiselier8c570322016-11-18 06:42:171742#endif // _LIBCPP_CXX03_LANG
Howard Hinnant74f4da72013-05-02 20:18:431743
Howard Hinnant770d1c42010-12-08 17:20:281744 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier219406e2016-05-03 02:12:261745 atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
Howard Hinnant770d1c42010-12-08 17:20:281746
Eric Fiselier8eb066a2017-01-06 20:58:251747#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant770d1c42010-12-08 17:20:281748 atomic_flag(const atomic_flag&) = delete;
1749 atomic_flag& operator=(const atomic_flag&) = delete;
1750 atomic_flag& operator=(const atomic_flag&) volatile = delete;
Eric Fiselier8eb066a2017-01-06 20:58:251751#else
Howard Hinnant770d1c42010-12-08 17:20:281752private:
1753 atomic_flag(const atomic_flag&);
1754 atomic_flag& operator=(const atomic_flag&);
1755 atomic_flag& operator=(const atomic_flag&) volatile;
Eric Fiselier8eb066a2017-01-06 20:58:251756#endif
Howard Hinnant770d1c42010-12-08 17:20:281757} atomic_flag;
1758
1759inline _LIBCPP_INLINE_VISIBILITY
1760bool
Howard Hinnant300c67a2012-04-11 20:14:211761atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281762{
1763 return __o->test_and_set();
1764}
1765
1766inline _LIBCPP_INLINE_VISIBILITY
1767bool
Howard Hinnant300c67a2012-04-11 20:14:211768atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281769{
1770 return __o->test_and_set();
1771}
1772
1773inline _LIBCPP_INLINE_VISIBILITY
1774bool
Howard Hinnant300c67a2012-04-11 20:14:211775atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281776{
1777 return __o->test_and_set(__m);
1778}
1779
1780inline _LIBCPP_INLINE_VISIBILITY
1781bool
Howard Hinnant300c67a2012-04-11 20:14:211782atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281783{
1784 return __o->test_and_set(__m);
1785}
1786
1787inline _LIBCPP_INLINE_VISIBILITY
1788void
Howard Hinnant300c67a2012-04-11 20:14:211789atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281790{
1791 __o->clear();
1792}
1793
1794inline _LIBCPP_INLINE_VISIBILITY
1795void
Howard Hinnant300c67a2012-04-11 20:14:211796atomic_flag_clear(atomic_flag* __o) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281797{
1798 __o->clear();
1799}
1800
1801inline _LIBCPP_INLINE_VISIBILITY
1802void
Howard Hinnant300c67a2012-04-11 20:14:211803atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281804{
1805 __o->clear(__m);
1806}
1807
1808inline _LIBCPP_INLINE_VISIBILITY
1809void
Howard Hinnant300c67a2012-04-11 20:14:211810atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281811{
1812 __o->clear(__m);
1813}
1814
1815// fences
1816
1817inline _LIBCPP_INLINE_VISIBILITY
1818void
Howard Hinnant300c67a2012-04-11 20:14:211819atomic_thread_fence(memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281820{
Richard Smith6186c7f2012-04-11 18:55:461821 __c11_atomic_thread_fence(__m);
Howard Hinnant770d1c42010-12-08 17:20:281822}
1823
1824inline _LIBCPP_INLINE_VISIBILITY
1825void
Howard Hinnant300c67a2012-04-11 20:14:211826atomic_signal_fence(memory_order __m) _NOEXCEPT
Howard Hinnant770d1c42010-12-08 17:20:281827{
Richard Smith6186c7f2012-04-11 18:55:461828 __c11_atomic_signal_fence(__m);
Howard Hinnant770d1c42010-12-08 17:20:281829}
1830
Howard Hinnantd2f6afb2010-12-07 23:24:411831// Atomics for standard typedef types
1832
Howard Hinnant6ae47052013-01-04 18:58:501833typedef atomic<bool> atomic_bool;
Howard Hinnantd2f6afb2010-12-07 23:24:411834typedef atomic<char> atomic_char;
1835typedef atomic<signed char> atomic_schar;
1836typedef atomic<unsigned char> atomic_uchar;
1837typedef atomic<short> atomic_short;
1838typedef atomic<unsigned short> atomic_ushort;
1839typedef atomic<int> atomic_int;
1840typedef atomic<unsigned int> atomic_uint;
1841typedef atomic<long> atomic_long;
1842typedef atomic<unsigned long> atomic_ulong;
1843typedef atomic<long long> atomic_llong;
1844typedef atomic<unsigned long long> atomic_ullong;
1845typedef atomic<char16_t> atomic_char16_t;
1846typedef atomic<char32_t> atomic_char32_t;
1847typedef atomic<wchar_t> atomic_wchar_t;
1848
1849typedef atomic<int_least8_t> atomic_int_least8_t;
1850typedef atomic<uint_least8_t> atomic_uint_least8_t;
1851typedef atomic<int_least16_t> atomic_int_least16_t;
1852typedef atomic<uint_least16_t> atomic_uint_least16_t;
1853typedef atomic<int_least32_t> atomic_int_least32_t;
1854typedef atomic<uint_least32_t> atomic_uint_least32_t;
1855typedef atomic<int_least64_t> atomic_int_least64_t;
1856typedef atomic<uint_least64_t> atomic_uint_least64_t;
1857
1858typedef atomic<int_fast8_t> atomic_int_fast8_t;
1859typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
1860typedef atomic<int_fast16_t> atomic_int_fast16_t;
1861typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1862typedef atomic<int_fast32_t> atomic_int_fast32_t;
1863typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1864typedef atomic<int_fast64_t> atomic_int_fast64_t;
1865typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1866
Marshall Clowca894502016-06-30 15:28:381867typedef atomic< int8_t> atomic_int8_t;
1868typedef atomic<uint8_t> atomic_uint8_t;
1869typedef atomic< int16_t> atomic_int16_t;
1870typedef atomic<uint16_t> atomic_uint16_t;
1871typedef atomic< int32_t> atomic_int32_t;
1872typedef atomic<uint32_t> atomic_uint32_t;
1873typedef atomic< int64_t> atomic_int64_t;
1874typedef atomic<uint64_t> atomic_uint64_t;
1875
Howard Hinnantd2f6afb2010-12-07 23:24:411876typedef atomic<intptr_t> atomic_intptr_t;
1877typedef atomic<uintptr_t> atomic_uintptr_t;
1878typedef atomic<size_t> atomic_size_t;
1879typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1880typedef atomic<intmax_t> atomic_intmax_t;
1881typedef atomic<uintmax_t> atomic_uintmax_t;
1882
Howard Hinnant767ae2b2010-09-29 21:20:031883#define ATOMIC_FLAG_INIT {false}
Howard Hinnant611fdaf2010-10-04 18:52:541884#define ATOMIC_VAR_INIT(__v) {__v}
1885
Howard Hinnant8f73c632010-09-27 21:17:381886_LIBCPP_END_NAMESPACE_STD
1887
Howard Hinnant8f73c632010-09-27 21:17:381888#endif // _LIBCPP_ATOMIC