blob: a17bdce1cc6f672ab338c50e69737dc372f2f837 [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
Eric Fiselierb5ab51d2017-01-13 23:45:39 +0000563#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
564 _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \
565 __m == memory_order_acquire || \
566 __m == memory_order_acq_rel, \
567 "memory order argument to atomic operation is invalid")
568
569#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
570 _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \
571 __m == memory_order_acq_rel, \
572 "memory order argument to atomic operation is invalid")
573
574#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
575 _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \
576 __f == memory_order_acq_rel, \
577 "memory order argument to atomic operation is invalid")
578
Howard Hinnant71be7292010-09-27 21:17:38 +0000579_LIBCPP_BEGIN_NAMESPACE_STD
580
Howard Hinnantdca6e712010-09-28 17:13:38 +0000581typedef enum memory_order
582{
583 memory_order_relaxed, memory_order_consume, memory_order_acquire,
584 memory_order_release, memory_order_acq_rel, memory_order_seq_cst
585} memory_order;
586
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000587#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
Dan Albert7b65ace2014-08-09 23:51:51 +0000588namespace __gcc_atomic {
Marshall Clow290eb3f2015-01-11 06:15:59 +0000589template <typename _Tp>
Dan Albert7b65ace2014-08-09 23:51:51 +0000590struct __gcc_atomic_t {
Eric Fiselier88f07122015-12-15 00:32:21 +0000591
592#if _GNUC_VER >= 501
593 static_assert(is_trivially_copyable<_Tp>::value,
594 "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
595#endif
596
Eric Fiselier684aaca2015-10-14 08:36:22 +0000597 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier07b2b552016-11-18 06:42:17 +0000598#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier684aaca2015-10-14 08:36:22 +0000599 __gcc_atomic_t() _NOEXCEPT = default;
600#else
601 __gcc_atomic_t() _NOEXCEPT : __a_value() {}
Eric Fiselier07b2b552016-11-18 06:42:17 +0000602#endif // _LIBCPP_CXX03_LANG
Eric Fiselier719e0442015-07-14 17:50:27 +0000603 _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT
604 : __a_value(value) {}
Marshall Clow290eb3f2015-01-11 06:15:59 +0000605 _Tp __a_value;
Dan Albert7b65ace2014-08-09 23:51:51 +0000606};
607#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>
608
Marshall Clow290eb3f2015-01-11 06:15:59 +0000609template <typename _Tp> _Tp __create();
Dan Albert7b65ace2014-08-09 23:51:51 +0000610
Marshall Clow290eb3f2015-01-11 06:15:59 +0000611template <typename _Tp, typename _Td>
612typename enable_if<sizeof(_Tp()->__a_value = __create<_Td>()), char>::type
Dan Albert7b65ace2014-08-09 23:51:51 +0000613 __test_atomic_assignable(int);
Marshall Clow290eb3f2015-01-11 06:15:59 +0000614template <typename _Tp, typename _Up>
Dan Albert7b65ace2014-08-09 23:51:51 +0000615__two __test_atomic_assignable(...);
616
Marshall Clow290eb3f2015-01-11 06:15:59 +0000617template <typename _Tp, typename _Td>
Dan Albert7b65ace2014-08-09 23:51:51 +0000618struct __can_assign {
619 static const bool value =
Marshall Clow290eb3f2015-01-11 06:15:59 +0000620 sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char);
Dan Albert7b65ace2014-08-09 23:51:51 +0000621};
622
Eric Fiselier684aaca2015-10-14 08:36:22 +0000623static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
Dan Albert7b65ace2014-08-09 23:51:51 +0000624 // Avoid switch statement to make this a constexpr.
625 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
626 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
627 (__order == memory_order_release ? __ATOMIC_RELEASE:
628 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
629 (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
630 __ATOMIC_CONSUME))));
631}
632
Eric Fiselier684aaca2015-10-14 08:36:22 +0000633static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
Dan Albert48815f22015-01-06 18:39:37 +0000634 // Avoid switch statement to make this a constexpr.
635 return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
636 (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
637 (__order == memory_order_release ? __ATOMIC_RELAXED:
638 (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
639 (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE:
640 __ATOMIC_CONSUME))));
641}
642
Dan Albert7b65ace2014-08-09 23:51:51 +0000643} // namespace __gcc_atomic
644
645template <typename _Tp>
646static inline
647typename enable_if<
648 __gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value>::type
649__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
650 __a->__a_value = __val;
651}
652
653template <typename _Tp>
654static inline
655typename enable_if<
656 !__gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value &&
657 __gcc_atomic::__can_assign< _Atomic(_Tp)*, _Tp>::value>::type
658__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) {
659 // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
660 // the default operator= in an object is not volatile, a byte-by-byte copy
661 // is required.
662 volatile char* to = reinterpret_cast<volatile char*>(&__a->__a_value);
663 volatile char* end = to + sizeof(_Tp);
664 char* from = reinterpret_cast<char*>(&__val);
665 while (to != end) {
666 *to++ = *from++;
667 }
668}
669
670template <typename _Tp>
671static inline void __c11_atomic_init(_Atomic(_Tp)* __a, _Tp __val) {
672 __a->__a_value = __val;
673}
674
675static inline void __c11_atomic_thread_fence(memory_order __order) {
676 __atomic_thread_fence(__gcc_atomic::__to_gcc_order(__order));
677}
678
679static inline void __c11_atomic_signal_fence(memory_order __order) {
680 __atomic_signal_fence(__gcc_atomic::__to_gcc_order(__order));
681}
682
Dan Albert7b65ace2014-08-09 23:51:51 +0000683template <typename _Tp>
684static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a, _Tp __val,
685 memory_order __order) {
686 return __atomic_store(&__a->__a_value, &__val,
687 __gcc_atomic::__to_gcc_order(__order));
688}
689
690template <typename _Tp>
691static inline void __c11_atomic_store(_Atomic(_Tp)* __a, _Tp __val,
692 memory_order __order) {
Dan Albert48815f22015-01-06 18:39:37 +0000693 __atomic_store(&__a->__a_value, &__val,
694 __gcc_atomic::__to_gcc_order(__order));
Dan Albert7b65ace2014-08-09 23:51:51 +0000695}
696
697template <typename _Tp>
698static inline _Tp __c11_atomic_load(volatile _Atomic(_Tp)* __a,
699 memory_order __order) {
700 _Tp __ret;
701 __atomic_load(&__a->__a_value, &__ret,
702 __gcc_atomic::__to_gcc_order(__order));
703 return __ret;
704}
705
706template <typename _Tp>
707static inline _Tp __c11_atomic_load(_Atomic(_Tp)* __a, memory_order __order) {
708 _Tp __ret;
709 __atomic_load(&__a->__a_value, &__ret,
710 __gcc_atomic::__to_gcc_order(__order));
711 return __ret;
712}
713
714template <typename _Tp>
715static inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a,
716 _Tp __value, memory_order __order) {
717 _Tp __ret;
718 __atomic_exchange(&__a->__a_value, &__value, &__ret,
719 __gcc_atomic::__to_gcc_order(__order));
720 return __ret;
721}
722
723template <typename _Tp>
724static inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value,
725 memory_order __order) {
726 _Tp __ret;
727 __atomic_exchange(&__a->__a_value, &__value, &__ret,
728 __gcc_atomic::__to_gcc_order(__order));
729 return __ret;
730}
731
732template <typename _Tp>
733static inline bool __c11_atomic_compare_exchange_strong(
734 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
735 memory_order __success, memory_order __failure) {
736 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
737 false,
738 __gcc_atomic::__to_gcc_order(__success),
Dan Albert48815f22015-01-06 18:39:37 +0000739 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Albert7b65ace2014-08-09 23:51:51 +0000740}
741
742template <typename _Tp>
743static inline bool __c11_atomic_compare_exchange_strong(
744 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
745 memory_order __failure) {
746 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
747 false,
748 __gcc_atomic::__to_gcc_order(__success),
Dan Albert48815f22015-01-06 18:39:37 +0000749 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Albert7b65ace2014-08-09 23:51:51 +0000750}
751
752template <typename _Tp>
753static inline bool __c11_atomic_compare_exchange_weak(
754 volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
755 memory_order __success, memory_order __failure) {
756 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
757 true,
758 __gcc_atomic::__to_gcc_order(__success),
Dan Albert48815f22015-01-06 18:39:37 +0000759 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Albert7b65ace2014-08-09 23:51:51 +0000760}
761
762template <typename _Tp>
763static inline bool __c11_atomic_compare_exchange_weak(
764 _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
765 memory_order __failure) {
766 return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
767 true,
768 __gcc_atomic::__to_gcc_order(__success),
Dan Albert48815f22015-01-06 18:39:37 +0000769 __gcc_atomic::__to_gcc_failure_order(__failure));
Dan Albert7b65ace2014-08-09 23:51:51 +0000770}
771
772template <typename _Tp>
773struct __skip_amt { enum {value = 1}; };
774
775template <typename _Tp>
776struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
777
778// FIXME: Haven't figured out what the spec says about using arrays with
779// atomic_fetch_add. Force a failure rather than creating bad behavior.
780template <typename _Tp>
781struct __skip_amt<_Tp[]> { };
782template <typename _Tp, int n>
783struct __skip_amt<_Tp[n]> { };
784
785template <typename _Tp, typename _Td>
786static inline _Tp __c11_atomic_fetch_add(volatile _Atomic(_Tp)* __a,
787 _Td __delta, memory_order __order) {
788 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
789 __gcc_atomic::__to_gcc_order(__order));
790}
791
792template <typename _Tp, typename _Td>
793static inline _Tp __c11_atomic_fetch_add(_Atomic(_Tp)* __a, _Td __delta,
794 memory_order __order) {
795 return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
796 __gcc_atomic::__to_gcc_order(__order));
797}
798
799template <typename _Tp, typename _Td>
800static inline _Tp __c11_atomic_fetch_sub(volatile _Atomic(_Tp)* __a,
801 _Td __delta, memory_order __order) {
802 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
803 __gcc_atomic::__to_gcc_order(__order));
804}
805
806template <typename _Tp, typename _Td>
807static inline _Tp __c11_atomic_fetch_sub(_Atomic(_Tp)* __a, _Td __delta,
808 memory_order __order) {
809 return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
810 __gcc_atomic::__to_gcc_order(__order));
811}
812
813template <typename _Tp>
814static inline _Tp __c11_atomic_fetch_and(volatile _Atomic(_Tp)* __a,
815 _Tp __pattern, memory_order __order) {
816 return __atomic_fetch_and(&__a->__a_value, __pattern,
817 __gcc_atomic::__to_gcc_order(__order));
818}
819
820template <typename _Tp>
821static inline _Tp __c11_atomic_fetch_and(_Atomic(_Tp)* __a,
822 _Tp __pattern, memory_order __order) {
823 return __atomic_fetch_and(&__a->__a_value, __pattern,
824 __gcc_atomic::__to_gcc_order(__order));
825}
826
827template <typename _Tp>
828static inline _Tp __c11_atomic_fetch_or(volatile _Atomic(_Tp)* __a,
829 _Tp __pattern, memory_order __order) {
830 return __atomic_fetch_or(&__a->__a_value, __pattern,
831 __gcc_atomic::__to_gcc_order(__order));
832}
833
834template <typename _Tp>
835static inline _Tp __c11_atomic_fetch_or(_Atomic(_Tp)* __a, _Tp __pattern,
836 memory_order __order) {
837 return __atomic_fetch_or(&__a->__a_value, __pattern,
838 __gcc_atomic::__to_gcc_order(__order));
839}
840
841template <typename _Tp>
842static inline _Tp __c11_atomic_fetch_xor(volatile _Atomic(_Tp)* __a,
843 _Tp __pattern, memory_order __order) {
844 return __atomic_fetch_xor(&__a->__a_value, __pattern,
845 __gcc_atomic::__to_gcc_order(__order));
846}
847
848template <typename _Tp>
849static inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern,
850 memory_order __order) {
851 return __atomic_fetch_xor(&__a->__a_value, __pattern,
852 __gcc_atomic::__to_gcc_order(__order));
853}
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000854#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP
Dan Albert7b65ace2014-08-09 23:51:51 +0000855
Howard Hinnantdca6e712010-09-28 17:13:38 +0000856template <class _Tp>
857inline _LIBCPP_INLINE_VISIBILITY
858_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +0000859kill_dependency(_Tp __y) _NOEXCEPT
Howard Hinnantdca6e712010-09-28 17:13:38 +0000860{
861 return __y;
862}
Howard Hinnant71be7292010-09-27 21:17:38 +0000863
JF Bastienfdb42c22016-03-25 15:48:21 +0000864#define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
865#define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
866#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
867#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
868#define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
869#define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
870#define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
871#define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
872#define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
873#define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
874
Howard Hinnant138f5922010-12-07 20:46:14 +0000875// general atomic<T>
876
877template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
878struct __atomic_base // false
879{
Howard Hinnantd5eebd62012-09-16 20:33:09 +0000880 mutable _Atomic(_Tp) __a_;
Howard Hinnant138f5922010-12-07 20:46:14 +0000881
JF Bastienfdb42c22016-03-25 15:48:21 +0000882#if defined(__cpp_lib_atomic_is_always_lock_free)
883 static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0);
884#endif
885
Howard Hinnant138f5922010-12-07 20:46:14 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000887 bool is_lock_free() const volatile _NOEXCEPT
Eric Fiselier3fd22c22015-06-13 00:23:07 +0000888 {
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000889#if defined(_LIBCPP_HAS_C_ATOMIC_IMP)
Eric Fiselier3fd22c22015-06-13 00:23:07 +0000890 return __c11_atomic_is_lock_free(sizeof(_Tp));
891#else
892 return __atomic_is_lock_free(sizeof(_Tp), 0);
893#endif
894 }
Howard Hinnant138f5922010-12-07 20:46:14 +0000895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000896 bool is_lock_free() const _NOEXCEPT
Eric Fiselier3fd22c22015-06-13 00:23:07 +0000897 {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();}
Howard Hinnant138f5922010-12-07 20:46:14 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000899 void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +0000900 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Richard Smith27a4a972012-04-11 18:55:46 +0000901 {__c11_atomic_store(&__a_, __d, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000903 void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +0000904 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Richard Smith27a4a972012-04-11 18:55:46 +0000905 {__c11_atomic_store(&__a_, __d, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000907 _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +0000908 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Richard Smith27a4a972012-04-11 18:55:46 +0000909 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000911 _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +0000912 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Richard Smith27a4a972012-04-11 18:55:46 +0000913 {return __c11_atomic_load(&__a_, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000915 operator _Tp() const volatile _NOEXCEPT {return load();}
Howard Hinnant138f5922010-12-07 20:46:14 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000917 operator _Tp() const _NOEXCEPT {return load();}
Howard Hinnant138f5922010-12-07 20:46:14 +0000918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000919 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000920 {return __c11_atomic_exchange(&__a_, __d, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000922 _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000923 {return __c11_atomic_exchange(&__a_, __d, __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 __s, memory_order __f) volatile _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +0000927 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith27a4a972012-04-11 18:55:46 +0000928 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000929 _LIBCPP_INLINE_VISIBILITY
930 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000931 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +0000932 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith27a4a972012-04-11 18:55:46 +0000933 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000934 _LIBCPP_INLINE_VISIBILITY
935 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000936 memory_order __s, memory_order __f) volatile _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +0000937 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith27a4a972012-04-11 18:55:46 +0000938 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000939 _LIBCPP_INLINE_VISIBILITY
940 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000941 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +0000942 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Richard Smith27a4a972012-04-11 18:55:46 +0000943 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000944 _LIBCPP_INLINE_VISIBILITY
945 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000946 memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000947 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000948 _LIBCPP_INLINE_VISIBILITY
949 bool compare_exchange_weak(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000950 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000951 {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000952 _LIBCPP_INLINE_VISIBILITY
953 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000954 memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000955 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000956 _LIBCPP_INLINE_VISIBILITY
957 bool compare_exchange_strong(_Tp& __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +0000958 memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +0000959 {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +0000960
961 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier07b2b552016-11-18 06:42:17 +0000962#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3d284222013-05-02 20:18:43 +0000963 __atomic_base() _NOEXCEPT = default;
964#else
965 __atomic_base() _NOEXCEPT : __a_() {}
Eric Fiselier07b2b552016-11-18 06:42:17 +0000966#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3d284222013-05-02 20:18:43 +0000967
Howard Hinnant138f5922010-12-07 20:46:14 +0000968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000969 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
Eric Fiselier2d8515f2017-01-06 20:58:25 +0000970#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant138f5922010-12-07 20:46:14 +0000971 __atomic_base(const __atomic_base&) = delete;
972 __atomic_base& operator=(const __atomic_base&) = delete;
973 __atomic_base& operator=(const __atomic_base&) volatile = delete;
Eric Fiselier2d8515f2017-01-06 20:58:25 +0000974#else
Howard Hinnant6ac60f82010-12-08 17:20:28 +0000975private:
976 __atomic_base(const __atomic_base&);
977 __atomic_base& operator=(const __atomic_base&);
978 __atomic_base& operator=(const __atomic_base&) volatile;
Eric Fiselier2d8515f2017-01-06 20:58:25 +0000979#endif
Howard Hinnant138f5922010-12-07 20:46:14 +0000980};
981
JF Bastienfdb42c22016-03-25 15:48:21 +0000982#if defined(__cpp_lib_atomic_is_always_lock_free)
983template <class _Tp, bool __b>
984_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
985#endif
986
Howard Hinnant138f5922010-12-07 20:46:14 +0000987// atomic<Integral>
988
989template <class _Tp>
990struct __atomic_base<_Tp, true>
991 : public __atomic_base<_Tp, false>
992{
993 typedef __atomic_base<_Tp, false> __base;
994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3d284222013-05-02 20:18:43 +0000995 __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant138f5922010-12-07 20:46:14 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +0000997 _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant138f5922010-12-07 20:46:14 +0000998
999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001000 _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001001 {return __c11_atomic_fetch_add(&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_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001004 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001006 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001007 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001009 _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001010 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001012 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001013 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001015 _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001016 {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001018 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001019 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001021 _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001022 {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001024 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001025 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001026 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001027 _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001028 {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001029
1030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001031 _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));}
Howard Hinnant138f5922010-12-07 20:46:14 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001033 _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));}
Howard Hinnant138f5922010-12-07 20:46:14 +00001034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001035 _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant138f5922010-12-07 20:46:14 +00001036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001037 _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));}
Howard Hinnant138f5922010-12-07 20:46:14 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001039 _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001040 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001041 _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001043 _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001045 _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001047 _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001049 _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001051 _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001053 _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001055 _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001057 _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001059 _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001061 _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001063 _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001065 _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001066};
1067
1068// atomic<T>
1069
1070template <class _Tp>
1071struct atomic
1072 : public __atomic_base<_Tp>
1073{
1074 typedef __atomic_base<_Tp> __base;
1075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3d284222013-05-02 20:18:43 +00001076 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant138f5922010-12-07 20:46:14 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001078 _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001079
1080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001081 _Tp operator=(_Tp __d) volatile _NOEXCEPT
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001082 {__base::store(__d); return __d;}
1083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001084 _Tp operator=(_Tp __d) _NOEXCEPT
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001085 {__base::store(__d); return __d;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001086};
1087
1088// atomic<T*>
1089
1090template <class _Tp>
1091struct atomic<_Tp*>
1092 : public __atomic_base<_Tp*>
1093{
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001094 typedef __atomic_base<_Tp*> __base;
Howard Hinnant138f5922010-12-07 20:46:14 +00001095 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3d284222013-05-02 20:18:43 +00001096 atomic() _NOEXCEPT _LIBCPP_DEFAULT
Howard Hinnant138f5922010-12-07 20:46:14 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001098 _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
Howard Hinnant138f5922010-12-07 20:46:14 +00001099
1100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001101 _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001102 {__base::store(__d); return __d;}
1103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001104 _Tp* operator=(_Tp* __d) _NOEXCEPT
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001105 {__base::store(__d); return __d;}
1106
1107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant138f5922010-12-07 20:46:14 +00001108 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnanteee2c142012-04-11 20:14:21 +00001109 volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001110 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001112 _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001113 {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001114 _LIBCPP_INLINE_VISIBILITY
1115 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
Howard Hinnanteee2c142012-04-11 20:14:21 +00001116 volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001117 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001119 _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001120 {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001121
1122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001123 _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001125 _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001127 _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001129 _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);}
Howard Hinnant138f5922010-12-07 20:46:14 +00001130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001131 _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001133 _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001135 _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001137 _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001139 _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001141 _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001143 _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001145 _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
Howard Hinnant138f5922010-12-07 20:46:14 +00001146};
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001147
1148// atomic_is_lock_free
1149
1150template <class _Tp>
1151inline _LIBCPP_INLINE_VISIBILITY
1152bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001153atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001154{
Howard Hinnant138f5922010-12-07 20:46:14 +00001155 return __o->is_lock_free();
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001156}
1157
1158template <class _Tp>
1159inline _LIBCPP_INLINE_VISIBILITY
1160bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001161atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001162{
Howard Hinnant138f5922010-12-07 20:46:14 +00001163 return __o->is_lock_free();
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001164}
1165
1166// atomic_init
1167
1168template <class _Tp>
1169inline _LIBCPP_INLINE_VISIBILITY
1170void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001171atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001172{
Richard Smith27a4a972012-04-11 18:55:46 +00001173 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001174}
1175
1176template <class _Tp>
1177inline _LIBCPP_INLINE_VISIBILITY
1178void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001179atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001180{
Richard Smith27a4a972012-04-11 18:55:46 +00001181 __c11_atomic_init(&__o->__a_, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001182}
1183
1184// atomic_store
1185
1186template <class _Tp>
1187inline _LIBCPP_INLINE_VISIBILITY
1188void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001189atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001190{
Howard Hinnant138f5922010-12-07 20:46:14 +00001191 __o->store(__d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001192}
1193
1194template <class _Tp>
1195inline _LIBCPP_INLINE_VISIBILITY
1196void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001197atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001198{
Howard Hinnant138f5922010-12-07 20:46:14 +00001199 __o->store(__d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001200}
1201
1202// atomic_store_explicit
1203
1204template <class _Tp>
1205inline _LIBCPP_INLINE_VISIBILITY
1206void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001207atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +00001208 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001209{
Howard Hinnant138f5922010-12-07 20:46:14 +00001210 __o->store(__d, __m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001211}
1212
1213template <class _Tp>
1214inline _LIBCPP_INLINE_VISIBILITY
1215void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001216atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +00001217 _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001218{
Howard Hinnant138f5922010-12-07 20:46:14 +00001219 __o->store(__d, __m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001220}
1221
1222// atomic_load
1223
1224template <class _Tp>
1225inline _LIBCPP_INLINE_VISIBILITY
1226_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001227atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001228{
Howard Hinnant138f5922010-12-07 20:46:14 +00001229 return __o->load();
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001230}
1231
1232template <class _Tp>
1233inline _LIBCPP_INLINE_VISIBILITY
1234_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001235atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001236{
Howard Hinnant138f5922010-12-07 20:46:14 +00001237 return __o->load();
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001238}
1239
1240// atomic_load_explicit
1241
1242template <class _Tp>
1243inline _LIBCPP_INLINE_VISIBILITY
1244_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001245atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +00001246 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001247{
Howard Hinnant138f5922010-12-07 20:46:14 +00001248 return __o->load(__m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001249}
1250
1251template <class _Tp>
1252inline _LIBCPP_INLINE_VISIBILITY
1253_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001254atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +00001255 _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001256{
Howard Hinnant138f5922010-12-07 20:46:14 +00001257 return __o->load(__m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001258}
1259
1260// atomic_exchange
1261
1262template <class _Tp>
1263inline _LIBCPP_INLINE_VISIBILITY
1264_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001265atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001266{
Howard Hinnant138f5922010-12-07 20:46:14 +00001267 return __o->exchange(__d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001268}
1269
1270template <class _Tp>
1271inline _LIBCPP_INLINE_VISIBILITY
1272_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001273atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001274{
Howard Hinnant138f5922010-12-07 20:46:14 +00001275 return __o->exchange(__d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001276}
1277
1278// atomic_exchange_explicit
1279
1280template <class _Tp>
1281inline _LIBCPP_INLINE_VISIBILITY
1282_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001283atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001284{
Howard Hinnant138f5922010-12-07 20:46:14 +00001285 return __o->exchange(__d, __m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001286}
1287
1288template <class _Tp>
1289inline _LIBCPP_INLINE_VISIBILITY
1290_Tp
Howard Hinnanteee2c142012-04-11 20:14:21 +00001291atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001292{
Howard Hinnant138f5922010-12-07 20:46:14 +00001293 return __o->exchange(__d, __m);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001294}
1295
1296// atomic_compare_exchange_weak
1297
1298template <class _Tp>
1299inline _LIBCPP_INLINE_VISIBILITY
1300bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001301atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001302{
Howard Hinnant138f5922010-12-07 20:46:14 +00001303 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001304}
1305
1306template <class _Tp>
1307inline _LIBCPP_INLINE_VISIBILITY
1308bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001309atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001310{
Howard Hinnant138f5922010-12-07 20:46:14 +00001311 return __o->compare_exchange_weak(*__e, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001312}
1313
1314// atomic_compare_exchange_strong
1315
1316template <class _Tp>
1317inline _LIBCPP_INLINE_VISIBILITY
1318bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001319atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001320{
Howard Hinnant138f5922010-12-07 20:46:14 +00001321 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001322}
1323
1324template <class _Tp>
1325inline _LIBCPP_INLINE_VISIBILITY
1326bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001327atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001328{
Howard Hinnant138f5922010-12-07 20:46:14 +00001329 return __o->compare_exchange_strong(*__e, __d);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001330}
1331
1332// atomic_compare_exchange_weak_explicit
1333
1334template <class _Tp>
1335inline _LIBCPP_INLINE_VISIBILITY
1336bool
1337atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
1338 _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001339 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +00001340 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001341{
Howard Hinnant138f5922010-12-07 20:46:14 +00001342 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001343}
1344
1345template <class _Tp>
1346inline _LIBCPP_INLINE_VISIBILITY
1347bool
1348atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001349 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +00001350 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001351{
Howard Hinnant138f5922010-12-07 20:46:14 +00001352 return __o->compare_exchange_weak(*__e, __d, __s, __f);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001353}
1354
1355// atomic_compare_exchange_strong_explicit
1356
1357template <class _Tp>
1358inline _LIBCPP_INLINE_VISIBILITY
1359bool
1360atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
1361 _Tp* __e, _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001362 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +00001363 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001364{
Howard Hinnant138f5922010-12-07 20:46:14 +00001365 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001366}
1367
1368template <class _Tp>
1369inline _LIBCPP_INLINE_VISIBILITY
1370bool
1371atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
1372 _Tp __d,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001373 memory_order __s, memory_order __f) _NOEXCEPT
Eric Fiselierb5ab51d2017-01-13 23:45:39 +00001374 _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001375{
Howard Hinnant138f5922010-12-07 20:46:14 +00001376 return __o->compare_exchange_strong(*__e, __d, __s, __f);
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001377}
1378
Howard Hinnant138f5922010-12-07 20:46:14 +00001379// atomic_fetch_add
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001380
1381template <class _Tp>
Howard Hinnant138f5922010-12-07 20:46:14 +00001382inline _LIBCPP_INLINE_VISIBILITY
1383typename enable_if
1384<
1385 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1386 _Tp
1387>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001388atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001389{
Howard Hinnant138f5922010-12-07 20:46:14 +00001390 return __o->fetch_add(__op);
1391}
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001392
Howard Hinnant138f5922010-12-07 20:46:14 +00001393template <class _Tp>
1394inline _LIBCPP_INLINE_VISIBILITY
1395typename enable_if
1396<
1397 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1398 _Tp
1399>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001400atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001401{
1402 return __o->fetch_add(__op);
1403}
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001404
Howard Hinnant138f5922010-12-07 20:46:14 +00001405template <class _Tp>
1406inline _LIBCPP_INLINE_VISIBILITY
1407_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001408atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001409{
1410 return __o->fetch_add(__op);
1411}
1412
1413template <class _Tp>
1414inline _LIBCPP_INLINE_VISIBILITY
1415_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001416atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001417{
1418 return __o->fetch_add(__op);
1419}
1420
1421// atomic_fetch_add_explicit
1422
1423template <class _Tp>
1424inline _LIBCPP_INLINE_VISIBILITY
1425typename enable_if
1426<
1427 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1428 _Tp
1429>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001430atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001431{
1432 return __o->fetch_add(__op, __m);
1433}
1434
1435template <class _Tp>
1436inline _LIBCPP_INLINE_VISIBILITY
1437typename enable_if
1438<
1439 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1440 _Tp
1441>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001442atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001443{
1444 return __o->fetch_add(__op, __m);
1445}
1446
1447template <class _Tp>
1448inline _LIBCPP_INLINE_VISIBILITY
1449_Tp*
1450atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001451 memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001452{
1453 return __o->fetch_add(__op, __m);
1454}
1455
1456template <class _Tp>
1457inline _LIBCPP_INLINE_VISIBILITY
1458_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001459atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001460{
1461 return __o->fetch_add(__op, __m);
1462}
1463
1464// atomic_fetch_sub
1465
1466template <class _Tp>
1467inline _LIBCPP_INLINE_VISIBILITY
1468typename enable_if
1469<
1470 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1471 _Tp
1472>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001473atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001474{
1475 return __o->fetch_sub(__op);
1476}
1477
1478template <class _Tp>
1479inline _LIBCPP_INLINE_VISIBILITY
1480typename enable_if
1481<
1482 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1483 _Tp
1484>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001485atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001486{
1487 return __o->fetch_sub(__op);
1488}
1489
1490template <class _Tp>
1491inline _LIBCPP_INLINE_VISIBILITY
1492_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001493atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001494{
1495 return __o->fetch_sub(__op);
1496}
1497
1498template <class _Tp>
1499inline _LIBCPP_INLINE_VISIBILITY
1500_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001501atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001502{
1503 return __o->fetch_sub(__op);
1504}
1505
1506// atomic_fetch_sub_explicit
1507
1508template <class _Tp>
1509inline _LIBCPP_INLINE_VISIBILITY
1510typename enable_if
1511<
1512 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1513 _Tp
1514>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001515atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001516{
1517 return __o->fetch_sub(__op, __m);
1518}
1519
1520template <class _Tp>
1521inline _LIBCPP_INLINE_VISIBILITY
1522typename enable_if
1523<
1524 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1525 _Tp
1526>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001527atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001528{
1529 return __o->fetch_sub(__op, __m);
1530}
1531
1532template <class _Tp>
1533inline _LIBCPP_INLINE_VISIBILITY
1534_Tp*
1535atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
Howard Hinnanteee2c142012-04-11 20:14:21 +00001536 memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001537{
1538 return __o->fetch_sub(__op, __m);
1539}
1540
1541template <class _Tp>
1542inline _LIBCPP_INLINE_VISIBILITY
1543_Tp*
Howard Hinnanteee2c142012-04-11 20:14:21 +00001544atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001545{
1546 return __o->fetch_sub(__op, __m);
1547}
1548
1549// atomic_fetch_and
1550
1551template <class _Tp>
1552inline _LIBCPP_INLINE_VISIBILITY
1553typename enable_if
1554<
1555 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1556 _Tp
1557>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001558atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001559{
1560 return __o->fetch_and(__op);
1561}
1562
1563template <class _Tp>
1564inline _LIBCPP_INLINE_VISIBILITY
1565typename enable_if
1566<
1567 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1568 _Tp
1569>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001570atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001571{
1572 return __o->fetch_and(__op);
1573}
1574
1575// atomic_fetch_and_explicit
1576
1577template <class _Tp>
1578inline _LIBCPP_INLINE_VISIBILITY
1579typename enable_if
1580<
1581 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1582 _Tp
1583>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001584atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001585{
1586 return __o->fetch_and(__op, __m);
1587}
1588
1589template <class _Tp>
1590inline _LIBCPP_INLINE_VISIBILITY
1591typename enable_if
1592<
1593 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1594 _Tp
1595>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001596atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001597{
1598 return __o->fetch_and(__op, __m);
1599}
1600
1601// atomic_fetch_or
1602
1603template <class _Tp>
1604inline _LIBCPP_INLINE_VISIBILITY
1605typename enable_if
1606<
1607 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1608 _Tp
1609>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001610atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001611{
1612 return __o->fetch_or(__op);
1613}
1614
1615template <class _Tp>
1616inline _LIBCPP_INLINE_VISIBILITY
1617typename enable_if
1618<
1619 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1620 _Tp
1621>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001622atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001623{
1624 return __o->fetch_or(__op);
1625}
1626
1627// atomic_fetch_or_explicit
1628
1629template <class _Tp>
1630inline _LIBCPP_INLINE_VISIBILITY
1631typename enable_if
1632<
1633 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1634 _Tp
1635>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001636atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001637{
1638 return __o->fetch_or(__op, __m);
1639}
1640
1641template <class _Tp>
1642inline _LIBCPP_INLINE_VISIBILITY
1643typename enable_if
1644<
1645 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1646 _Tp
1647>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001648atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001649{
1650 return __o->fetch_or(__op, __m);
1651}
1652
1653// atomic_fetch_xor
1654
1655template <class _Tp>
1656inline _LIBCPP_INLINE_VISIBILITY
1657typename enable_if
1658<
1659 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1660 _Tp
1661>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001662atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001663{
1664 return __o->fetch_xor(__op);
1665}
1666
1667template <class _Tp>
1668inline _LIBCPP_INLINE_VISIBILITY
1669typename enable_if
1670<
1671 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1672 _Tp
1673>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001674atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001675{
1676 return __o->fetch_xor(__op);
1677}
1678
1679// atomic_fetch_xor_explicit
1680
1681template <class _Tp>
1682inline _LIBCPP_INLINE_VISIBILITY
1683typename enable_if
1684<
1685 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1686 _Tp
1687>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001688atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001689{
1690 return __o->fetch_xor(__op, __m);
1691}
1692
1693template <class _Tp>
1694inline _LIBCPP_INLINE_VISIBILITY
1695typename enable_if
1696<
1697 is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1698 _Tp
1699>::type
Howard Hinnanteee2c142012-04-11 20:14:21 +00001700atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
Howard Hinnant138f5922010-12-07 20:46:14 +00001701{
1702 return __o->fetch_xor(__op, __m);
1703}
Howard Hinnant7bfaeb82010-12-06 23:10:08 +00001704
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001705// flag type and operations
1706
1707typedef struct atomic_flag
1708{
David Chisnall26ed3f42011-12-19 11:44:20 +00001709 _Atomic(bool) __a_;
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001710
1711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001712 bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001713 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001715 bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001716 {return __c11_atomic_exchange(&__a_, true, __m);}
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001718 void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001719 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteee2c142012-04-11 20:14:21 +00001721 void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
Richard Smith27a4a972012-04-11 18:55:46 +00001722 {__c11_atomic_store(&__a_, false, __m);}
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001723
1724 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier07b2b552016-11-18 06:42:17 +00001725#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3d284222013-05-02 20:18:43 +00001726 atomic_flag() _NOEXCEPT = default;
1727#else
1728 atomic_flag() _NOEXCEPT : __a_() {}
Eric Fiselier07b2b552016-11-18 06:42:17 +00001729#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3d284222013-05-02 20:18:43 +00001730
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001731 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfec26a92016-05-03 02:12:26 +00001732 atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001733
Eric Fiselier2d8515f2017-01-06 20:58:25 +00001734#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001735 atomic_flag(const atomic_flag&) = delete;
1736 atomic_flag& operator=(const atomic_flag&) = delete;
1737 atomic_flag& operator=(const atomic_flag&) volatile = delete;
Eric Fiselier2d8515f2017-01-06 20:58:25 +00001738#else
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001739private:
1740 atomic_flag(const atomic_flag&);
1741 atomic_flag& operator=(const atomic_flag&);
1742 atomic_flag& operator=(const atomic_flag&) volatile;
Eric Fiselier2d8515f2017-01-06 20:58:25 +00001743#endif
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001744} atomic_flag;
1745
1746inline _LIBCPP_INLINE_VISIBILITY
1747bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001748atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001749{
1750 return __o->test_and_set();
1751}
1752
1753inline _LIBCPP_INLINE_VISIBILITY
1754bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001755atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001756{
1757 return __o->test_and_set();
1758}
1759
1760inline _LIBCPP_INLINE_VISIBILITY
1761bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001762atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001763{
1764 return __o->test_and_set(__m);
1765}
1766
1767inline _LIBCPP_INLINE_VISIBILITY
1768bool
Howard Hinnanteee2c142012-04-11 20:14:21 +00001769atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001770{
1771 return __o->test_and_set(__m);
1772}
1773
1774inline _LIBCPP_INLINE_VISIBILITY
1775void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001776atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001777{
1778 __o->clear();
1779}
1780
1781inline _LIBCPP_INLINE_VISIBILITY
1782void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001783atomic_flag_clear(atomic_flag* __o) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001784{
1785 __o->clear();
1786}
1787
1788inline _LIBCPP_INLINE_VISIBILITY
1789void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001790atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001791{
1792 __o->clear(__m);
1793}
1794
1795inline _LIBCPP_INLINE_VISIBILITY
1796void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001797atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001798{
1799 __o->clear(__m);
1800}
1801
1802// fences
1803
1804inline _LIBCPP_INLINE_VISIBILITY
1805void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001806atomic_thread_fence(memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001807{
Richard Smith27a4a972012-04-11 18:55:46 +00001808 __c11_atomic_thread_fence(__m);
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001809}
1810
1811inline _LIBCPP_INLINE_VISIBILITY
1812void
Howard Hinnanteee2c142012-04-11 20:14:21 +00001813atomic_signal_fence(memory_order __m) _NOEXCEPT
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001814{
Richard Smith27a4a972012-04-11 18:55:46 +00001815 __c11_atomic_signal_fence(__m);
Howard Hinnant6ac60f82010-12-08 17:20:28 +00001816}
1817
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001818// Atomics for standard typedef types
1819
Howard Hinnantf0af8d92013-01-04 18:58:50 +00001820typedef atomic<bool> atomic_bool;
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001821typedef atomic<char> atomic_char;
1822typedef atomic<signed char> atomic_schar;
1823typedef atomic<unsigned char> atomic_uchar;
1824typedef atomic<short> atomic_short;
1825typedef atomic<unsigned short> atomic_ushort;
1826typedef atomic<int> atomic_int;
1827typedef atomic<unsigned int> atomic_uint;
1828typedef atomic<long> atomic_long;
1829typedef atomic<unsigned long> atomic_ulong;
1830typedef atomic<long long> atomic_llong;
1831typedef atomic<unsigned long long> atomic_ullong;
1832typedef atomic<char16_t> atomic_char16_t;
1833typedef atomic<char32_t> atomic_char32_t;
1834typedef atomic<wchar_t> atomic_wchar_t;
1835
1836typedef atomic<int_least8_t> atomic_int_least8_t;
1837typedef atomic<uint_least8_t> atomic_uint_least8_t;
1838typedef atomic<int_least16_t> atomic_int_least16_t;
1839typedef atomic<uint_least16_t> atomic_uint_least16_t;
1840typedef atomic<int_least32_t> atomic_int_least32_t;
1841typedef atomic<uint_least32_t> atomic_uint_least32_t;
1842typedef atomic<int_least64_t> atomic_int_least64_t;
1843typedef atomic<uint_least64_t> atomic_uint_least64_t;
1844
1845typedef atomic<int_fast8_t> atomic_int_fast8_t;
1846typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
1847typedef atomic<int_fast16_t> atomic_int_fast16_t;
1848typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1849typedef atomic<int_fast32_t> atomic_int_fast32_t;
1850typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1851typedef atomic<int_fast64_t> atomic_int_fast64_t;
1852typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1853
Marshall Clowf710afc2016-06-30 15:28:38 +00001854typedef atomic< int8_t> atomic_int8_t;
1855typedef atomic<uint8_t> atomic_uint8_t;
1856typedef atomic< int16_t> atomic_int16_t;
1857typedef atomic<uint16_t> atomic_uint16_t;
1858typedef atomic< int32_t> atomic_int32_t;
1859typedef atomic<uint32_t> atomic_uint32_t;
1860typedef atomic< int64_t> atomic_int64_t;
1861typedef atomic<uint64_t> atomic_uint64_t;
1862
Howard Hinnant96e4cd62010-12-07 23:24:41 +00001863typedef atomic<intptr_t> atomic_intptr_t;
1864typedef atomic<uintptr_t> atomic_uintptr_t;
1865typedef atomic<size_t> atomic_size_t;
1866typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1867typedef atomic<intmax_t> atomic_intmax_t;
1868typedef atomic<uintmax_t> atomic_uintmax_t;
1869
Howard Hinnantf1f066a2010-09-29 21:20:03 +00001870#define ATOMIC_FLAG_INIT {false}
Howard Hinnant953c31d2010-10-04 18:52:54 +00001871#define ATOMIC_VAR_INIT(__v) {__v}
1872
Howard Hinnant71be7292010-09-27 21:17:38 +00001873_LIBCPP_END_NAMESPACE_STD
1874
Howard Hinnant71be7292010-09-27 21:17:38 +00001875#endif // _LIBCPP_ATOMIC