atomic revision 253159
1227825Stheraven// -*- C++ -*-
2227825Stheraven//===--------------------------- atomic -----------------------------------===//
3227825Stheraven//
4227825Stheraven//                     The LLVM Compiler Infrastructure
5227825Stheraven//
6227825Stheraven// This file is distributed under the University of Illinois Open Source
7227825Stheraven// License. See LICENSE.TXT for details.
8227825Stheraven//
9227825Stheraven//===----------------------------------------------------------------------===//
10227825Stheraven
11227825Stheraven#ifndef _LIBCPP_ATOMIC
12227825Stheraven#define _LIBCPP_ATOMIC
13227825Stheraven
14227825Stheraven/*
15227825Stheraven    atomic synopsis
16227825Stheraven
17227825Stheravennamespace std
18227825Stheraven{
19227825Stheraven
20227825Stheraven// order and consistency
21227825Stheraven
22227825Stheraventypedef enum memory_order
23227825Stheraven{
24227825Stheraven    memory_order_relaxed,
25227825Stheraven    memory_order_consume,  // load-consume
26227825Stheraven    memory_order_acquire,  // load-acquire
27227825Stheraven    memory_order_release,  // store-release
28227825Stheraven    memory_order_acq_rel,  // store-release load-acquire
29227825Stheraven    memory_order_seq_cst   // store-release load-acquire
30227825Stheraven} memory_order;
31227825Stheraven
32227825Stheraventemplate <class T> T kill_dependency(T y) noexcept;
33227825Stheraven
34227825Stheraven// lock-free property
35227825Stheraven
36227825Stheraven#define ATOMIC_BOOL_LOCK_FREE unspecified
37227825Stheraven#define ATOMIC_CHAR_LOCK_FREE unspecified
38227825Stheraven#define ATOMIC_CHAR16_T_LOCK_FREE unspecified
39227825Stheraven#define ATOMIC_CHAR32_T_LOCK_FREE unspecified
40227825Stheraven#define ATOMIC_WCHAR_T_LOCK_FREE unspecified
41227825Stheraven#define ATOMIC_SHORT_LOCK_FREE unspecified
42227825Stheraven#define ATOMIC_INT_LOCK_FREE unspecified
43227825Stheraven#define ATOMIC_LONG_LOCK_FREE unspecified
44227825Stheraven#define ATOMIC_LLONG_LOCK_FREE unspecified
45227825Stheraven#define ATOMIC_POINTER_LOCK_FREE unspecified
46227825Stheraven
47227825Stheraven// flag type and operations
48227825Stheraven
49227825Stheraventypedef struct atomic_flag
50227825Stheraven{
51227825Stheraven    bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
52227825Stheraven    bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
53227825Stheraven    void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
54227825Stheraven    void clear(memory_order m = memory_order_seq_cst) noexcept;
55227825Stheraven    atomic_flag()  noexcept = default;
56227825Stheraven    atomic_flag(const atomic_flag&) = delete;
57227825Stheraven    atomic_flag& operator=(const atomic_flag&) = delete;
58227825Stheraven    atomic_flag& operator=(const atomic_flag&) volatile = delete;
59227825Stheraven} atomic_flag;
60227825Stheraven
61227825Stheravenbool
62227825Stheraven    atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
63227825Stheraven
64227825Stheravenbool
65227825Stheraven    atomic_flag_test_and_set(atomic_flag* obj) noexcept;
66227825Stheraven
67227825Stheravenbool
68227825Stheraven    atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
69227825Stheraven                                      memory_order m) noexcept;
70227825Stheraven
71227825Stheravenbool
72227825Stheraven    atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
73227825Stheraven
74227825Stheravenvoid
75227825Stheraven    atomic_flag_clear(volatile atomic_flag* obj) noexcept;
76227825Stheraven
77227825Stheravenvoid
78227825Stheraven    atomic_flag_clear(atomic_flag* obj) noexcept;
79227825Stheraven
80227825Stheravenvoid
81227825Stheraven    atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
82227825Stheraven
83227825Stheravenvoid
84227825Stheraven    atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
85227825Stheraven
86227825Stheraven#define ATOMIC_FLAG_INIT see below
87227825Stheraven#define ATOMIC_VAR_INIT(value) see below
88227825Stheraven
89227825Stheraventemplate <class T>
90227825Stheravenstruct atomic
91227825Stheraven{
92227825Stheraven    bool is_lock_free() const volatile noexcept;
93227825Stheraven    bool is_lock_free() const noexcept;
94227825Stheraven    void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
95227825Stheraven    void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
96227825Stheraven    T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
97227825Stheraven    T load(memory_order m = memory_order_seq_cst) const noexcept;
98227825Stheraven    operator T() const volatile noexcept;
99227825Stheraven    operator T() const noexcept;
100227825Stheraven    T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
101227825Stheraven    T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
102227825Stheraven    bool compare_exchange_weak(T& expc, T desr,
103227825Stheraven                               memory_order s, memory_order f) volatile noexcept;
104227825Stheraven    bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept;
105227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
106227825Stheraven                                 memory_order s, memory_order f) volatile noexcept;
107227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
108227825Stheraven                                 memory_order s, memory_order f) noexcept;
109227825Stheraven    bool compare_exchange_weak(T& expc, T desr,
110227825Stheraven                               memory_order m = memory_order_seq_cst) volatile noexcept;
111227825Stheraven    bool compare_exchange_weak(T& expc, T desr,
112227825Stheraven                               memory_order m = memory_order_seq_cst) noexcept;
113227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
114227825Stheraven                                memory_order m = memory_order_seq_cst) volatile noexcept;
115227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
116227825Stheraven                                 memory_order m = memory_order_seq_cst) noexcept;
117227825Stheraven
118227825Stheraven    atomic() noexcept = default;
119227825Stheraven    constexpr atomic(T desr) noexcept;
120227825Stheraven    atomic(const atomic&) = delete;
121227825Stheraven    atomic& operator=(const atomic&) = delete;
122227825Stheraven    atomic& operator=(const atomic&) volatile = delete;
123227825Stheraven    T operator=(T) volatile noexcept;
124227825Stheraven    T operator=(T) noexcept;
125227825Stheraven};
126227825Stheraven
127227825Stheraventemplate <>
128227825Stheravenstruct atomic<integral>
129227825Stheraven{
130227825Stheraven    bool is_lock_free() const volatile noexcept;
131227825Stheraven    bool is_lock_free() const noexcept;
132227825Stheraven    void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
133227825Stheraven    void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
134227825Stheraven    integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
135227825Stheraven    integral load(memory_order m = memory_order_seq_cst) const noexcept;
136227825Stheraven    operator integral() const volatile noexcept;
137227825Stheraven    operator integral() const noexcept;
138227825Stheraven    integral exchange(integral desr,
139227825Stheraven                      memory_order m = memory_order_seq_cst) volatile noexcept;
140227825Stheraven    integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
141227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
142227825Stheraven                               memory_order s, memory_order f) volatile noexcept;
143227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
144227825Stheraven                               memory_order s, memory_order f) noexcept;
145227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
146227825Stheraven                                 memory_order s, memory_order f) volatile noexcept;
147227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
148227825Stheraven                                 memory_order s, memory_order f) noexcept;
149227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
150227825Stheraven                               memory_order m = memory_order_seq_cst) volatile noexcept;
151227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
152227825Stheraven                               memory_order m = memory_order_seq_cst) noexcept;
153227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
154227825Stheraven                                memory_order m = memory_order_seq_cst) volatile noexcept;
155227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
156227825Stheraven                                 memory_order m = memory_order_seq_cst) noexcept;
157227825Stheraven
158227825Stheraven    integral
159227825Stheraven        fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
160227825Stheraven    integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
161227825Stheraven    integral
162227825Stheraven        fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
163227825Stheraven    integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
164227825Stheraven    integral
165227825Stheraven        fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
166227825Stheraven    integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
167227825Stheraven    integral
168227825Stheraven        fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
169227825Stheraven    integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
170227825Stheraven    integral
171227825Stheraven        fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
172227825Stheraven    integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
173227825Stheraven
174227825Stheraven    atomic() noexcept = default;
175227825Stheraven    constexpr atomic(integral desr) noexcept;
176227825Stheraven    atomic(const atomic&) = delete;
177227825Stheraven    atomic& operator=(const atomic&) = delete;
178227825Stheraven    atomic& operator=(const atomic&) volatile = delete;
179227825Stheraven    integral operator=(integral desr) volatile noexcept;
180227825Stheraven    integral operator=(integral desr) noexcept;
181227825Stheraven
182227825Stheraven    integral operator++(int) volatile noexcept;
183227825Stheraven    integral operator++(int) noexcept;
184227825Stheraven    integral operator--(int) volatile noexcept;
185227825Stheraven    integral operator--(int) noexcept;
186227825Stheraven    integral operator++() volatile noexcept;
187227825Stheraven    integral operator++() noexcept;
188227825Stheraven    integral operator--() volatile noexcept;
189227825Stheraven    integral operator--() noexcept;
190227825Stheraven    integral operator+=(integral op) volatile noexcept;
191227825Stheraven    integral operator+=(integral op) noexcept;
192227825Stheraven    integral operator-=(integral op) volatile noexcept;
193227825Stheraven    integral operator-=(integral op) noexcept;
194227825Stheraven    integral operator&=(integral op) volatile noexcept;
195227825Stheraven    integral operator&=(integral op) noexcept;
196227825Stheraven    integral operator|=(integral op) volatile noexcept;
197227825Stheraven    integral operator|=(integral op) noexcept;
198227825Stheraven    integral operator^=(integral op) volatile noexcept;
199227825Stheraven    integral operator^=(integral op) noexcept;
200227825Stheraven};
201227825Stheraven
202227825Stheraventemplate <class T>
203227825Stheravenstruct atomic<T*>
204227825Stheraven{
205227825Stheraven    bool is_lock_free() const volatile noexcept;
206227825Stheraven    bool is_lock_free() const noexcept;
207227825Stheraven    void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
208227825Stheraven    void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
209227825Stheraven    T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
210227825Stheraven    T* load(memory_order m = memory_order_seq_cst) const noexcept;
211227825Stheraven    operator T*() const volatile noexcept;
212227825Stheraven    operator T*() const noexcept;
213227825Stheraven    T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
214227825Stheraven    T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
215227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
216227825Stheraven                               memory_order s, memory_order f) volatile noexcept;
217227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
218227825Stheraven                               memory_order s, memory_order f) noexcept;
219227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
220227825Stheraven                                 memory_order s, memory_order f) volatile noexcept;
221227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
222227825Stheraven                                 memory_order s, memory_order f) noexcept;
223227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
224227825Stheraven                               memory_order m = memory_order_seq_cst) volatile noexcept;
225227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
226227825Stheraven                               memory_order m = memory_order_seq_cst) noexcept;
227227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
228227825Stheraven                                memory_order m = memory_order_seq_cst) volatile noexcept;
229227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
230227825Stheraven                                 memory_order m = memory_order_seq_cst) noexcept;
231227825Stheraven    T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
232227825Stheraven    T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
233227825Stheraven    T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
234227825Stheraven    T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
235227825Stheraven
236227825Stheraven    atomic() noexcept = default;
237227825Stheraven    constexpr atomic(T* desr) noexcept;
238227825Stheraven    atomic(const atomic&) = delete;
239227825Stheraven    atomic& operator=(const atomic&) = delete;
240227825Stheraven    atomic& operator=(const atomic&) volatile = delete;
241227825Stheraven
242227825Stheraven    T* operator=(T*) volatile noexcept;
243227825Stheraven    T* operator=(T*) noexcept;
244227825Stheraven    T* operator++(int) volatile noexcept;
245227825Stheraven    T* operator++(int) noexcept;
246227825Stheraven    T* operator--(int) volatile noexcept;
247227825Stheraven    T* operator--(int) noexcept;
248227825Stheraven    T* operator++() volatile noexcept;
249227825Stheraven    T* operator++() noexcept;
250227825Stheraven    T* operator--() volatile noexcept;
251227825Stheraven    T* operator--() noexcept;
252227825Stheraven    T* operator+=(ptrdiff_t op) volatile noexcept;
253227825Stheraven    T* operator+=(ptrdiff_t op) noexcept;
254227825Stheraven    T* operator-=(ptrdiff_t op) volatile noexcept;
255227825Stheraven    T* operator-=(ptrdiff_t op) noexcept;
256227825Stheraven};
257227825Stheraven
258227825Stheraven
259227825Stheraventemplate <class T>
260227825Stheraven    bool
261227825Stheraven    atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
262227825Stheraven
263227825Stheraventemplate <class T>
264227825Stheraven    bool
265227825Stheraven    atomic_is_lock_free(const atomic<T>* obj) noexcept;
266227825Stheraven
267227825Stheraventemplate <class T>
268227825Stheraven    void
269227825Stheraven    atomic_init(volatile atomic<T>* obj, T desr) noexcept;
270227825Stheraven
271227825Stheraventemplate <class T>
272227825Stheraven    void
273227825Stheraven    atomic_init(atomic<T>* obj, T desr) noexcept;
274227825Stheraven
275227825Stheraventemplate <class T>
276227825Stheraven    void
277227825Stheraven    atomic_store(volatile atomic<T>* obj, T desr) noexcept;
278227825Stheraven
279227825Stheraventemplate <class T>
280227825Stheraven    void
281227825Stheraven    atomic_store(atomic<T>* obj, T desr) noexcept;
282227825Stheraven
283227825Stheraventemplate <class T>
284227825Stheraven    void
285227825Stheraven    atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
286227825Stheraven
287227825Stheraventemplate <class T>
288227825Stheraven    void
289227825Stheraven    atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
290227825Stheraven
291227825Stheraventemplate <class T>
292227825Stheraven    T
293227825Stheraven    atomic_load(const volatile atomic<T>* obj) noexcept;
294227825Stheraven
295227825Stheraventemplate <class T>
296227825Stheraven    T
297227825Stheraven    atomic_load(const atomic<T>* obj) noexcept;
298227825Stheraven
299227825Stheraventemplate <class T>
300227825Stheraven    T
301227825Stheraven    atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
302227825Stheraven
303227825Stheraventemplate <class T>
304227825Stheraven    T
305227825Stheraven    atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
306227825Stheraven
307227825Stheraventemplate <class T>
308227825Stheraven    T
309227825Stheraven    atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
310227825Stheraven
311227825Stheraventemplate <class T>
312227825Stheraven    T
313227825Stheraven    atomic_exchange(atomic<T>* obj, T desr) noexcept;
314227825Stheraven
315227825Stheraventemplate <class T>
316227825Stheraven    T
317227825Stheraven    atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
318227825Stheraven
319227825Stheraventemplate <class T>
320227825Stheraven    T
321227825Stheraven    atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
322227825Stheraven
323227825Stheraventemplate <class T>
324227825Stheraven    bool
325227825Stheraven    atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
326227825Stheraven
327227825Stheraventemplate <class T>
328227825Stheraven    bool
329227825Stheraven    atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
330227825Stheraven
331227825Stheraventemplate <class T>
332227825Stheraven    bool
333227825Stheraven    atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
334227825Stheraven
335227825Stheraventemplate <class T>
336227825Stheraven    bool
337227825Stheraven    atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
338227825Stheraven
339227825Stheraventemplate <class T>
340227825Stheraven    bool
341227825Stheraven    atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
342227825Stheraven                                          T desr,
343227825Stheraven                                          memory_order s, memory_order f) noexcept;
344227825Stheraven
345227825Stheraventemplate <class T>
346227825Stheraven    bool
347227825Stheraven    atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
348227825Stheraven                                          memory_order s, memory_order f) noexcept;
349227825Stheraven
350227825Stheraventemplate <class T>
351227825Stheraven    bool
352227825Stheraven    atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
353227825Stheraven                                            T* expc, T desr,
354227825Stheraven                                            memory_order s, memory_order f) noexcept;
355227825Stheraven
356227825Stheraventemplate <class T>
357227825Stheraven    bool
358227825Stheraven    atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
359227825Stheraven                                            T desr,
360227825Stheraven                                            memory_order s, memory_order f) noexcept;
361227825Stheraven
362227825Stheraventemplate <class Integral>
363227825Stheraven    Integral
364227825Stheraven    atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
365227825Stheraven
366227825Stheraventemplate <class Integral>
367227825Stheraven    Integral
368227825Stheraven    atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
369227825Stheraven
370227825Stheraventemplate <class Integral>
371227825Stheraven    Integral
372227825Stheraven    atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
373227825Stheraven                              memory_order m) noexcept;
374227825Stheraventemplate <class Integral>
375227825Stheraven    Integral
376227825Stheraven    atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
377227825Stheraven                              memory_order m) noexcept;
378227825Stheraventemplate <class Integral>
379227825Stheraven    Integral
380227825Stheraven    atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
381227825Stheraven
382227825Stheraventemplate <class Integral>
383227825Stheraven    Integral
384227825Stheraven    atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
385227825Stheraven
386227825Stheraventemplate <class Integral>
387227825Stheraven    Integral
388227825Stheraven    atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
389227825Stheraven                              memory_order m) noexcept;
390227825Stheraventemplate <class Integral>
391227825Stheraven    Integral
392227825Stheraven    atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
393227825Stheraven                              memory_order m) noexcept;
394227825Stheraventemplate <class Integral>
395227825Stheraven    Integral
396227825Stheraven    atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
397227825Stheraven
398227825Stheraventemplate <class Integral>
399227825Stheraven    Integral
400227825Stheraven    atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
401227825Stheraven
402227825Stheraventemplate <class Integral>
403227825Stheraven    Integral
404227825Stheraven    atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
405227825Stheraven                              memory_order m) noexcept;
406227825Stheraventemplate <class Integral>
407227825Stheraven    Integral
408227825Stheraven    atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
409227825Stheraven                              memory_order m) noexcept;
410227825Stheraventemplate <class Integral>
411227825Stheraven    Integral
412227825Stheraven    atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
413227825Stheraven
414227825Stheraventemplate <class Integral>
415227825Stheraven    Integral
416227825Stheraven    atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
417227825Stheraven
418227825Stheraventemplate <class Integral>
419227825Stheraven    Integral
420227825Stheraven    atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
421227825Stheraven                             memory_order m) noexcept;
422227825Stheraventemplate <class Integral>
423227825Stheraven    Integral
424227825Stheraven    atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
425227825Stheraven                             memory_order m) noexcept;
426227825Stheraventemplate <class Integral>
427227825Stheraven    Integral
428227825Stheraven    atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
429227825Stheraven
430227825Stheraventemplate <class Integral>
431227825Stheraven    Integral
432227825Stheraven    atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
433227825Stheraven
434227825Stheraventemplate <class Integral>
435227825Stheraven    Integral
436227825Stheraven    atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
437227825Stheraven                              memory_order m) noexcept;
438227825Stheraventemplate <class Integral>
439227825Stheraven    Integral
440227825Stheraven    atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
441227825Stheraven                              memory_order m) noexcept;
442227825Stheraven
443227825Stheraventemplate <class T>
444227825Stheraven    T*
445227825Stheraven    atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
446227825Stheraven
447227825Stheraventemplate <class T>
448227825Stheraven    T*
449227825Stheraven    atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
450227825Stheraven
451227825Stheraventemplate <class T>
452227825Stheraven    T*
453227825Stheraven    atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
454227825Stheraven                              memory_order m) noexcept;
455227825Stheraventemplate <class T>
456227825Stheraven    T*
457227825Stheraven    atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
458227825Stheraven
459227825Stheraventemplate <class T>
460227825Stheraven    T*
461227825Stheraven    atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
462227825Stheraven
463227825Stheraventemplate <class T>
464227825Stheraven    T*
465227825Stheraven    atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
466227825Stheraven
467227825Stheraventemplate <class T>
468227825Stheraven    T*
469227825Stheraven    atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
470227825Stheraven                              memory_order m) noexcept;
471227825Stheraventemplate <class T>
472227825Stheraven    T*
473227825Stheraven    atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
474227825Stheraven
475227825Stheraven// Atomics for standard typedef types
476227825Stheraven
477227825Stheraventypedef atomic<bool>               atomic_bool;
478227825Stheraventypedef atomic<char>               atomic_char;
479227825Stheraventypedef atomic<signed char>        atomic_schar;
480227825Stheraventypedef atomic<unsigned char>      atomic_uchar;
481227825Stheraventypedef atomic<short>              atomic_short;
482227825Stheraventypedef atomic<unsigned short>     atomic_ushort;
483227825Stheraventypedef atomic<int>                atomic_int;
484227825Stheraventypedef atomic<unsigned int>       atomic_uint;
485227825Stheraventypedef atomic<long>               atomic_long;
486227825Stheraventypedef atomic<unsigned long>      atomic_ulong;
487227825Stheraventypedef atomic<long long>          atomic_llong;
488227825Stheraventypedef atomic<unsigned long long> atomic_ullong;
489227825Stheraventypedef atomic<char16_t>           atomic_char16_t;
490227825Stheraventypedef atomic<char32_t>           atomic_char32_t;
491227825Stheraventypedef atomic<wchar_t>            atomic_wchar_t;
492227825Stheraven
493227825Stheraventypedef atomic<int_least8_t>   atomic_int_least8_t;
494227825Stheraventypedef atomic<uint_least8_t>  atomic_uint_least8_t;
495227825Stheraventypedef atomic<int_least16_t>  atomic_int_least16_t;
496227825Stheraventypedef atomic<uint_least16_t> atomic_uint_least16_t;
497227825Stheraventypedef atomic<int_least32_t>  atomic_int_least32_t;
498227825Stheraventypedef atomic<uint_least32_t> atomic_uint_least32_t;
499227825Stheraventypedef atomic<int_least64_t>  atomic_int_least64_t;
500227825Stheraventypedef atomic<uint_least64_t> atomic_uint_least64_t;
501227825Stheraven
502227825Stheraventypedef atomic<int_fast8_t>   atomic_int_fast8_t;
503227825Stheraventypedef atomic<uint_fast8_t>  atomic_uint_fast8_t;
504227825Stheraventypedef atomic<int_fast16_t>  atomic_int_fast16_t;
505227825Stheraventypedef atomic<uint_fast16_t> atomic_uint_fast16_t;
506227825Stheraventypedef atomic<int_fast32_t>  atomic_int_fast32_t;
507227825Stheraventypedef atomic<uint_fast32_t> atomic_uint_fast32_t;
508227825Stheraventypedef atomic<int_fast64_t>  atomic_int_fast64_t;
509227825Stheraventypedef atomic<uint_fast64_t> atomic_uint_fast64_t;
510227825Stheraven
511227825Stheraventypedef atomic<intptr_t>  atomic_intptr_t;
512227825Stheraventypedef atomic<uintptr_t> atomic_uintptr_t;
513227825Stheraventypedef atomic<size_t>    atomic_size_t;
514227825Stheraventypedef atomic<ptrdiff_t> atomic_ptrdiff_t;
515227825Stheraventypedef atomic<intmax_t>  atomic_intmax_t;
516227825Stheraventypedef atomic<uintmax_t> atomic_uintmax_t;
517227825Stheraven
518227825Stheraven// fences
519227825Stheraven
520227825Stheravenvoid atomic_thread_fence(memory_order m) noexcept;
521227825Stheravenvoid atomic_signal_fence(memory_order m) noexcept;
522227825Stheraven
523227825Stheraven}  // std
524227825Stheraven
525227825Stheraven*/
526227825Stheraven
527227825Stheraven#include <__config>
528227825Stheraven#include <cstddef>
529227825Stheraven#include <cstdint>
530227825Stheraven#include <type_traits>
531227825Stheraven
532227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
533227825Stheraven#pragma GCC system_header
534227825Stheraven#endif
535227825Stheraven
536227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
537227825Stheraven
538227825Stheraven#if !__has_feature(cxx_atomic)
539227825Stheraven#error <atomic> is not implemented
540227825Stheraven#else
541227825Stheraven
542227825Stheraventypedef enum memory_order
543227825Stheraven{
544227825Stheraven    memory_order_relaxed, memory_order_consume, memory_order_acquire,
545227825Stheraven    memory_order_release, memory_order_acq_rel, memory_order_seq_cst
546227825Stheraven} memory_order;
547227825Stheraven
548227825Stheraventemplate <class _Tp>
549227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
550227825Stheraven_Tp
551227825Stheravenkill_dependency(_Tp __y) _NOEXCEPT
552227825Stheraven{
553227825Stheraven    return __y;
554227825Stheraven}
555227825Stheraven
556227825Stheraven// general atomic<T>
557227825Stheraven
558227825Stheraventemplate <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
559227825Stheravenstruct __atomic_base  // false
560227825Stheraven{
561227825Stheraven    mutable _Atomic(_Tp) __a_;
562227825Stheraven
563227825Stheraven    _LIBCPP_INLINE_VISIBILITY
564227825Stheraven    bool is_lock_free() const volatile _NOEXCEPT
565227825Stheraven        {return __c11_atomic_is_lock_free(sizeof(_Tp));}
566227825Stheraven    _LIBCPP_INLINE_VISIBILITY
567227825Stheraven    bool is_lock_free() const _NOEXCEPT
568227825Stheraven        {return __c11_atomic_is_lock_free(sizeof(_Tp));}
569227825Stheraven    _LIBCPP_INLINE_VISIBILITY
570227825Stheraven    void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
571227825Stheraven        {__c11_atomic_store(&__a_, __d, __m);}
572227825Stheraven    _LIBCPP_INLINE_VISIBILITY
573227825Stheraven    void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
574227825Stheraven        {__c11_atomic_store(&__a_, __d, __m);}
575227825Stheraven    _LIBCPP_INLINE_VISIBILITY
576227825Stheraven    _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
577227825Stheraven        {return __c11_atomic_load(&__a_, __m);}
578227825Stheraven    _LIBCPP_INLINE_VISIBILITY
579227825Stheraven    _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
580227825Stheraven        {return __c11_atomic_load(&__a_, __m);}
581227825Stheraven    _LIBCPP_INLINE_VISIBILITY
582227825Stheraven    operator _Tp() const volatile _NOEXCEPT {return load();}
583227825Stheraven    _LIBCPP_INLINE_VISIBILITY
584227825Stheraven    operator _Tp() const _NOEXCEPT          {return load();}
585227825Stheraven    _LIBCPP_INLINE_VISIBILITY
586227825Stheraven    _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
587227825Stheraven        {return __c11_atomic_exchange(&__a_, __d, __m);}
588227825Stheraven    _LIBCPP_INLINE_VISIBILITY
589227825Stheraven    _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
590227825Stheraven        {return __c11_atomic_exchange(&__a_, __d, __m);}
591227825Stheraven    _LIBCPP_INLINE_VISIBILITY
592227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
593227825Stheraven                               memory_order __s, memory_order __f) volatile _NOEXCEPT
594227825Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
595227825Stheraven    _LIBCPP_INLINE_VISIBILITY
596227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
597227825Stheraven                               memory_order __s, memory_order __f) _NOEXCEPT
598227825Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
599227825Stheraven    _LIBCPP_INLINE_VISIBILITY
600227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
601227825Stheraven                                 memory_order __s, memory_order __f) volatile _NOEXCEPT
602227825Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
603227825Stheraven    _LIBCPP_INLINE_VISIBILITY
604227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
605227825Stheraven                                 memory_order __s, memory_order __f) _NOEXCEPT
606227825Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
607227825Stheraven    _LIBCPP_INLINE_VISIBILITY
608227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
609227825Stheraven                              memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
610227825Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
611227825Stheraven    _LIBCPP_INLINE_VISIBILITY
612227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
613227825Stheraven                               memory_order __m = memory_order_seq_cst) _NOEXCEPT
614227825Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
615227825Stheraven    _LIBCPP_INLINE_VISIBILITY
616227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
617227825Stheraven                              memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
618227825Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
619227825Stheraven    _LIBCPP_INLINE_VISIBILITY
620227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
621227825Stheraven                                 memory_order __m = memory_order_seq_cst) _NOEXCEPT
622227825Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
623227825Stheraven
624227825Stheraven    _LIBCPP_INLINE_VISIBILITY
625227825Stheraven#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
626227825Stheraven    __atomic_base() _NOEXCEPT = default;
627227825Stheraven#else
628227825Stheraven    __atomic_base() _NOEXCEPT : __a_() {}
629227825Stheraven#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
630227825Stheraven
631227825Stheraven    _LIBCPP_INLINE_VISIBILITY
632227825Stheraven    _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
633227825Stheraven#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
634227825Stheraven    __atomic_base(const __atomic_base&) = delete;
635227825Stheraven    __atomic_base& operator=(const __atomic_base&) = delete;
636227825Stheraven    __atomic_base& operator=(const __atomic_base&) volatile = delete;
637227825Stheraven#else  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
638227825Stheravenprivate:
639227825Stheraven    __atomic_base(const __atomic_base&);
640227825Stheraven    __atomic_base& operator=(const __atomic_base&);
641227825Stheraven    __atomic_base& operator=(const __atomic_base&) volatile;
642227825Stheraven#endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
643227825Stheraven};
644227825Stheraven
645227825Stheraven// atomic<Integral>
646227825Stheraven
647227825Stheraventemplate <class _Tp>
648227825Stheravenstruct __atomic_base<_Tp, true>
649227825Stheraven    : public __atomic_base<_Tp, false>
650227825Stheraven{
651227825Stheraven    typedef __atomic_base<_Tp, false> __base;
652227825Stheraven    _LIBCPP_INLINE_VISIBILITY
653227825Stheraven    __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
654227825Stheraven    _LIBCPP_INLINE_VISIBILITY
655227825Stheraven    _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
656227825Stheraven
657227825Stheraven    _LIBCPP_INLINE_VISIBILITY
658227825Stheraven    _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
659227825Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
660227825Stheraven    _LIBCPP_INLINE_VISIBILITY
661227825Stheraven    _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
662227825Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
663227825Stheraven    _LIBCPP_INLINE_VISIBILITY
664227825Stheraven    _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
665227825Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
666227825Stheraven    _LIBCPP_INLINE_VISIBILITY
667227825Stheraven    _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
668227825Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
669227825Stheraven    _LIBCPP_INLINE_VISIBILITY
670227825Stheraven    _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
671227825Stheraven        {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
672227825Stheraven    _LIBCPP_INLINE_VISIBILITY
673227825Stheraven    _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
674227825Stheraven        {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
675227825Stheraven    _LIBCPP_INLINE_VISIBILITY
676227825Stheraven    _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
677227825Stheraven        {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
678227825Stheraven    _LIBCPP_INLINE_VISIBILITY
679227825Stheraven    _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
680227825Stheraven        {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
681227825Stheraven    _LIBCPP_INLINE_VISIBILITY
682227825Stheraven    _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
683227825Stheraven        {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
684227825Stheraven    _LIBCPP_INLINE_VISIBILITY
685227825Stheraven    _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
686227825Stheraven        {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
687227825Stheraven
688227825Stheraven    _LIBCPP_INLINE_VISIBILITY
689227825Stheraven    _Tp operator++(int) volatile _NOEXCEPT      {return fetch_add(_Tp(1));}
690227825Stheraven    _LIBCPP_INLINE_VISIBILITY
691227825Stheraven    _Tp operator++(int) _NOEXCEPT               {return fetch_add(_Tp(1));}
692227825Stheraven    _LIBCPP_INLINE_VISIBILITY
693227825Stheraven    _Tp operator--(int) volatile _NOEXCEPT      {return fetch_sub(_Tp(1));}
694227825Stheraven    _LIBCPP_INLINE_VISIBILITY
695227825Stheraven    _Tp operator--(int) _NOEXCEPT               {return fetch_sub(_Tp(1));}
696227825Stheraven    _LIBCPP_INLINE_VISIBILITY
697227825Stheraven    _Tp operator++() volatile _NOEXCEPT         {return fetch_add(_Tp(1)) + _Tp(1);}
698227825Stheraven    _LIBCPP_INLINE_VISIBILITY
699227825Stheraven    _Tp operator++() _NOEXCEPT                  {return fetch_add(_Tp(1)) + _Tp(1);}
700227825Stheraven    _LIBCPP_INLINE_VISIBILITY
701227825Stheraven    _Tp operator--() volatile _NOEXCEPT         {return fetch_sub(_Tp(1)) - _Tp(1);}
702227825Stheraven    _LIBCPP_INLINE_VISIBILITY
703227825Stheraven    _Tp operator--() _NOEXCEPT                  {return fetch_sub(_Tp(1)) - _Tp(1);}
704227825Stheraven    _LIBCPP_INLINE_VISIBILITY
705227825Stheraven    _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
706227825Stheraven    _LIBCPP_INLINE_VISIBILITY
707227825Stheraven    _Tp operator+=(_Tp __op) _NOEXCEPT          {return fetch_add(__op) + __op;}
708227825Stheraven    _LIBCPP_INLINE_VISIBILITY
709227825Stheraven    _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
710227825Stheraven    _LIBCPP_INLINE_VISIBILITY
711227825Stheraven    _Tp operator-=(_Tp __op) _NOEXCEPT          {return fetch_sub(__op) - __op;}
712227825Stheraven    _LIBCPP_INLINE_VISIBILITY
713227825Stheraven    _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
714227825Stheraven    _LIBCPP_INLINE_VISIBILITY
715227825Stheraven    _Tp operator&=(_Tp __op) _NOEXCEPT          {return fetch_and(__op) & __op;}
716227825Stheraven    _LIBCPP_INLINE_VISIBILITY
717227825Stheraven    _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
718227825Stheraven    _LIBCPP_INLINE_VISIBILITY
719227825Stheraven    _Tp operator|=(_Tp __op) _NOEXCEPT          {return fetch_or(__op) | __op;}
720227825Stheraven    _LIBCPP_INLINE_VISIBILITY
721227825Stheraven    _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
722227825Stheraven    _LIBCPP_INLINE_VISIBILITY
723227825Stheraven    _Tp operator^=(_Tp __op) _NOEXCEPT          {return fetch_xor(__op) ^ __op;}
724227825Stheraven};
725227825Stheraven
726227825Stheraven// atomic<T>
727227825Stheraven
728227825Stheraventemplate <class _Tp>
729227825Stheravenstruct atomic
730227825Stheraven    : public __atomic_base<_Tp>
731227825Stheraven{
732227825Stheraven    typedef __atomic_base<_Tp> __base;
733227825Stheraven    _LIBCPP_INLINE_VISIBILITY
734227825Stheraven    atomic() _NOEXCEPT _LIBCPP_DEFAULT
735227825Stheraven    _LIBCPP_INLINE_VISIBILITY
736227825Stheraven    _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
737227825Stheraven
738227825Stheraven    _LIBCPP_INLINE_VISIBILITY
739227825Stheraven    _Tp operator=(_Tp __d) volatile _NOEXCEPT
740227825Stheraven        {__base::store(__d); return __d;}
741227825Stheraven    _LIBCPP_INLINE_VISIBILITY
742227825Stheraven    _Tp operator=(_Tp __d) _NOEXCEPT
743227825Stheraven        {__base::store(__d); return __d;}
744227825Stheraven};
745227825Stheraven
746227825Stheraven// atomic<T*>
747227825Stheraven
748227825Stheraventemplate <class _Tp>
749227825Stheravenstruct atomic<_Tp*>
750227825Stheraven    : public __atomic_base<_Tp*>
751227825Stheraven{
752227825Stheraven    typedef __atomic_base<_Tp*> __base;
753227825Stheraven    _LIBCPP_INLINE_VISIBILITY
754227825Stheraven    atomic() _NOEXCEPT _LIBCPP_DEFAULT
755227825Stheraven    _LIBCPP_INLINE_VISIBILITY
756227825Stheraven    _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
757227825Stheraven
758227825Stheraven    _LIBCPP_INLINE_VISIBILITY
759227825Stheraven    _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
760227825Stheraven        {__base::store(__d); return __d;}
761227825Stheraven    _LIBCPP_INLINE_VISIBILITY
762227825Stheraven    _Tp* operator=(_Tp* __d) _NOEXCEPT
763227825Stheraven        {__base::store(__d); return __d;}
764227825Stheraven
765227825Stheraven    _LIBCPP_INLINE_VISIBILITY
766227825Stheraven    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
767227825Stheraven                                                                        volatile _NOEXCEPT
768227825Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
769227825Stheraven    _LIBCPP_INLINE_VISIBILITY
770227825Stheraven    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
771227825Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
772227825Stheraven    _LIBCPP_INLINE_VISIBILITY
773227825Stheraven    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
774227825Stheraven                                                                        volatile _NOEXCEPT
775227825Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
776227825Stheraven    _LIBCPP_INLINE_VISIBILITY
777227825Stheraven    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
778227825Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
779227825Stheraven
780227825Stheraven    _LIBCPP_INLINE_VISIBILITY
781227825Stheraven    _Tp* operator++(int) volatile _NOEXCEPT            {return fetch_add(1);}
782227825Stheraven    _LIBCPP_INLINE_VISIBILITY
783227825Stheraven    _Tp* operator++(int) _NOEXCEPT                     {return fetch_add(1);}
784227825Stheraven    _LIBCPP_INLINE_VISIBILITY
785227825Stheraven    _Tp* operator--(int) volatile _NOEXCEPT            {return fetch_sub(1);}
786227825Stheraven    _LIBCPP_INLINE_VISIBILITY
787227825Stheraven    _Tp* operator--(int) _NOEXCEPT                     {return fetch_sub(1);}
788227825Stheraven    _LIBCPP_INLINE_VISIBILITY
789227825Stheraven    _Tp* operator++() volatile _NOEXCEPT               {return fetch_add(1) + 1;}
790227825Stheraven    _LIBCPP_INLINE_VISIBILITY
791227825Stheraven    _Tp* operator++() _NOEXCEPT                        {return fetch_add(1) + 1;}
792227825Stheraven    _LIBCPP_INLINE_VISIBILITY
793227825Stheraven    _Tp* operator--() volatile _NOEXCEPT               {return fetch_sub(1) - 1;}
794227825Stheraven    _LIBCPP_INLINE_VISIBILITY
795227825Stheraven    _Tp* operator--() _NOEXCEPT                        {return fetch_sub(1) - 1;}
796227825Stheraven    _LIBCPP_INLINE_VISIBILITY
797227825Stheraven    _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
798227825Stheraven    _LIBCPP_INLINE_VISIBILITY
799227825Stheraven    _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT          {return fetch_add(__op) + __op;}
800227825Stheraven    _LIBCPP_INLINE_VISIBILITY
801227825Stheraven    _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
802227825Stheraven    _LIBCPP_INLINE_VISIBILITY
803227825Stheraven    _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT          {return fetch_sub(__op) - __op;}
804227825Stheraven};
805227825Stheraven
806227825Stheraven// atomic_is_lock_free
807227825Stheraven
808227825Stheraventemplate <class _Tp>
809227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
810227825Stheravenbool
811227825Stheravenatomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
812227825Stheraven{
813227825Stheraven    return __o->is_lock_free();
814227825Stheraven}
815227825Stheraven
816227825Stheraventemplate <class _Tp>
817227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
818227825Stheravenbool
819227825Stheravenatomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
820227825Stheraven{
821227825Stheraven    return __o->is_lock_free();
822227825Stheraven}
823227825Stheraven
824227825Stheraven// atomic_init
825227825Stheraven
826227825Stheraventemplate <class _Tp>
827227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
828227825Stheravenvoid
829227825Stheravenatomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
830227825Stheraven{
831227825Stheraven    __c11_atomic_init(&__o->__a_, __d);
832227825Stheraven}
833227825Stheraven
834227825Stheraventemplate <class _Tp>
835227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
836227825Stheravenvoid
837227825Stheravenatomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
838227825Stheraven{
839227825Stheraven    __c11_atomic_init(&__o->__a_, __d);
840227825Stheraven}
841227825Stheraven
842227825Stheraven// atomic_store
843227825Stheraven
844227825Stheraventemplate <class _Tp>
845227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
846227825Stheravenvoid
847227825Stheravenatomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
848227825Stheraven{
849227825Stheraven    __o->store(__d);
850227825Stheraven}
851227825Stheraven
852227825Stheraventemplate <class _Tp>
853227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
854227825Stheravenvoid
855227825Stheravenatomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
856227825Stheraven{
857227825Stheraven    __o->store(__d);
858227825Stheraven}
859227825Stheraven
860227825Stheraven// atomic_store_explicit
861227825Stheraven
862227825Stheraventemplate <class _Tp>
863227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
864227825Stheravenvoid
865227825Stheravenatomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
866227825Stheraven{
867227825Stheraven    __o->store(__d, __m);
868227825Stheraven}
869227825Stheraven
870227825Stheraventemplate <class _Tp>
871227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
872227825Stheravenvoid
873227825Stheravenatomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
874227825Stheraven{
875227825Stheraven    __o->store(__d, __m);
876227825Stheraven}
877227825Stheraven
878227825Stheraven// atomic_load
879227825Stheraven
880227825Stheraventemplate <class _Tp>
881227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
882227825Stheraven_Tp
883227825Stheravenatomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
884227825Stheraven{
885227825Stheraven    return __o->load();
886227825Stheraven}
887227825Stheraven
888227825Stheraventemplate <class _Tp>
889227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
890227825Stheraven_Tp
891227825Stheravenatomic_load(const atomic<_Tp>* __o) _NOEXCEPT
892227825Stheraven{
893227825Stheraven    return __o->load();
894227825Stheraven}
895227825Stheraven
896227825Stheraven// atomic_load_explicit
897227825Stheraven
898227825Stheraventemplate <class _Tp>
899227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
900227825Stheraven_Tp
901227825Stheravenatomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
902227825Stheraven{
903227825Stheraven    return __o->load(__m);
904227825Stheraven}
905227825Stheraven
906227825Stheraventemplate <class _Tp>
907227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
908227825Stheraven_Tp
909227825Stheravenatomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
910227825Stheraven{
911227825Stheraven    return __o->load(__m);
912227825Stheraven}
913227825Stheraven
914227825Stheraven// atomic_exchange
915227825Stheraven
916227825Stheraventemplate <class _Tp>
917227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
918227825Stheraven_Tp
919227825Stheravenatomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
920227825Stheraven{
921227825Stheraven    return __o->exchange(__d);
922227825Stheraven}
923227825Stheraven
924227825Stheraventemplate <class _Tp>
925227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
926227825Stheraven_Tp
927227825Stheravenatomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
928227825Stheraven{
929227825Stheraven    return __o->exchange(__d);
930227825Stheraven}
931227825Stheraven
932227825Stheraven// atomic_exchange_explicit
933227825Stheraven
934227825Stheraventemplate <class _Tp>
935227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
936227825Stheraven_Tp
937227825Stheravenatomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
938227825Stheraven{
939227825Stheraven    return __o->exchange(__d, __m);
940227825Stheraven}
941227825Stheraven
942227825Stheraventemplate <class _Tp>
943227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
944227825Stheraven_Tp
945227825Stheravenatomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
946227825Stheraven{
947227825Stheraven    return __o->exchange(__d, __m);
948227825Stheraven}
949227825Stheraven
950227825Stheraven// atomic_compare_exchange_weak
951227825Stheraven
952227825Stheraventemplate <class _Tp>
953227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
954227825Stheravenbool
955227825Stheravenatomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
956227825Stheraven{
957227825Stheraven    return __o->compare_exchange_weak(*__e, __d);
958227825Stheraven}
959227825Stheraven
960227825Stheraventemplate <class _Tp>
961227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
962227825Stheravenbool
963227825Stheravenatomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
964227825Stheraven{
965227825Stheraven    return __o->compare_exchange_weak(*__e, __d);
966227825Stheraven}
967227825Stheraven
968227825Stheraven// atomic_compare_exchange_strong
969227825Stheraven
970227825Stheraventemplate <class _Tp>
971227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
972227825Stheravenbool
973227825Stheravenatomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
974227825Stheraven{
975227825Stheraven    return __o->compare_exchange_strong(*__e, __d);
976227825Stheraven}
977227825Stheraven
978227825Stheraventemplate <class _Tp>
979227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
980227825Stheravenbool
981227825Stheravenatomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
982227825Stheraven{
983227825Stheraven    return __o->compare_exchange_strong(*__e, __d);
984227825Stheraven}
985227825Stheraven
986227825Stheraven// atomic_compare_exchange_weak_explicit
987227825Stheraven
988227825Stheraventemplate <class _Tp>
989227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
990227825Stheravenbool
991227825Stheravenatomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
992227825Stheraven                                      _Tp __d,
993227825Stheraven                                      memory_order __s, memory_order __f) _NOEXCEPT
994227825Stheraven{
995227825Stheraven    return __o->compare_exchange_weak(*__e, __d, __s, __f);
996227825Stheraven}
997227825Stheraven
998227825Stheraventemplate <class _Tp>
999227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1000227825Stheravenbool
1001227825Stheravenatomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
1002227825Stheraven                                      memory_order __s, memory_order __f) _NOEXCEPT
1003227825Stheraven{
1004227825Stheraven    return __o->compare_exchange_weak(*__e, __d, __s, __f);
1005227825Stheraven}
1006227825Stheraven
1007227825Stheraven// atomic_compare_exchange_strong_explicit
1008227825Stheraven
1009227825Stheraventemplate <class _Tp>
1010227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1011227825Stheravenbool
1012227825Stheravenatomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
1013227825Stheraven                                        _Tp* __e, _Tp __d,
1014227825Stheraven                                        memory_order __s, memory_order __f) _NOEXCEPT
1015227825Stheraven{
1016227825Stheraven    return __o->compare_exchange_strong(*__e, __d, __s, __f);
1017227825Stheraven}
1018227825Stheraven
1019227825Stheraventemplate <class _Tp>
1020227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1021227825Stheravenbool
1022227825Stheravenatomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
1023227825Stheraven                                        _Tp __d,
1024227825Stheraven                                        memory_order __s, memory_order __f) _NOEXCEPT
1025227825Stheraven{
1026227825Stheraven    return __o->compare_exchange_strong(*__e, __d, __s, __f);
1027227825Stheraven}
1028227825Stheraven
1029227825Stheraven// atomic_fetch_add
1030227825Stheraven
1031227825Stheraventemplate <class _Tp>
1032227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1033227825Stheraventypename enable_if
1034227825Stheraven<
1035227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1036227825Stheraven    _Tp
1037227825Stheraven>::type
1038227825Stheravenatomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1039227825Stheraven{
1040227825Stheraven    return __o->fetch_add(__op);
1041227825Stheraven}
1042227825Stheraven
1043227825Stheraventemplate <class _Tp>
1044227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1045227825Stheraventypename enable_if
1046227825Stheraven<
1047227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1048227825Stheraven    _Tp
1049227825Stheraven>::type
1050227825Stheravenatomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1051227825Stheraven{
1052227825Stheraven    return __o->fetch_add(__op);
1053227825Stheraven}
1054227825Stheraven
1055227825Stheraventemplate <class _Tp>
1056227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1057227825Stheraven_Tp*
1058227825Stheravenatomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1059227825Stheraven{
1060227825Stheraven    return __o->fetch_add(__op);
1061227825Stheraven}
1062227825Stheraven
1063227825Stheraventemplate <class _Tp>
1064227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1065227825Stheraven_Tp*
1066227825Stheravenatomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1067227825Stheraven{
1068227825Stheraven    return __o->fetch_add(__op);
1069227825Stheraven}
1070227825Stheraven
1071227825Stheraven// atomic_fetch_add_explicit
1072227825Stheraven
1073227825Stheraventemplate <class _Tp>
1074227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1075227825Stheraventypename enable_if
1076227825Stheraven<
1077227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1078227825Stheraven    _Tp
1079227825Stheraven>::type
1080227825Stheravenatomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1081227825Stheraven{
1082227825Stheraven    return __o->fetch_add(__op, __m);
1083227825Stheraven}
1084227825Stheraven
1085227825Stheraventemplate <class _Tp>
1086227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1087227825Stheraventypename enable_if
1088227825Stheraven<
1089227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1090227825Stheraven    _Tp
1091227825Stheraven>::type
1092227825Stheravenatomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1093227825Stheraven{
1094227825Stheraven    return __o->fetch_add(__op, __m);
1095227825Stheraven}
1096227825Stheraven
1097227825Stheraventemplate <class _Tp>
1098227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1099227825Stheraven_Tp*
1100227825Stheravenatomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
1101227825Stheraven                          memory_order __m) _NOEXCEPT
1102227825Stheraven{
1103227825Stheraven    return __o->fetch_add(__op, __m);
1104227825Stheraven}
1105227825Stheraven
1106227825Stheraventemplate <class _Tp>
1107227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1108227825Stheraven_Tp*
1109227825Stheravenatomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
1110227825Stheraven{
1111227825Stheraven    return __o->fetch_add(__op, __m);
1112227825Stheraven}
1113227825Stheraven
1114227825Stheraven// atomic_fetch_sub
1115227825Stheraven
1116227825Stheraventemplate <class _Tp>
1117227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1118227825Stheraventypename enable_if
1119227825Stheraven<
1120227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1121227825Stheraven    _Tp
1122227825Stheraven>::type
1123227825Stheravenatomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1124227825Stheraven{
1125227825Stheraven    return __o->fetch_sub(__op);
1126227825Stheraven}
1127227825Stheraven
1128227825Stheraventemplate <class _Tp>
1129227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1130227825Stheraventypename enable_if
1131227825Stheraven<
1132227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1133227825Stheraven    _Tp
1134227825Stheraven>::type
1135227825Stheravenatomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1136227825Stheraven{
1137227825Stheraven    return __o->fetch_sub(__op);
1138227825Stheraven}
1139227825Stheraven
1140227825Stheraventemplate <class _Tp>
1141227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1142227825Stheraven_Tp*
1143227825Stheravenatomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1144227825Stheraven{
1145227825Stheraven    return __o->fetch_sub(__op);
1146227825Stheraven}
1147227825Stheraven
1148227825Stheraventemplate <class _Tp>
1149227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1150227825Stheraven_Tp*
1151227825Stheravenatomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1152227825Stheraven{
1153227825Stheraven    return __o->fetch_sub(__op);
1154227825Stheraven}
1155227825Stheraven
1156227825Stheraven// atomic_fetch_sub_explicit
1157227825Stheraven
1158227825Stheraventemplate <class _Tp>
1159227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1160227825Stheraventypename enable_if
1161227825Stheraven<
1162227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1163227825Stheraven    _Tp
1164227825Stheraven>::type
1165227825Stheravenatomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1166227825Stheraven{
1167227825Stheraven    return __o->fetch_sub(__op, __m);
1168227825Stheraven}
1169227825Stheraven
1170227825Stheraventemplate <class _Tp>
1171227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1172227825Stheraventypename enable_if
1173227825Stheraven<
1174227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1175227825Stheraven    _Tp
1176227825Stheraven>::type
1177227825Stheravenatomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1178227825Stheraven{
1179227825Stheraven    return __o->fetch_sub(__op, __m);
1180227825Stheraven}
1181227825Stheraven
1182227825Stheraventemplate <class _Tp>
1183227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1184227825Stheraven_Tp*
1185227825Stheravenatomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
1186227825Stheraven                          memory_order __m) _NOEXCEPT
1187227825Stheraven{
1188227825Stheraven    return __o->fetch_sub(__op, __m);
1189227825Stheraven}
1190227825Stheraven
1191227825Stheraventemplate <class _Tp>
1192227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1193227825Stheraven_Tp*
1194227825Stheravenatomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
1195227825Stheraven{
1196227825Stheraven    return __o->fetch_sub(__op, __m);
1197227825Stheraven}
1198227825Stheraven
1199227825Stheraven// atomic_fetch_and
1200227825Stheraven
1201227825Stheraventemplate <class _Tp>
1202227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1203227825Stheraventypename enable_if
1204227825Stheraven<
1205227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1206227825Stheraven    _Tp
1207227825Stheraven>::type
1208227825Stheravenatomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1209227825Stheraven{
1210227825Stheraven    return __o->fetch_and(__op);
1211227825Stheraven}
1212227825Stheraven
1213227825Stheraventemplate <class _Tp>
1214227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1215227825Stheraventypename enable_if
1216227825Stheraven<
1217227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1218227825Stheraven    _Tp
1219227825Stheraven>::type
1220227825Stheravenatomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1221227825Stheraven{
1222227825Stheraven    return __o->fetch_and(__op);
1223227825Stheraven}
1224227825Stheraven
1225227825Stheraven// atomic_fetch_and_explicit
1226227825Stheraven
1227227825Stheraventemplate <class _Tp>
1228227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1229227825Stheraventypename enable_if
1230227825Stheraven<
1231227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1232227825Stheraven    _Tp
1233227825Stheraven>::type
1234227825Stheravenatomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1235227825Stheraven{
1236227825Stheraven    return __o->fetch_and(__op, __m);
1237227825Stheraven}
1238227825Stheraven
1239227825Stheraventemplate <class _Tp>
1240227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1241227825Stheraventypename enable_if
1242227825Stheraven<
1243227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1244227825Stheraven    _Tp
1245227825Stheraven>::type
1246227825Stheravenatomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1247227825Stheraven{
1248227825Stheraven    return __o->fetch_and(__op, __m);
1249227825Stheraven}
1250227825Stheraven
1251227825Stheraven// atomic_fetch_or
1252227825Stheraven
1253227825Stheraventemplate <class _Tp>
1254227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1255227825Stheraventypename enable_if
1256227825Stheraven<
1257227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1258227825Stheraven    _Tp
1259227825Stheraven>::type
1260227825Stheravenatomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1261227825Stheraven{
1262227825Stheraven    return __o->fetch_or(__op);
1263227825Stheraven}
1264227825Stheraven
1265227825Stheraventemplate <class _Tp>
1266227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1267227825Stheraventypename enable_if
1268227825Stheraven<
1269227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1270227825Stheraven    _Tp
1271227825Stheraven>::type
1272227825Stheravenatomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1273227825Stheraven{
1274227825Stheraven    return __o->fetch_or(__op);
1275227825Stheraven}
1276227825Stheraven
1277227825Stheraven// atomic_fetch_or_explicit
1278227825Stheraven
1279227825Stheraventemplate <class _Tp>
1280227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1281227825Stheraventypename enable_if
1282227825Stheraven<
1283227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1284227825Stheraven    _Tp
1285227825Stheraven>::type
1286227825Stheravenatomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1287227825Stheraven{
1288227825Stheraven    return __o->fetch_or(__op, __m);
1289227825Stheraven}
1290227825Stheraven
1291227825Stheraventemplate <class _Tp>
1292227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1293227825Stheraventypename enable_if
1294227825Stheraven<
1295227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1296227825Stheraven    _Tp
1297227825Stheraven>::type
1298227825Stheravenatomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1299227825Stheraven{
1300227825Stheraven    return __o->fetch_or(__op, __m);
1301227825Stheraven}
1302227825Stheraven
1303227825Stheraven// atomic_fetch_xor
1304227825Stheraven
1305227825Stheraventemplate <class _Tp>
1306227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1307227825Stheraventypename enable_if
1308227825Stheraven<
1309227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1310227825Stheraven    _Tp
1311227825Stheraven>::type
1312227825Stheravenatomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1313227825Stheraven{
1314227825Stheraven    return __o->fetch_xor(__op);
1315227825Stheraven}
1316227825Stheraven
1317227825Stheraventemplate <class _Tp>
1318227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1319227825Stheraventypename enable_if
1320227825Stheraven<
1321227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1322227825Stheraven    _Tp
1323227825Stheraven>::type
1324227825Stheravenatomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1325227825Stheraven{
1326227825Stheraven    return __o->fetch_xor(__op);
1327227825Stheraven}
1328227825Stheraven
1329227825Stheraven// atomic_fetch_xor_explicit
1330227825Stheraven
1331227825Stheraventemplate <class _Tp>
1332227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1333227825Stheraventypename enable_if
1334227825Stheraven<
1335227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1336227825Stheraven    _Tp
1337227825Stheraven>::type
1338227825Stheravenatomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1339227825Stheraven{
1340227825Stheraven    return __o->fetch_xor(__op, __m);
1341227825Stheraven}
1342227825Stheraven
1343227825Stheraventemplate <class _Tp>
1344227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1345227825Stheraventypename enable_if
1346227825Stheraven<
1347227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1348227825Stheraven    _Tp
1349227825Stheraven>::type
1350227825Stheravenatomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1351227825Stheraven{
1352227825Stheraven    return __o->fetch_xor(__op, __m);
1353227825Stheraven}
1354227825Stheraven
1355227825Stheraven// flag type and operations
1356227825Stheraven
1357227825Stheraventypedef struct atomic_flag
1358227825Stheraven{
1359227825Stheraven    _Atomic(bool) __a_;
1360227825Stheraven
1361227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1362227825Stheraven    bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
1363227825Stheraven        {return __c11_atomic_exchange(&__a_, true, __m);}
1364227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1365227825Stheraven    bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
1366227825Stheraven        {return __c11_atomic_exchange(&__a_, true, __m);}
1367227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1368227825Stheraven    void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
1369227825Stheraven        {__c11_atomic_store(&__a_, false, __m);}
1370227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1371227825Stheraven    void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
1372227825Stheraven        {__c11_atomic_store(&__a_, false, __m);}
1373227825Stheraven
1374227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1375227825Stheraven#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1376227825Stheraven    atomic_flag() _NOEXCEPT = default;
1377227825Stheraven#else
1378227825Stheraven    atomic_flag() _NOEXCEPT : __a_() {}
1379227825Stheraven#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1380227825Stheraven
1381227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1382227825Stheraven    atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {}
1383227825Stheraven
1384227825Stheraven#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1385227825Stheraven    atomic_flag(const atomic_flag&) = delete;
1386227825Stheraven    atomic_flag& operator=(const atomic_flag&) = delete;
1387227825Stheraven    atomic_flag& operator=(const atomic_flag&) volatile = delete;
1388227825Stheraven#else  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1389227825Stheravenprivate:
1390227825Stheraven    atomic_flag(const atomic_flag&);
1391227825Stheraven    atomic_flag& operator=(const atomic_flag&);
1392227825Stheraven    atomic_flag& operator=(const atomic_flag&) volatile;
1393227825Stheraven#endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1394227825Stheraven} atomic_flag;
1395227825Stheraven
1396227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1397227825Stheravenbool
1398227825Stheravenatomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
1399227825Stheraven{
1400227825Stheraven    return __o->test_and_set();
1401227825Stheraven}
1402227825Stheraven
1403227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1404227825Stheravenbool
1405227825Stheravenatomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
1406227825Stheraven{
1407227825Stheraven    return __o->test_and_set();
1408227825Stheraven}
1409227825Stheraven
1410227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1411227825Stheravenbool
1412227825Stheravenatomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
1413227825Stheraven{
1414227825Stheraven    return __o->test_and_set(__m);
1415227825Stheraven}
1416227825Stheraven
1417227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1418227825Stheravenbool
1419227825Stheravenatomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
1420227825Stheraven{
1421227825Stheraven    return __o->test_and_set(__m);
1422227825Stheraven}
1423227825Stheraven
1424227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1425227825Stheravenvoid
1426227825Stheravenatomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
1427227825Stheraven{
1428227825Stheraven    __o->clear();
1429227825Stheraven}
1430227825Stheraven
1431227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1432227825Stheravenvoid
1433227825Stheravenatomic_flag_clear(atomic_flag* __o) _NOEXCEPT
1434227825Stheraven{
1435227825Stheraven    __o->clear();
1436227825Stheraven}
1437227825Stheraven
1438227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1439227825Stheravenvoid
1440227825Stheravenatomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
1441227825Stheraven{
1442227825Stheraven    __o->clear(__m);
1443227825Stheraven}
1444227825Stheraven
1445227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1446227825Stheravenvoid
1447227825Stheravenatomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
1448227825Stheraven{
1449227825Stheraven    __o->clear(__m);
1450227825Stheraven}
1451227825Stheraven
1452227825Stheraven// fences
1453227825Stheraven
1454227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1455227825Stheravenvoid
1456227825Stheravenatomic_thread_fence(memory_order __m) _NOEXCEPT
1457227825Stheraven{
1458227825Stheraven    __c11_atomic_thread_fence(__m);
1459227825Stheraven}
1460227825Stheraven
1461227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1462227825Stheravenvoid
1463227825Stheravenatomic_signal_fence(memory_order __m) _NOEXCEPT
1464227825Stheraven{
1465227825Stheraven    __c11_atomic_signal_fence(__m);
1466227825Stheraven}
1467227825Stheraven
1468227825Stheraven// Atomics for standard typedef types
1469227825Stheraven
1470227825Stheraventypedef atomic<bool>               atomic_bool;
1471227825Stheraventypedef atomic<char>               atomic_char;
1472227825Stheraventypedef atomic<signed char>        atomic_schar;
1473227825Stheraventypedef atomic<unsigned char>      atomic_uchar;
1474227825Stheraventypedef atomic<short>              atomic_short;
1475227825Stheraventypedef atomic<unsigned short>     atomic_ushort;
1476227825Stheraventypedef atomic<int>                atomic_int;
1477227825Stheraventypedef atomic<unsigned int>       atomic_uint;
1478227825Stheraventypedef atomic<long>               atomic_long;
1479227825Stheraventypedef atomic<unsigned long>      atomic_ulong;
1480227825Stheraventypedef atomic<long long>          atomic_llong;
1481227825Stheraventypedef atomic<unsigned long long> atomic_ullong;
1482227825Stheraventypedef atomic<char16_t>           atomic_char16_t;
1483227825Stheraventypedef atomic<char32_t>           atomic_char32_t;
1484227825Stheraventypedef atomic<wchar_t>            atomic_wchar_t;
1485227825Stheraven
1486227825Stheraventypedef atomic<int_least8_t>   atomic_int_least8_t;
1487227825Stheraventypedef atomic<uint_least8_t>  atomic_uint_least8_t;
1488227825Stheraventypedef atomic<int_least16_t>  atomic_int_least16_t;
1489227825Stheraventypedef atomic<uint_least16_t> atomic_uint_least16_t;
1490227825Stheraventypedef atomic<int_least32_t>  atomic_int_least32_t;
1491227825Stheraventypedef atomic<uint_least32_t> atomic_uint_least32_t;
1492227825Stheraventypedef atomic<int_least64_t>  atomic_int_least64_t;
1493227825Stheraventypedef atomic<uint_least64_t> atomic_uint_least64_t;
1494227825Stheraven
1495227825Stheraventypedef atomic<int_fast8_t>   atomic_int_fast8_t;
1496227825Stheraventypedef atomic<uint_fast8_t>  atomic_uint_fast8_t;
1497227825Stheraventypedef atomic<int_fast16_t>  atomic_int_fast16_t;
1498227825Stheraventypedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1499227825Stheraventypedef atomic<int_fast32_t>  atomic_int_fast32_t;
1500227825Stheraventypedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1501227825Stheraventypedef atomic<int_fast64_t>  atomic_int_fast64_t;
1502227825Stheraventypedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1503227825Stheraven
1504227825Stheraventypedef atomic<intptr_t>  atomic_intptr_t;
1505227825Stheraventypedef atomic<uintptr_t> atomic_uintptr_t;
1506227825Stheraventypedef atomic<size_t>    atomic_size_t;
1507227825Stheraventypedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1508227825Stheraventypedef atomic<intmax_t>  atomic_intmax_t;
1509227825Stheraventypedef atomic<uintmax_t> atomic_uintmax_t;
1510227825Stheraven
1511227825Stheraven#define ATOMIC_FLAG_INIT {false}
1512227825Stheraven#define ATOMIC_VAR_INIT(__v) {__v}
1513227825Stheraven
1514227825Stheraven// lock-free property
1515227825Stheraven
1516#define ATOMIC_BOOL_LOCK_FREE      __GCC_ATOMIC_BOOL_LOCK_FREE
1517#define ATOMIC_CHAR_LOCK_FREE      __GCC_ATOMIC_CHAR_LOCK_FREE
1518#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
1519#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
1520#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
1521#define ATOMIC_SHORT_LOCK_FREE     __GCC_ATOMIC_SHORT_LOCK_FREE
1522#define ATOMIC_INT_LOCK_FREE       __GCC_ATOMIC_INT_LOCK_FREE
1523#define ATOMIC_LONG_LOCK_FREE      __GCC_ATOMIC_LONG_LOCK_FREE
1524#define ATOMIC_LLONG_LOCK_FREE     __GCC_ATOMIC_LLONG_LOCK_FREE
1525#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
1526
1527#endif  //  !__has_feature(cxx_atomic)
1528
1529_LIBCPP_END_NAMESPACE_STD
1530
1531#endif  // _LIBCPP_ATOMIC
1532