blob: a25b5bf8d7732a8b296faa4869454b1e32ca71e1 [file] [log] [blame]
Howard Hinnant71be7292010-09-27 21:17:38 +00001// -*- 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 Bastienfdb42c22016-03-25 15:48:21 +000020// feature test macro
21
22#define __cpp_lib_atomic_is_always_lock_free // as specified by SG10
23
Howard Hinnant71be7292010-09-27 21:17:38 +000024// order and consistency
25
26typedef enum memory_order
27{
Howard Hinnantdca6e712010-09-28 17:13:38 +000028 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 Hinnant71be7292010-09-27 21:17:38 +000034} memory_order;
35
Howard Hinnanteee2c142012-04-11 20:14:21 +000036template <class T> T kill_dependency(T y) noexcept;
Howard Hinnant71be7292010-09-27 21:17:38 +000037
38// lock-free property
39
Howard Hinnant931e3402013-01-21 20:39:41 +000040#define ATOMIC_BOOL_LOCK_FREE unspecified
Howard Hinnant71be7292010-09-27 21:17:38 +000041#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 Hinnant931e3402013-01-21 20:39:41 +000049#define ATOMIC_POINTER_LOCK_FREE unspecified
Howard Hinnant71be7292010-09-27 21:17:38 +000050
Howard Hinnant71be7292010-09-27 21:17:38 +000051// flag type and operations
52
53typedef struct atomic_flag
54{
Howard Hinnanteee2c142012-04-11 20:14:21 +000055 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 Hinnant71be7292010-09-27 21:17:38 +000060 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 Hinnant7bfaeb82010-12-06 23:10:08 +000065bool
Howard Hinnanteee2c142012-04-11 20:14:21 +000066 atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +000067
68bool
Howard Hinnanteee2c142012-04-11 20:14:21 +000069 atomic_flag_test_and_set(atomic_flag* obj) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +000070
71bool
72 atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
Howard Hinnanteee2c142012-04-11 20:14:21 +000073 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +000074
75bool
Howard Hinnanteee2c142012-04-11 20:14:21 +000076 atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +000077
78void
Howard Hinnanteee2c142012-04-11 20:14:21 +000079 atomic_flag_clear(volatile atomic_flag* obj) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +000080
81void
Howard Hinnanteee2c142012-04-11 20:14:21 +000082 atomic_flag_clear(atomic_flag* obj) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +000083
84void
Howard Hinnanteee2c142012-04-11 20:14:21 +000085 atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +000086
87void
Howard Hinnanteee2c142012-04-11 20:14:21 +000088 atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
Howard Hinnant71be7292010-09-27 21:17:38 +000089
90#define ATOMIC_FLAG_INIT see below
Howard Hinnant493d1d92010-10-19 16:51:18 +000091#define ATOMIC_VAR_INIT(value) see below
Howard Hinnant71be7292010-09-27 21:17:38 +000092
Howard Hinnant71be7292010-09-27 21:17:38 +000093template <class T>
94struct atomic
95{
JF Bastienfdb42c22016-03-25 15:48:21 +000096 static constexpr bool is_always_lock_free;
Howard Hinnanteee2c142012-04-11 20:14:21 +000097 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 Hinnant7bfaeb82010-12-06 23:10:08 +0000107 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000108 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 Hinnant7bfaeb82010-12-06 23:10:08 +0000110 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000111 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000112 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000113 memory_order s, memory_order f) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000114 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000115 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000116 bool compare_exchange_weak(T& expc, T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000117 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000118 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000119 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000120 bool compare_exchange_strong(T& expc, T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000121 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant71be7292010-09-27 21:17:38 +0000122
Howard Hinnanteee2c142012-04-11 20:14:21 +0000123 atomic() noexcept = default;
124 constexpr atomic(T desr) noexcept;
Howard Hinnant71be7292010-09-27 21:17:38 +0000125 atomic(const atomic&) = delete;
126 atomic& operator=(const atomic&) = delete;
127 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnanteee2c142012-04-11 20:14:21 +0000128 T operator=(T) volatile noexcept;
129 T operator=(T) noexcept;
Howard Hinnant71be7292010-09-27 21:17:38 +0000130};
131
132template <>
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000133struct atomic<integral>
Howard Hinnant71be7292010-09-27 21:17:38 +0000134{
JF Bastienfdb42c22016-03-25 15:48:21 +0000135 static constexpr bool is_always_lock_free;
Howard Hinnanteee2c142012-04-11 20:14:21 +0000136 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 Hinnant7bfaeb82010-12-06 23:10:08 +0000144 integral exchange(integral desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000145 memory_order m = memory_order_seq_cst) volatile noexcept;
146 integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000147 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000148 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000149 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000150 memory_order s, memory_order f) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000151 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000152 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000153 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000154 memory_order s, memory_order f) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000155 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000156 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000157 bool compare_exchange_weak(integral& expc, integral desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000158 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000159 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000160 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000161 bool compare_exchange_strong(integral& expc, integral desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000162 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant71be7292010-09-27 21:17:38 +0000163
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000164 integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000165 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 Hinnant7bfaeb82010-12-06 23:10:08 +0000167 integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000168 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 Hinnant7bfaeb82010-12-06 23:10:08 +0000170 integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000171 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 Hinnant7bfaeb82010-12-06 23:10:08 +0000173 integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000174 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 Hinnant7bfaeb82010-12-06 23:10:08 +0000176 integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000177 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 Hinnant71be7292010-09-27 21:17:38 +0000179
Howard Hinnanteee2c142012-04-11 20:14:21 +0000180 atomic() noexcept = default;
181 constexpr atomic(integral desr) noexcept;
Howard Hinnant71be7292010-09-27 21:17:38 +0000182 atomic(const atomic&) = delete;
183 atomic& operator=(const atomic&) = delete;
184 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnanteee2c142012-04-11 20:14:21 +0000185 integral operator=(integral desr) volatile noexcept;
186 integral operator=(integral desr) noexcept;
Howard Hinnant71be7292010-09-27 21:17:38 +0000187
Howard Hinnanteee2c142012-04-11 20:14:21 +0000188 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 Hinnant71be7292010-09-27 21:17:38 +0000206};
207
208template <class T>
209struct atomic<T*>
Howard Hinnant71be7292010-09-27 21:17:38 +0000210{
JF Bastienfdb42c22016-03-25 15:48:21 +0000211 static constexpr bool is_always_lock_free;
Howard Hinnanteee2c142012-04-11 20:14:21 +0000212 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 Hinnant7bfaeb82010-12-06 23:10:08 +0000222 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000223 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000224 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000225 memory_order s, memory_order f) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000226 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000227 memory_order s, memory_order f) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000228 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000229 memory_order s, memory_order f) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000230 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000231 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000232 bool compare_exchange_weak(T*& expc, T* desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000233 memory_order m = memory_order_seq_cst) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000234 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000235 memory_order m = memory_order_seq_cst) volatile noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000236 bool compare_exchange_strong(T*& expc, T* desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000237 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 Hinnant7bfaeb82010-12-06 23:10:08 +0000242
Howard Hinnanteee2c142012-04-11 20:14:21 +0000243 atomic() noexcept = default;
244 constexpr atomic(T* desr) noexcept;
Howard Hinnant71be7292010-09-27 21:17:38 +0000245 atomic(const atomic&) = delete;
246 atomic& operator=(const atomic&) = delete;
247 atomic& operator=(const atomic&) volatile = delete;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000248
Howard Hinnanteee2c142012-04-11 20:14:21 +0000249 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 Hinnant71be7292010-09-27 21:17:38 +0000263};
264
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000265
266template <class T>
267 bool
Howard Hinnanteee2c142012-04-11 20:14:21 +0000268 atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000269
270template <class T>
271 bool
Howard Hinnanteee2c142012-04-11 20:14:21 +0000272 atomic_is_lock_free(const atomic<T>* obj) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000273
274template <class T>
275 void
Howard Hinnanteee2c142012-04-11 20:14:21 +0000276 atomic_init(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000277
278template <class T>
279 void
Howard Hinnanteee2c142012-04-11 20:14:21 +0000280 atomic_init(atomic<T>* obj, T desr) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000281
282template <class T>
283 void
Howard Hinnanteee2c142012-04-11 20:14:21 +0000284 atomic_store(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000285
286template <class T>
287 void
Howard Hinnanteee2c142012-04-11 20:14:21 +0000288 atomic_store(atomic<T>* obj, T desr) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000289
290template <class T>
291 void
Howard Hinnanteee2c142012-04-11 20:14:21 +0000292 atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000293
294template <class T>
295 void
Howard Hinnanteee2c142012-04-11 20:14:21 +0000296 atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000297
298template <class T>
299 T
Howard Hinnanteee2c142012-04-11 20:14:21 +0000300 atomic_load(const volatile atomic<T>* obj) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000301
302template <class T>
303 T
Howard Hinnanteee2c142012-04-11 20:14:21 +0000304 atomic_load(const atomic<T>* obj) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000305
306template <class T>
307 T
Howard Hinnanteee2c142012-04-11 20:14:21 +0000308 atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000309
310template <class T>
311 T
Howard Hinnanteee2c142012-04-11 20:14:21 +0000312 atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000313
314template <class T>
315 T
Howard Hinnanteee2c142012-04-11 20:14:21 +0000316 atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000317
318template <class T>
319 T
Howard Hinnanteee2c142012-04-11 20:14:21 +0000320 atomic_exchange(atomic<T>* obj, T desr) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000321
322template <class T>
323 T
Howard Hinnanteee2c142012-04-11 20:14:21 +0000324 atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000325
326template <class T>
327 T
Howard Hinnanteee2c142012-04-11 20:14:21 +0000328 atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000329
330template <class T>
331 bool
Howard Hinnanteee2c142012-04-11 20:14:21 +0000332 atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000333
334template <class T>
335 bool
Howard Hinnanteee2c142012-04-11 20:14:21 +0000336 atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000337
338template <class T>
339 bool
Howard Hinnanteee2c142012-04-11 20:14:21 +0000340 atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000341
342template <class T>
343 bool
Howard Hinnanteee2c142012-04-11 20:14:21 +0000344 atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000345
346template <class T>
347 bool
348 atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
349 T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000350 memory_order s, memory_order f) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000351
352template <class T>
353 bool
354 atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000355 memory_order s, memory_order f) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000356
357template <class T>
358 bool
359 atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
360 T* expc, T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000361 memory_order s, memory_order f) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000362
363template <class T>
364 bool
365 atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
366 T desr,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000367 memory_order s, memory_order f) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000368
369template <class Integral>
370 Integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000371 atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000372
373template <class Integral>
374 Integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000375 atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000376
377template <class Integral>
378 Integral
379 atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000380 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000381template <class Integral>
382 Integral
383 atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000384 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000385template <class Integral>
386 Integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000387 atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000388
389template <class Integral>
390 Integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000391 atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000392
393template <class Integral>
394 Integral
395 atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000396 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000397template <class Integral>
398 Integral
399 atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000400 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000401template <class Integral>
402 Integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000403 atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000404
405template <class Integral>
406 Integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000407 atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000408
409template <class Integral>
410 Integral
411 atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000412 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000413template <class Integral>
414 Integral
415 atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000416 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000417template <class Integral>
418 Integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000419 atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000420
421template <class Integral>
422 Integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000423 atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000424
425template <class Integral>
426 Integral
427 atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000428 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000429template <class Integral>
430 Integral
431 atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000432 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000433template <class Integral>
434 Integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000435 atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000436
437template <class Integral>
438 Integral
Howard Hinnanteee2c142012-04-11 20:14:21 +0000439 atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000440
441template <class Integral>
442 Integral
443 atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000444 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000445template <class Integral>
446 Integral
447 atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000448 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000449
450template <class T>
451 T*
Howard Hinnanteee2c142012-04-11 20:14:21 +0000452 atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000453
454template <class T>
455 T*
Howard Hinnanteee2c142012-04-11 20:14:21 +0000456 atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000457
458template <class T>
459 T*
460 atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000461 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000462template <class T>
463 T*
Howard Hinnanteee2c142012-04-11 20:14:21 +0000464 atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000465
466template <class T>
467 T*
Howard Hinnanteee2c142012-04-11 20:14:21 +0000468 atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000469
470template <class T>
471 T*
Howard Hinnanteee2c142012-04-11 20:14:21 +0000472 atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000473
474template <class T>
475 T*
476 atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000477 memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000478template <class T>
479 T*
Howard Hinnanteee2c142012-04-11 20:14:21 +0000480 atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000481
482// Atomics for standard typedef types
483
Howard Hinnantf0af8d92013-01-04 18:58:50 +0000484typedef atomic<bool> atomic_bool;
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000485typedef 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 Clowf710afc2016-06-30 15:28:38 +0000518typedef 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 Hinnant7bfaeb82010-12-06 23:10:08 +0000527typedef 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 Hinnant71be7292010-09-27 21:17:38 +0000534// fences
535
Howard Hinnanteee2c142012-04-11 20:14:21 +0000536void atomic_thread_fence(memory_order m) noexcept;
537void atomic_signal_fence(memory_order m) noexcept;
Howard Hinnant71be7292010-09-27 21:17:38 +0000538
539} // std
540
541*/
542
543#include <__config>
Howard Hinnant7bfaeb82010-12-06 23:10:08 +0000544#include <cstddef>
545#include <cstdint>
546#include <type_traits>
Howard Hinnant71be7292010-09-27 21:17:38 +0000547
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000548#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant71be7292010-09-27 21:17:38 +0000549#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000550#endif
Howard Hinnant71be7292010-09-27 21:17:38 +0000551
Jonathan Roelofs39cb6bf2014-09-05 19:45:05 +0000552#ifdef _LIBCPP_HAS_NO_THREADS
553#error <atomic> is not supported on this single threaded system
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000554#endif
555#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
556#error <atomic> is not implemented
557#endif
Jonathan Roelofs39cb6bf2014-09-05 19:45:05 +0000558
JF Bastienfdb42c22016-03-25 15:48:21 +0000559#if _LIBCPP_STD_VER > 14
JF Bastienfdb42c22016-03-25 15:48:21 +0000560# define __cpp_lib_atomic_is_always_lock_free 201603L
561#endif
562
Howard Hinnant71be7292010-09-27 21:17:38 +0000563_LIBCPP_BEGIN_NAMESPACE_STD
564
Howard Hinnantdca6e712010-09-28 17:13:38 +0000565typedef enum memory_order
566{
567 memory_order_relaxed, memory_order_consume, memory_order_acquire,
568 memory_order_release, memory_order_acq_rel, memory_order_seq_cst
569} memory_order;
570
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000571#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
Dan Albert7b65ace2014-08-09 23:51:51 +0000572namespace __gcc_atomic {
Marshall Clow290eb3f2015-01-11 06:15:59 +0000573template <typename _Tp>
Dan Albert7b65ace2014-08-09 23:51:51 +0000574struct __gcc_atomic_t {
Eric Fiselier88f07122015-12-15 00:32:21 +0000575
576#if _GNUC_VER >= 501
577 static_assert(is_trivially_copyable<_Tp>::value,
578 "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
579#endif
580
Eric Fiselier684aaca2015-10-14 08:36:22 +0000581 _LIBCPP_INLINE_VISIBILITY
582#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
583 __gcc_atomic_t() _NOEXCEPT = default;
584#else
585 __gcc_atomic_t() _NOEXCEPT : __a_value() {}
586#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
Eric Fiselier719e0442015-07-14 17:50:27 +0000587 _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT
588 : __a_value(value) {}
Marshall Clow290eb3f2015-01-11 06:15:59 +0000589 _Tp __a_value;
Dan Albert7b65ace2014-08-09 23:51:51 +0000590};
591#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>
592
Marshall Clow290eb3f2015-01-11 06:15:59 +0000593template <typename _Tp> _Tp __create();
Dan Albert7b65ace2014-08-09 23:51:51 +0000594
Marshall Clow290eb3f2015-01-11 06:15:59 +0000595template <typename _Tp, typename _Td>
596typename enable_if<sizeof(_Tp()->__a_value = __create<_Td>()), char>::type
Dan Albert7b65ace2014-08-09 23:51:51 +0000597 __test_atomic_assignable(int);
Marshall Clow290eb3f2015-01-11 06:15:59 +0000598template <typename _Tp, typename _Up>
Dan Albert7b65ace2014-08-09 23:51:51 +0000599__two __test_atomic_assignable(...);
600
Marshall Clow290eb3f2015-01-11 06:15:59 +0000601template <typename _Tp, typename _Td>
Dan Albert7b65ace2014-08-09 23:51:51 +0000602struct __can_assign {
603 static const bool value =
Marshall Clow290eb3f2015-01-11 06:15:59 +0000604 sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char);
Dan Albert7b65ace2014-08-09 23:51:51 +0000605};
606
Eric Fiselier684aaca2015-10-14 08:36:22 +0000607static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
Dan Albert7b65ace2014-08-09 23:51:51 +0000608 // Avoid switch statement to make this a constexpr.
609 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
610 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
611 (__order == memory_order_release ? __ATOMIC_RELEASE:
612 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
613 (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
614 __ATOMIC_CONSUME))));
615}
616
Eric Fiselier684aaca2015-10-14 08:36:22 +0000617static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
Dan Albert48815f22015-01-06 18:39:37 +0000618 // Avoid switch statement to make this a constexpr.
619 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
620 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
621 (__order == memory_order_release ? __ATOMIC_RELAXED:
622 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
623 (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE:
624 __ATOMIC_CONSUME))));
625}
626
Dan Albert7b65ace2014-08-09 23:51:51 +0000627} // namespace __gcc_atomic
628
629template <typename _Tp>
630static inline
631typename enable_if<
632 __gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value>::type
633__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
634 __a->__a_value = __val;
635}
636
637template <typename _Tp>
638static inline
639typename enable_if<
640 !__gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value &&
641 __gcc_atomic::__can_assign< _Atomic(_Tp)*, _Tp>::value>::type
642__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
643 // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
644 // the default operator= in an object is not volatile, a byte-by-byte copy
645 // is required.
646 volatile char* to = reinterpret_cast<volatile char*>(&__a->__a_value);
647 volatile char* end = to + sizeof(_Tp);
648 char* from = reinterpret_cast<char*>(&__val);
649 while (to != end) {
650 *to++ = *from++;
651 }
652}
653
654template <typename _Tp>
655static inline void __c11_atomic_init(_Atomic(_Tp)* __a, _Tp __val) {
656 __a->__a_value = __val;
657}
658
659static inline void __c11_atomic_thread_fence(memory_order __order) {
660 __atomic_thread_fence(__gcc_atomic::__to_gcc_order(__order));
661}
662
663static inline void __c11_atomic_signal_fence(memory_order __order) {
664 __atomic_signal_fence(__gcc_atomic::__to_gcc_order(__order));
665}
666
Dan Albert7b65ace2014-08-09 23:51:51 +0000667template <typename _Tp>
668static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a, _Tp __val,
669 memory_order __order) {
670 return __atomic_store(&__a->__a_value, &__val,
671 __gcc_atomic::__to_gcc_order(__order));
672}
673
674template <typename _Tp>
675static inline void __c11_atomic_store(_Atomic(_Tp)* __a, _Tp __val,
676 memory_order __order) {
Dan Albert48815f22015-01-06 18:39:37 +0000677 __atomic_store(&__a->__a_value, &__val,
678 __gcc_atomic::__to_gcc_order(__order));
Dan Albert7b65ace2014-08-09 23:51:51 +0000679}
680
681template <typename _Tp>
682static inline _Tp __c11_atomic_load(volatile _Atomic(_Tp)* __a,
683 memory_order __order) {
684 _Tp __ret;
685 __atomic_load(&__a->__a_value, &__ret,
686 __gcc_atomic::__to_gcc_order(__order));
687 return __ret;
688}
689
690template <typename _Tp>
691static inline _Tp __c11_atomic_load(_Atomic(_Tp)* __a, memory_order __order) {
692 _Tp __ret;
693 __atomic_load(&__a->__a_value, &__ret,
694 __gcc_atomic::__to_gcc_order(__order));
695 return __ret;
696}
697
698template <typename _Tp>
699static inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a,
700 _Tp __value, memory_order __order) {
701 _Tp __ret;
702 __atomic_exchange(&__a->__a_value, &__value, &__ret,
703 __gcc_atomic::__to_gcc_order(__order));
704 return __ret;
705}
706
707template <typename _Tp>
708static inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value,
709 memory_order __order) {
710 _Tp __ret;
711 __atomic_exchange(&__a->__a_value, &__value, &__ret,
712 __gcc_atomic::__to_gcc_order(__order));
713 return __ret;
714}
715
716template <typename _Tp>
717static inline bool __c11_atomic_compare_exchange_strong(
718 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
719 memory_order __success, memory_order __failure) {
720 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
721 false,
722 __gcc_atomic::__to_gcc_order(__success),
Dan Albert48815f22015-01-06 18:39:37 +0000723 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Albert7b65ace2014-08-09 23:51:51 +0000724}
725
726template <typename _Tp>
727static inline bool __c11_atomic_compare_exchange_strong(
728 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
729 memory_order __failure) {
730 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
731 false,
732 __gcc_atomic::__to_gcc_order(__success),
Dan Albert48815f22015-01-06 18:39:37 +0000733 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Albert7b65ace2014-08-09 23:51:51 +0000734}
735
736template <typename _Tp>
737static inline bool __c11_atomic_compare_exchange_weak(
738 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
739 memory_order __success, memory_order __failure) {
740 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
741 true,
742 __gcc_atomic::__to_gcc_order(__success),
Dan Albert48815f22015-01-06 18:39:37 +0000743 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Albert7b65ace2014-08-09 23:51:51 +0000744}
745
746template <typename _Tp>
747static inline bool __c11_atomic_compare_exchange_weak(
748 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
749 memory_order __failure) {
750 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
751 true,
752 __gcc_atomic::__to_gcc_order(__success),
Dan Albert48815f22015-01-06 18:39:37 +0000753 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Albert7b65ace2014-08-09 23:51:51 +0000754}
755
756template <typename _Tp>
757struct __skip_amt { enum {value = 1}; };
758
759template <typename _Tp>
760struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
761
762// FIXME: Haven't figured out what the spec says about using arrays with
763// atomic_fetch_add. Force a failure rather than creating bad behavior.
764template <typename _Tp>
765struct __skip_amt<_Tp[]> { };
766template <typename _Tp, int n>
767struct __skip_amt<_Tp[n]> { };
768
769template <typename _Tp, typename _Td>
770static inline _Tp __c11_atomic_fetch_add(volatile _Atomic(_Tp)* __a,
771 _Td __delta, memory_order __order) {
772 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
773 __gcc_atomic::__to_gcc_order(__order));
774}
775
776template <typename _Tp, typename _Td>
777static inline _Tp __c11_atomic_fetch_add(_Atomic(_Tp)* __a, _Td __delta,
778 memory_order __order) {
779 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
780 __gcc_atomic::__to_gcc_order(__order));
781}
782
783template <typename _Tp, typename _Td>
784static inline _Tp __c11_atomic_fetch_sub(volatile _Atomic(_Tp)* __a,
785 _Td __delta, memory_order __order) {
786 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
787 __gcc_atomic::__to_gcc_order(__order));
788}
789
790template <typename _Tp, typename _Td>
791static inline _Tp __c11_atomic_fetch_sub(_Atomic(_Tp)* __a, _Td __delta,
792 memory_order __order) {
793 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
794 __gcc_atomic::__to_gcc_order(__order));
795}
796
797template <typename _Tp>
798static inline _Tp __c11_atomic_fetch_and(volatile _Atomic(_Tp)* __a,
799 _Tp __pattern, memory_order __order) {
800 return __atomic_fetch_and(&__a->__a_value, __pattern,
801 __gcc_atomic::__to_gcc_order(__order));
802}
803
804template <typename _Tp>
805static inline _Tp __c11_atomic_fetch_and(_Atomic(_Tp)* __a,
806 _Tp __pattern, memory_order __order) {
807 return __atomic_fetch_and(&__a->__a_value, __pattern,
808 __gcc_atomic::__to_gcc_order(__order));
809}
810
811template <typename _Tp>
812static inline _Tp __c11_atomic_fetch_or(volatile _Atomic(_Tp)* __a,
813 _Tp __pattern, memory_order __order) {
814 return __atomic_fetch_or(&__a->__a_value, __pattern,
815 __gcc_atomic::__to_gcc_order(__order));
816}
817
818template <typename _Tp>
819static inline _Tp __c11_atomic_fetch_or(_Atomic(_Tp)* __a, _Tp __pattern,
820 memory_order __order) {
821 return __atomic_fetch_or(&__a->__a_value, __pattern,
822 __gcc_atomic::__to_gcc_order(__order));
823}
824
825template <typename _Tp>
826static inline _Tp __c11_atomic_fetch_xor(volatile _Atomic(_Tp)* __a,
827 _Tp __pattern, memory_order __order) {
828 return __atomic_fetch_xor(&__a->__a_value, __pattern,
829 __gcc_atomic::__to_gcc_order(__order));
830}
831
832template <typename _Tp>
833static inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern,
834 memory_order __order) {
835 return __atomic_fetch_xor(&__a->__a_value, __pattern,
836 __gcc_atomic::__to_gcc_order(__order));
837}
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000838#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP
Dan Albert7b65ace2014-08-09 23:51:51 +0000839
Howard Hinnantdca6e712010-09-28 17:13:38 +0000840template <class _Tp>
841inline _LIBCPP_INLINE_VISIBILITY
842_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +0000843kill_dependency(_Tp __y) _NOEXCEPT
Howard Hinnantdca6e712010-09-28 17:13:38 +0000844{
845 return __y;
846}
Howard Hinnant71be7292010-09-27 21:17:38 +0000847
JF Bastienfdb42c22016-03-25 15:48:21 +0000848#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
849#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
850#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
851#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
852#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
853#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
854#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
855#define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
856#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
857#define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
858
Howard Hinnant138f5922010-12-07 20:46:14 +0000859// general atomic<T>
860
861template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
862struct __atomic_base // false
863{
Howard Hinnantd5eebd62012-09-16 20:33:09 +0000864 mutable _Atomic(_Tp) __a_;
Howard Hinnant138f5922010-12-07 20:46:14 +0000865
JF Bastienfdb42c22016-03-25 15:48:21 +0000866#if defined(__cpp_lib_atomic_is_always_lock_free)
867 static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0);
868#endif
869
Howard Hinnant138f5922010-12-07 20:46:14 +0000870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000871 bool is_lock_free() const volatile _NOEXCEPT
Eric Fiselier3fd22c22015-06-13 00:23:07 +0000872 {
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000873#if defined(_LIBCPP_HAS_C_ATOMIC_IMP)
Eric Fiselier3fd22c22015-06-13 00:23:07 +0000874 return __c11_atomic_is_lock_free(sizeof(_Tp));
875#else
876 return __atomic_is_lock_free(sizeof(_Tp), 0);
877#endif
878 }
Howard Hinnant138f5922010-12-07 20:46:14 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000880 bool is_lock_free() const _NOEXCEPT
Eric Fiselier3fd22c22015-06-13 00:23:07 +0000881 {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();}
Howard Hinnant138f5922010-12-07 20:46:14 +0000882 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000883 void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000884 {__c11_atomic_store(&__a_, __d, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000886 void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000887 {__c11_atomic_store(&__a_, __d, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000889 _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000890 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000892 _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000893 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000895 operator _Tp() const volatile _NOEXCEPT {return load();}
Howard Hinnant138f5922010-12-07 20:46:14 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000897 operator _Tp() const _NOEXCEPT {return load();}
Howard Hinnant138f5922010-12-07 20:46:14 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000899 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000900 {return __c11_atomic_exchange(&__a_, __d, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000902 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000903 {return __c11_atomic_exchange(&__a_, __d, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000904 _LIBCPP_INLINE_VISIBILITY
905 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000906 memory_order __s, memory_order __f) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000907 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000908 _LIBCPP_INLINE_VISIBILITY
909 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000910 memory_order __s, memory_order __f) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000911 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000912 _LIBCPP_INLINE_VISIBILITY
913 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000914 memory_order __s, memory_order __f) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000915 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000916 _LIBCPP_INLINE_VISIBILITY
917 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000918 memory_order __s, memory_order __f) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000919 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000920 _LIBCPP_INLINE_VISIBILITY
921 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000922 memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000923 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000924 _LIBCPP_INLINE_VISIBILITY
925 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000926 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000927 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000928 _LIBCPP_INLINE_VISIBILITY
929 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000930 memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000931 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000932 _LIBCPP_INLINE_VISIBILITY
933 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000934 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000935 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000936
937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3d284222013-05-02 20:18:43 +0000938#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
939 __atomic_base() _NOEXCEPT = default;
940#else
941 __atomic_base() _NOEXCEPT : __a_() {}
942#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
943
Howard Hinnant138f5922010-12-07 20:46:14 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000945 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
Howard Hinnant6ac60f82010-12-08 17:20:28 +0000946#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
Howard Hinnant138f5922010-12-07 20:46:14 +0000947 __atomic_base(const __atomic_base&) = delete;
948 __atomic_base& operator=(const __atomic_base&) = delete;
949 __atomic_base& operator=(const __atomic_base&) volatile = delete;
Howard Hinnant6ac60f82010-12-08 17:20:28 +0000950#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
951private:
952 __atomic_base(const __atomic_base&);
953 __atomic_base& operator=(const __atomic_base&);
954 __atomic_base& operator=(const __atomic_base&) volatile;
955#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
Howard Hinnant138f5922010-12-07 20:46:14 +0000956};
957
JF Bastienfdb42c22016-03-25 15:48:21 +0000958#if defined(__cpp_lib_atomic_is_always_lock_free)
959template <class _Tp, bool __b>
960_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
961#endif
962
Howard Hinnant138f5922010-12-07 20:46:14 +0000963// atomic<Integral>
964
965template <class _Tp>
966struct __atomic_base<_Tp, true>
967 : public __atomic_base<_Tp, false>
968{
969 typedef __atomic_base<_Tp, false> __base;
970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3d284222013-05-02 20:18:43 +0000971 __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant138f5922010-12-07 20:46:14 +0000972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000973 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant138f5922010-12-07 20:46:14 +0000974
975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000976 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000977 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000979 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000980 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000982 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000983 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000985 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000986 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000988 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000989 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000991 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000992 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000994 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000995 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000997 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000998 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001000 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001001 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001003 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001004 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001005
1006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001007 _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));}
Howard Hinnant138f5922010-12-07 20:46:14 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001009 _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));}
Howard Hinnant138f5922010-12-07 20:46:14 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001011 _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant138f5922010-12-07 20:46:14 +00001012 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001013 _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant138f5922010-12-07 20:46:14 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001015 _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001016 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001017 _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001019 _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001021 _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001023 _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001025 _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001026 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001027 _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001028 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001029 _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001031 _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001033 _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001035 _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001037 _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001039 _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001040 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001041 _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001042};
1043
1044// atomic<T>
1045
1046template <class _Tp>
1047struct atomic
1048 : public __atomic_base<_Tp>
1049{
1050 typedef __atomic_base<_Tp> __base;
1051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3d284222013-05-02 20:18:43 +00001052 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant138f5922010-12-07 20:46:14 +00001053 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001054 _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001055
1056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001057 _Tp operator=(_Tp __d) volatile _NOEXCEPT
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001058 {__base::store(__d); return __d;}
1059 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001060 _Tp operator=(_Tp __d) _NOEXCEPT
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001061 {__base::store(__d); return __d;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001062};
1063
1064// atomic<T*>
1065
1066template <class _Tp>
1067struct atomic<_Tp*>
1068 : public __atomic_base<_Tp*>
1069{
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001070 typedef __atomic_base<_Tp*> __base;
Howard Hinnant138f5922010-12-07 20:46:14 +00001071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3d284222013-05-02 20:18:43 +00001072 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant138f5922010-12-07 20:46:14 +00001073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001074 _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant138f5922010-12-07 20:46:14 +00001075
1076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001077 _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001078 {__base::store(__d); return __d;}
1079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001080 _Tp* operator=(_Tp* __d) _NOEXCEPT
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001081 {__base::store(__d); return __d;}
1082
1083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant138f5922010-12-07 20:46:14 +00001084 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnanteee2c142012-04-11 20:14:21 +00001085 volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001086 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001088 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001089 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001090 _LIBCPP_INLINE_VISIBILITY
1091 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnanteee2c142012-04-11 20:14:21 +00001092 volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001093 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001095 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001096 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001097
1098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001099 _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001101 _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001103 _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001104 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001105 _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001107 _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001109 _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001111 _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001113 _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001115 _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001117 _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001119 _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001121 _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001122};
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001123
1124// atomic_is_lock_free
1125
1126template <class _Tp>
1127inline _LIBCPP_INLINE_VISIBILITY
1128bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001129atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001130{
Howard Hinnant138f5922010-12-07 20:46:14 +00001131 return __o->is_lock_free();
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001132}
1133
1134template <class _Tp>
1135inline _LIBCPP_INLINE_VISIBILITY
1136bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001137atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001138{
Howard Hinnant138f5922010-12-07 20:46:14 +00001139 return __o->is_lock_free();
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001140}
1141
1142// atomic_init
1143
1144template <class _Tp>
1145inline _LIBCPP_INLINE_VISIBILITY
1146void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001147atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001148{
Richard Smith27a4a972012-04-11 18:55:46 +00001149 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001150}
1151
1152template <class _Tp>
1153inline _LIBCPP_INLINE_VISIBILITY
1154void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001155atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001156{
Richard Smith27a4a972012-04-11 18:55:46 +00001157 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001158}
1159
1160// atomic_store
1161
1162template <class _Tp>
1163inline _LIBCPP_INLINE_VISIBILITY
1164void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001165atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001166{
Howard Hinnant138f5922010-12-07 20:46:14 +00001167 __o->store(__d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001168}
1169
1170template <class _Tp>
1171inline _LIBCPP_INLINE_VISIBILITY
1172void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001173atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001174{
Howard Hinnant138f5922010-12-07 20:46:14 +00001175 __o->store(__d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001176}
1177
1178// atomic_store_explicit
1179
1180template <class _Tp>
1181inline _LIBCPP_INLINE_VISIBILITY
1182void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001183atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001184{
Howard Hinnant138f5922010-12-07 20:46:14 +00001185 __o->store(__d, __m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001186}
1187
1188template <class _Tp>
1189inline _LIBCPP_INLINE_VISIBILITY
1190void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001191atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001192{
Howard Hinnant138f5922010-12-07 20:46:14 +00001193 __o->store(__d, __m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001194}
1195
1196// atomic_load
1197
1198template <class _Tp>
1199inline _LIBCPP_INLINE_VISIBILITY
1200_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001201atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001202{
Howard Hinnant138f5922010-12-07 20:46:14 +00001203 return __o->load();
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001204}
1205
1206template <class _Tp>
1207inline _LIBCPP_INLINE_VISIBILITY
1208_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001209atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001210{
Howard Hinnant138f5922010-12-07 20:46:14 +00001211 return __o->load();
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001212}
1213
1214// atomic_load_explicit
1215
1216template <class _Tp>
1217inline _LIBCPP_INLINE_VISIBILITY
1218_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001219atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001220{
Howard Hinnant138f5922010-12-07 20:46:14 +00001221 return __o->load(__m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001222}
1223
1224template <class _Tp>
1225inline _LIBCPP_INLINE_VISIBILITY
1226_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001227atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001228{
Howard Hinnant138f5922010-12-07 20:46:14 +00001229 return __o->load(__m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001230}
1231
1232// atomic_exchange
1233
1234template <class _Tp>
1235inline _LIBCPP_INLINE_VISIBILITY
1236_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001237atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001238{
Howard Hinnant138f5922010-12-07 20:46:14 +00001239 return __o->exchange(__d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001240}
1241
1242template <class _Tp>
1243inline _LIBCPP_INLINE_VISIBILITY
1244_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001245atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001246{
Howard Hinnant138f5922010-12-07 20:46:14 +00001247 return __o->exchange(__d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001248}
1249
1250// atomic_exchange_explicit
1251
1252template <class _Tp>
1253inline _LIBCPP_INLINE_VISIBILITY
1254_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001255atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001256{
Howard Hinnant138f5922010-12-07 20:46:14 +00001257 return __o->exchange(__d, __m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001258}
1259
1260template <class _Tp>
1261inline _LIBCPP_INLINE_VISIBILITY
1262_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001263atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001264{
Howard Hinnant138f5922010-12-07 20:46:14 +00001265 return __o->exchange(__d, __m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001266}
1267
1268// atomic_compare_exchange_weak
1269
1270template <class _Tp>
1271inline _LIBCPP_INLINE_VISIBILITY
1272bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001273atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001274{
Howard Hinnant138f5922010-12-07 20:46:14 +00001275 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001276}
1277
1278template <class _Tp>
1279inline _LIBCPP_INLINE_VISIBILITY
1280bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001281atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001282{
Howard Hinnant138f5922010-12-07 20:46:14 +00001283 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001284}
1285
1286// atomic_compare_exchange_strong
1287
1288template <class _Tp>
1289inline _LIBCPP_INLINE_VISIBILITY
1290bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001291atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001292{
Howard Hinnant138f5922010-12-07 20:46:14 +00001293 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001294}
1295
1296template <class _Tp>
1297inline _LIBCPP_INLINE_VISIBILITY
1298bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001299atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001300{
Howard Hinnant138f5922010-12-07 20:46:14 +00001301 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001302}
1303
1304// atomic_compare_exchange_weak_explicit
1305
1306template <class _Tp>
1307inline _LIBCPP_INLINE_VISIBILITY
1308bool
1309atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
1310 _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001311 memory_order __s, memory_order __f) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001312{
Howard Hinnant138f5922010-12-07 20:46:14 +00001313 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001314}
1315
1316template <class _Tp>
1317inline _LIBCPP_INLINE_VISIBILITY
1318bool
1319atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001320 memory_order __s, memory_order __f) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001321{
Howard Hinnant138f5922010-12-07 20:46:14 +00001322 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001323}
1324
1325// atomic_compare_exchange_strong_explicit
1326
1327template <class _Tp>
1328inline _LIBCPP_INLINE_VISIBILITY
1329bool
1330atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
1331 _Tp* __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001332 memory_order __s, memory_order __f) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001333{
Howard Hinnant138f5922010-12-07 20:46:14 +00001334 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001335}
1336
1337template <class _Tp>
1338inline _LIBCPP_INLINE_VISIBILITY
1339bool
1340atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
1341 _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001342 memory_order __s, memory_order __f) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001343{
Howard Hinnant138f5922010-12-07 20:46:14 +00001344 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001345}
1346
Howard Hinnant138f5922010-12-07 20:46:14 +00001347// atomic_fetch_add
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001348
1349template <class _Tp>
Howard Hinnant138f5922010-12-07 20:46:14 +00001350inline _LIBCPP_INLINE_VISIBILITY
1351typename enable_if
1352<
1353 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1354 _Tp
1355>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001356atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001357{
Howard Hinnant138f5922010-12-07 20:46:14 +00001358 return __o->fetch_add(__op);
1359}
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001360
Howard Hinnant138f5922010-12-07 20:46:14 +00001361template <class _Tp>
1362inline _LIBCPP_INLINE_VISIBILITY
1363typename enable_if
1364<
1365 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1366 _Tp
1367>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001368atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001369{
1370 return __o->fetch_add(__op);
1371}
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001372
Howard Hinnant138f5922010-12-07 20:46:14 +00001373template <class _Tp>
1374inline _LIBCPP_INLINE_VISIBILITY
1375_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001376atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001377{
1378 return __o->fetch_add(__op);
1379}
1380
1381template <class _Tp>
1382inline _LIBCPP_INLINE_VISIBILITY
1383_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001384atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001385{
1386 return __o->fetch_add(__op);
1387}
1388
1389// atomic_fetch_add_explicit
1390
1391template <class _Tp>
1392inline _LIBCPP_INLINE_VISIBILITY
1393typename enable_if
1394<
1395 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1396 _Tp
1397>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001398atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001399{
1400 return __o->fetch_add(__op, __m);
1401}
1402
1403template <class _Tp>
1404inline _LIBCPP_INLINE_VISIBILITY
1405typename enable_if
1406<
1407 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1408 _Tp
1409>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001410atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001411{
1412 return __o->fetch_add(__op, __m);
1413}
1414
1415template <class _Tp>
1416inline _LIBCPP_INLINE_VISIBILITY
1417_Tp*
1418atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001419 memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001420{
1421 return __o->fetch_add(__op, __m);
1422}
1423
1424template <class _Tp>
1425inline _LIBCPP_INLINE_VISIBILITY
1426_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001427atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001428{
1429 return __o->fetch_add(__op, __m);
1430}
1431
1432// atomic_fetch_sub
1433
1434template <class _Tp>
1435inline _LIBCPP_INLINE_VISIBILITY
1436typename enable_if
1437<
1438 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1439 _Tp
1440>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001441atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001442{
1443 return __o->fetch_sub(__op);
1444}
1445
1446template <class _Tp>
1447inline _LIBCPP_INLINE_VISIBILITY
1448typename enable_if
1449<
1450 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1451 _Tp
1452>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001453atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001454{
1455 return __o->fetch_sub(__op);
1456}
1457
1458template <class _Tp>
1459inline _LIBCPP_INLINE_VISIBILITY
1460_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001461atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001462{
1463 return __o->fetch_sub(__op);
1464}
1465
1466template <class _Tp>
1467inline _LIBCPP_INLINE_VISIBILITY
1468_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001469atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001470{
1471 return __o->fetch_sub(__op);
1472}
1473
1474// atomic_fetch_sub_explicit
1475
1476template <class _Tp>
1477inline _LIBCPP_INLINE_VISIBILITY
1478typename enable_if
1479<
1480 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1481 _Tp
1482>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001483atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001484{
1485 return __o->fetch_sub(__op, __m);
1486}
1487
1488template <class _Tp>
1489inline _LIBCPP_INLINE_VISIBILITY
1490typename enable_if
1491<
1492 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1493 _Tp
1494>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001495atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001496{
1497 return __o->fetch_sub(__op, __m);
1498}
1499
1500template <class _Tp>
1501inline _LIBCPP_INLINE_VISIBILITY
1502_Tp*
1503atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001504 memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001505{
1506 return __o->fetch_sub(__op, __m);
1507}
1508
1509template <class _Tp>
1510inline _LIBCPP_INLINE_VISIBILITY
1511_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001512atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001513{
1514 return __o->fetch_sub(__op, __m);
1515}
1516
1517// atomic_fetch_and
1518
1519template <class _Tp>
1520inline _LIBCPP_INLINE_VISIBILITY
1521typename enable_if
1522<
1523 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1524 _Tp
1525>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001526atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001527{
1528 return __o->fetch_and(__op);
1529}
1530
1531template <class _Tp>
1532inline _LIBCPP_INLINE_VISIBILITY
1533typename enable_if
1534<
1535 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1536 _Tp
1537>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001538atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001539{
1540 return __o->fetch_and(__op);
1541}
1542
1543// atomic_fetch_and_explicit
1544
1545template <class _Tp>
1546inline _LIBCPP_INLINE_VISIBILITY
1547typename enable_if
1548<
1549 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1550 _Tp
1551>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001552atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001553{
1554 return __o->fetch_and(__op, __m);
1555}
1556
1557template <class _Tp>
1558inline _LIBCPP_INLINE_VISIBILITY
1559typename enable_if
1560<
1561 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1562 _Tp
1563>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001564atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001565{
1566 return __o->fetch_and(__op, __m);
1567}
1568
1569// atomic_fetch_or
1570
1571template <class _Tp>
1572inline _LIBCPP_INLINE_VISIBILITY
1573typename enable_if
1574<
1575 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1576 _Tp
1577>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001578atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001579{
1580 return __o->fetch_or(__op);
1581}
1582
1583template <class _Tp>
1584inline _LIBCPP_INLINE_VISIBILITY
1585typename enable_if
1586<
1587 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1588 _Tp
1589>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001590atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001591{
1592 return __o->fetch_or(__op);
1593}
1594
1595// atomic_fetch_or_explicit
1596
1597template <class _Tp>
1598inline _LIBCPP_INLINE_VISIBILITY
1599typename enable_if
1600<
1601 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1602 _Tp
1603>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001604atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001605{
1606 return __o->fetch_or(__op, __m);
1607}
1608
1609template <class _Tp>
1610inline _LIBCPP_INLINE_VISIBILITY
1611typename enable_if
1612<
1613 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1614 _Tp
1615>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001616atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001617{
1618 return __o->fetch_or(__op, __m);
1619}
1620
1621// atomic_fetch_xor
1622
1623template <class _Tp>
1624inline _LIBCPP_INLINE_VISIBILITY
1625typename enable_if
1626<
1627 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1628 _Tp
1629>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001630atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001631{
1632 return __o->fetch_xor(__op);
1633}
1634
1635template <class _Tp>
1636inline _LIBCPP_INLINE_VISIBILITY
1637typename enable_if
1638<
1639 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1640 _Tp
1641>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001642atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001643{
1644 return __o->fetch_xor(__op);
1645}
1646
1647// atomic_fetch_xor_explicit
1648
1649template <class _Tp>
1650inline _LIBCPP_INLINE_VISIBILITY
1651typename enable_if
1652<
1653 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1654 _Tp
1655>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001656atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001657{
1658 return __o->fetch_xor(__op, __m);
1659}
1660
1661template <class _Tp>
1662inline _LIBCPP_INLINE_VISIBILITY
1663typename enable_if
1664<
1665 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1666 _Tp
1667>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001668atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001669{
1670 return __o->fetch_xor(__op, __m);
1671}
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001672
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001673// flag type and operations
1674
1675typedef struct atomic_flag
1676{
David Chisnall26ed3f42011-12-19 11:44:20 +00001677 _Atomic(bool) __a_;
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001678
1679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001680 bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001681 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001683 bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001684 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001686 void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001687 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001689 void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001690 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001691
1692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3d284222013-05-02 20:18:43 +00001693#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1694 atomic_flag() _NOEXCEPT = default;
1695#else
1696 atomic_flag() _NOEXCEPT : __a_() {}
1697#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1698
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001699 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfec26a92016-05-03 02:12:26 +00001700 atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001701
1702#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1703 atomic_flag(const atomic_flag&) = delete;
1704 atomic_flag& operator=(const atomic_flag&) = delete;
1705 atomic_flag& operator=(const atomic_flag&) volatile = delete;
1706#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1707private:
1708 atomic_flag(const atomic_flag&);
1709 atomic_flag& operator=(const atomic_flag&);
1710 atomic_flag& operator=(const atomic_flag&) volatile;
1711#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1712} atomic_flag;
1713
1714inline _LIBCPP_INLINE_VISIBILITY
1715bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001716atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001717{
1718 return __o->test_and_set();
1719}
1720
1721inline _LIBCPP_INLINE_VISIBILITY
1722bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001723atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001724{
1725 return __o->test_and_set();
1726}
1727
1728inline _LIBCPP_INLINE_VISIBILITY
1729bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001730atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001731{
1732 return __o->test_and_set(__m);
1733}
1734
1735inline _LIBCPP_INLINE_VISIBILITY
1736bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001737atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001738{
1739 return __o->test_and_set(__m);
1740}
1741
1742inline _LIBCPP_INLINE_VISIBILITY
1743void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001744atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001745{
1746 __o->clear();
1747}
1748
1749inline _LIBCPP_INLINE_VISIBILITY
1750void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001751atomic_flag_clear(atomic_flag* __o) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001752{
1753 __o->clear();
1754}
1755
1756inline _LIBCPP_INLINE_VISIBILITY
1757void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001758atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001759{
1760 __o->clear(__m);
1761}
1762
1763inline _LIBCPP_INLINE_VISIBILITY
1764void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001765atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001766{
1767 __o->clear(__m);
1768}
1769
1770// fences
1771
1772inline _LIBCPP_INLINE_VISIBILITY
1773void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001774atomic_thread_fence(memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001775{
Richard Smith27a4a972012-04-11 18:55:46 +00001776 __c11_atomic_thread_fence(__m);
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001777}
1778
1779inline _LIBCPP_INLINE_VISIBILITY
1780void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001781atomic_signal_fence(memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001782{
Richard Smith27a4a972012-04-11 18:55:46 +00001783 __c11_atomic_signal_fence(__m);
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001784}
1785
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001786// Atomics for standard typedef types
1787
Howard Hinnantf0af8d92013-01-04 18:58:50 +00001788typedef atomic<bool> atomic_bool;
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001789typedef atomic<char> atomic_char;
1790typedef atomic<signed char> atomic_schar;
1791typedef atomic<unsigned char> atomic_uchar;
1792typedef atomic<short> atomic_short;
1793typedef atomic<unsigned short> atomic_ushort;
1794typedef atomic<int> atomic_int;
1795typedef atomic<unsigned int> atomic_uint;
1796typedef atomic<long> atomic_long;
1797typedef atomic<unsigned long> atomic_ulong;
1798typedef atomic<long long> atomic_llong;
1799typedef atomic<unsigned long long> atomic_ullong;
1800typedef atomic<char16_t> atomic_char16_t;
1801typedef atomic<char32_t> atomic_char32_t;
1802typedef atomic<wchar_t> atomic_wchar_t;
1803
1804typedef atomic<int_least8_t> atomic_int_least8_t;
1805typedef atomic<uint_least8_t> atomic_uint_least8_t;
1806typedef atomic<int_least16_t> atomic_int_least16_t;
1807typedef atomic<uint_least16_t> atomic_uint_least16_t;
1808typedef atomic<int_least32_t> atomic_int_least32_t;
1809typedef atomic<uint_least32_t> atomic_uint_least32_t;
1810typedef atomic<int_least64_t> atomic_int_least64_t;
1811typedef atomic<uint_least64_t> atomic_uint_least64_t;
1812
1813typedef atomic<int_fast8_t> atomic_int_fast8_t;
1814typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
1815typedef atomic<int_fast16_t> atomic_int_fast16_t;
1816typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1817typedef atomic<int_fast32_t> atomic_int_fast32_t;
1818typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1819typedef atomic<int_fast64_t> atomic_int_fast64_t;
1820typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1821
Marshall Clowf710afc2016-06-30 15:28:38 +00001822typedef atomic< int8_t> atomic_int8_t;
1823typedef atomic<uint8_t> atomic_uint8_t;
1824typedef atomic< int16_t> atomic_int16_t;
1825typedef atomic<uint16_t> atomic_uint16_t;
1826typedef atomic< int32_t> atomic_int32_t;
1827typedef atomic<uint32_t> atomic_uint32_t;
1828typedef atomic< int64_t> atomic_int64_t;
1829typedef atomic<uint64_t> atomic_uint64_t;
1830
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001831typedef atomic<intptr_t> atomic_intptr_t;
1832typedef atomic<uintptr_t> atomic_uintptr_t;
1833typedef atomic<size_t> atomic_size_t;
1834typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1835typedef atomic<intmax_t> atomic_intmax_t;
1836typedef atomic<uintmax_t> atomic_uintmax_t;
1837
Howard Hinnantf1f066a2010-09-29 21:20:03 +00001838#define ATOMIC_FLAG_INIT {false}
Howard Hinnant953c31d2010-10-04 18:52:54 +00001839#define ATOMIC_VAR_INIT(__v) {__v}
1840
Howard Hinnant71be7292010-09-27 21:17:38 +00001841_LIBCPP_END_NAMESPACE_STD
1842
Howard Hinnant71be7292010-09-27 21:17:38 +00001843#endif // _LIBCPP_ATOMIC