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
32234976Stheraventemplate <class T> T kill_dependency(T y) noexcept;
33227825Stheraven
34227825Stheraven// lock-free property
35227825Stheraven
36250514Sdim#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
45250514Sdim#define ATOMIC_POINTER_LOCK_FREE unspecified
46227825Stheraven
47227825Stheraven// flag type and operations
48227825Stheraven
49227825Stheraventypedef struct atomic_flag
50227825Stheraven{
51234976Stheraven    bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
52234976Stheraven    bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
53234976Stheraven    void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
54234976Stheraven    void clear(memory_order m = memory_order_seq_cst) noexcept;
55234976Stheraven    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
62234976Stheraven    atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
63227825Stheraven
64227825Stheravenbool
65234976Stheraven    atomic_flag_test_and_set(atomic_flag* obj) noexcept;
66227825Stheraven
67227825Stheravenbool
68227825Stheraven    atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
69234976Stheraven                                      memory_order m) noexcept;
70227825Stheraven
71227825Stheravenbool
72234976Stheraven    atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
73227825Stheraven
74227825Stheravenvoid
75234976Stheraven    atomic_flag_clear(volatile atomic_flag* obj) noexcept;
76227825Stheraven
77227825Stheravenvoid
78234976Stheraven    atomic_flag_clear(atomic_flag* obj) noexcept;
79227825Stheraven
80227825Stheravenvoid
81234976Stheraven    atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
82227825Stheraven
83227825Stheravenvoid
84234976Stheraven    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{
92234976Stheraven    bool is_lock_free() const volatile noexcept;
93234976Stheraven    bool is_lock_free() const noexcept;
94234976Stheraven    void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
95234976Stheraven    void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
96234976Stheraven    T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
97234976Stheraven    T load(memory_order m = memory_order_seq_cst) const noexcept;
98234976Stheraven    operator T() const volatile noexcept;
99234976Stheraven    operator T() const noexcept;
100234976Stheraven    T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
101234976Stheraven    T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
102227825Stheraven    bool compare_exchange_weak(T& expc, T desr,
103234976Stheraven                               memory_order s, memory_order f) volatile noexcept;
104234976Stheraven    bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept;
105227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
106234976Stheraven                                 memory_order s, memory_order f) volatile noexcept;
107227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
108234976Stheraven                                 memory_order s, memory_order f) noexcept;
109227825Stheraven    bool compare_exchange_weak(T& expc, T desr,
110234976Stheraven                               memory_order m = memory_order_seq_cst) volatile noexcept;
111227825Stheraven    bool compare_exchange_weak(T& expc, T desr,
112234976Stheraven                               memory_order m = memory_order_seq_cst) noexcept;
113227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
114234976Stheraven                                memory_order m = memory_order_seq_cst) volatile noexcept;
115227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
116234976Stheraven                                 memory_order m = memory_order_seq_cst) noexcept;
117227825Stheraven
118234976Stheraven    atomic() noexcept = default;
119234976Stheraven    constexpr atomic(T desr) noexcept;
120227825Stheraven    atomic(const atomic&) = delete;
121227825Stheraven    atomic& operator=(const atomic&) = delete;
122227825Stheraven    atomic& operator=(const atomic&) volatile = delete;
123234976Stheraven    T operator=(T) volatile noexcept;
124234976Stheraven    T operator=(T) noexcept;
125227825Stheraven};
126227825Stheraven
127227825Stheraventemplate <>
128227825Stheravenstruct atomic<integral>
129227825Stheraven{
130234976Stheraven    bool is_lock_free() const volatile noexcept;
131234976Stheraven    bool is_lock_free() const noexcept;
132234976Stheraven    void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
133234976Stheraven    void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
134234976Stheraven    integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
135234976Stheraven    integral load(memory_order m = memory_order_seq_cst) const noexcept;
136234976Stheraven    operator integral() const volatile noexcept;
137234976Stheraven    operator integral() const noexcept;
138227825Stheraven    integral exchange(integral desr,
139234976Stheraven                      memory_order m = memory_order_seq_cst) volatile noexcept;
140234976Stheraven    integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
141227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
142234976Stheraven                               memory_order s, memory_order f) volatile noexcept;
143227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
144234976Stheraven                               memory_order s, memory_order f) noexcept;
145227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
146234976Stheraven                                 memory_order s, memory_order f) volatile noexcept;
147227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
148234976Stheraven                                 memory_order s, memory_order f) noexcept;
149227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
150234976Stheraven                               memory_order m = memory_order_seq_cst) volatile noexcept;
151227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
152234976Stheraven                               memory_order m = memory_order_seq_cst) noexcept;
153227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
154234976Stheraven                                memory_order m = memory_order_seq_cst) volatile noexcept;
155227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
156234976Stheraven                                 memory_order m = memory_order_seq_cst) noexcept;
157227825Stheraven
158227825Stheraven    integral
159234976Stheraven        fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
160234976Stheraven    integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
161227825Stheraven    integral
162234976Stheraven        fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
163234976Stheraven    integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
164227825Stheraven    integral
165234976Stheraven        fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
166234976Stheraven    integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
167227825Stheraven    integral
168234976Stheraven        fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
169234976Stheraven    integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
170227825Stheraven    integral
171234976Stheraven        fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
172234976Stheraven    integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
173227825Stheraven
174234976Stheraven    atomic() noexcept = default;
175234976Stheraven    constexpr atomic(integral desr) noexcept;
176227825Stheraven    atomic(const atomic&) = delete;
177227825Stheraven    atomic& operator=(const atomic&) = delete;
178227825Stheraven    atomic& operator=(const atomic&) volatile = delete;
179234976Stheraven    integral operator=(integral desr) volatile noexcept;
180234976Stheraven    integral operator=(integral desr) noexcept;
181227825Stheraven
182234976Stheraven    integral operator++(int) volatile noexcept;
183234976Stheraven    integral operator++(int) noexcept;
184234976Stheraven    integral operator--(int) volatile noexcept;
185234976Stheraven    integral operator--(int) noexcept;
186234976Stheraven    integral operator++() volatile noexcept;
187234976Stheraven    integral operator++() noexcept;
188234976Stheraven    integral operator--() volatile noexcept;
189234976Stheraven    integral operator--() noexcept;
190234976Stheraven    integral operator+=(integral op) volatile noexcept;
191234976Stheraven    integral operator+=(integral op) noexcept;
192234976Stheraven    integral operator-=(integral op) volatile noexcept;
193234976Stheraven    integral operator-=(integral op) noexcept;
194234976Stheraven    integral operator&=(integral op) volatile noexcept;
195234976Stheraven    integral operator&=(integral op) noexcept;
196234976Stheraven    integral operator|=(integral op) volatile noexcept;
197234976Stheraven    integral operator|=(integral op) noexcept;
198234976Stheraven    integral operator^=(integral op) volatile noexcept;
199234976Stheraven    integral operator^=(integral op) noexcept;
200227825Stheraven};
201227825Stheraven
202227825Stheraventemplate <class T>
203227825Stheravenstruct atomic<T*>
204227825Stheraven{
205234976Stheraven    bool is_lock_free() const volatile noexcept;
206234976Stheraven    bool is_lock_free() const noexcept;
207234976Stheraven    void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
208234976Stheraven    void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
209234976Stheraven    T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
210234976Stheraven    T* load(memory_order m = memory_order_seq_cst) const noexcept;
211234976Stheraven    operator T*() const volatile noexcept;
212234976Stheraven    operator T*() const noexcept;
213234976Stheraven    T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
214234976Stheraven    T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
215227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
216234976Stheraven                               memory_order s, memory_order f) volatile noexcept;
217227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
218234976Stheraven                               memory_order s, memory_order f) noexcept;
219227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
220234976Stheraven                                 memory_order s, memory_order f) volatile noexcept;
221227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
222234976Stheraven                                 memory_order s, memory_order f) noexcept;
223227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
224234976Stheraven                               memory_order m = memory_order_seq_cst) volatile noexcept;
225227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
226234976Stheraven                               memory_order m = memory_order_seq_cst) noexcept;
227227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
228234976Stheraven                                memory_order m = memory_order_seq_cst) volatile noexcept;
229227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
230234976Stheraven                                 memory_order m = memory_order_seq_cst) noexcept;
231234976Stheraven    T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
232234976Stheraven    T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
233234976Stheraven    T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
234234976Stheraven    T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
235227825Stheraven
236234976Stheraven    atomic() noexcept = default;
237234976Stheraven    constexpr atomic(T* desr) noexcept;
238227825Stheraven    atomic(const atomic&) = delete;
239227825Stheraven    atomic& operator=(const atomic&) = delete;
240227825Stheraven    atomic& operator=(const atomic&) volatile = delete;
241227825Stheraven
242234976Stheraven    T* operator=(T*) volatile noexcept;
243234976Stheraven    T* operator=(T*) noexcept;
244234976Stheraven    T* operator++(int) volatile noexcept;
245234976Stheraven    T* operator++(int) noexcept;
246234976Stheraven    T* operator--(int) volatile noexcept;
247234976Stheraven    T* operator--(int) noexcept;
248234976Stheraven    T* operator++() volatile noexcept;
249234976Stheraven    T* operator++() noexcept;
250234976Stheraven    T* operator--() volatile noexcept;
251234976Stheraven    T* operator--() noexcept;
252234976Stheraven    T* operator+=(ptrdiff_t op) volatile noexcept;
253234976Stheraven    T* operator+=(ptrdiff_t op) noexcept;
254234976Stheraven    T* operator-=(ptrdiff_t op) volatile noexcept;
255234976Stheraven    T* operator-=(ptrdiff_t op) noexcept;
256227825Stheraven};
257227825Stheraven
258227825Stheraven
259227825Stheraventemplate <class T>
260227825Stheraven    bool
261234976Stheraven    atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
262227825Stheraven
263227825Stheraventemplate <class T>
264227825Stheraven    bool
265234976Stheraven    atomic_is_lock_free(const atomic<T>* obj) noexcept;
266227825Stheraven
267227825Stheraventemplate <class T>
268227825Stheraven    void
269234976Stheraven    atomic_init(volatile atomic<T>* obj, T desr) noexcept;
270227825Stheraven
271227825Stheraventemplate <class T>
272227825Stheraven    void
273234976Stheraven    atomic_init(atomic<T>* obj, T desr) noexcept;
274227825Stheraven
275227825Stheraventemplate <class T>
276227825Stheraven    void
277234976Stheraven    atomic_store(volatile atomic<T>* obj, T desr) noexcept;
278227825Stheraven
279227825Stheraventemplate <class T>
280227825Stheraven    void
281234976Stheraven    atomic_store(atomic<T>* obj, T desr) noexcept;
282227825Stheraven
283227825Stheraventemplate <class T>
284227825Stheraven    void
285234976Stheraven    atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
286227825Stheraven
287227825Stheraventemplate <class T>
288227825Stheraven    void
289234976Stheraven    atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
290227825Stheraven
291227825Stheraventemplate <class T>
292227825Stheraven    T
293234976Stheraven    atomic_load(const volatile atomic<T>* obj) noexcept;
294227825Stheraven
295227825Stheraventemplate <class T>
296227825Stheraven    T
297234976Stheraven    atomic_load(const atomic<T>* obj) noexcept;
298227825Stheraven
299227825Stheraventemplate <class T>
300227825Stheraven    T
301234976Stheraven    atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
302227825Stheraven
303227825Stheraventemplate <class T>
304227825Stheraven    T
305234976Stheraven    atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
306227825Stheraven
307227825Stheraventemplate <class T>
308227825Stheraven    T
309234976Stheraven    atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
310227825Stheraven
311227825Stheraventemplate <class T>
312227825Stheraven    T
313234976Stheraven    atomic_exchange(atomic<T>* obj, T desr) noexcept;
314227825Stheraven
315227825Stheraventemplate <class T>
316227825Stheraven    T
317234976Stheraven    atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
318227825Stheraven
319227825Stheraventemplate <class T>
320227825Stheraven    T
321234976Stheraven    atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
322227825Stheraven
323227825Stheraventemplate <class T>
324227825Stheraven    bool
325234976Stheraven    atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
326227825Stheraven
327227825Stheraventemplate <class T>
328227825Stheraven    bool
329234976Stheraven    atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
330227825Stheraven
331227825Stheraventemplate <class T>
332227825Stheraven    bool
333234976Stheraven    atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
334227825Stheraven
335227825Stheraventemplate <class T>
336227825Stheraven    bool
337234976Stheraven    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,
343234976Stheraven                                          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,
348234976Stheraven                                          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,
354234976Stheraven                                            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,
360234976Stheraven                                            memory_order s, memory_order f) noexcept;
361227825Stheraven
362227825Stheraventemplate <class Integral>
363227825Stheraven    Integral
364234976Stheraven    atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
365227825Stheraven
366227825Stheraventemplate <class Integral>
367227825Stheraven    Integral
368234976Stheraven    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,
373234976Stheraven                              memory_order m) noexcept;
374227825Stheraventemplate <class Integral>
375227825Stheraven    Integral
376227825Stheraven    atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
377234976Stheraven                              memory_order m) noexcept;
378227825Stheraventemplate <class Integral>
379227825Stheraven    Integral
380234976Stheraven    atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
381227825Stheraven
382227825Stheraventemplate <class Integral>
383227825Stheraven    Integral
384234976Stheraven    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,
389234976Stheraven                              memory_order m) noexcept;
390227825Stheraventemplate <class Integral>
391227825Stheraven    Integral
392227825Stheraven    atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
393234976Stheraven                              memory_order m) noexcept;
394227825Stheraventemplate <class Integral>
395227825Stheraven    Integral
396234976Stheraven    atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
397227825Stheraven
398227825Stheraventemplate <class Integral>
399227825Stheraven    Integral
400234976Stheraven    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,
405234976Stheraven                              memory_order m) noexcept;
406227825Stheraventemplate <class Integral>
407227825Stheraven    Integral
408227825Stheraven    atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
409234976Stheraven                              memory_order m) noexcept;
410227825Stheraventemplate <class Integral>
411227825Stheraven    Integral
412234976Stheraven    atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
413227825Stheraven
414227825Stheraventemplate <class Integral>
415227825Stheraven    Integral
416234976Stheraven    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,
421234976Stheraven                             memory_order m) noexcept;
422227825Stheraventemplate <class Integral>
423227825Stheraven    Integral
424227825Stheraven    atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
425234976Stheraven                             memory_order m) noexcept;
426227825Stheraventemplate <class Integral>
427227825Stheraven    Integral
428234976Stheraven    atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
429227825Stheraven
430227825Stheraventemplate <class Integral>
431227825Stheraven    Integral
432234976Stheraven    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,
437234976Stheraven                              memory_order m) noexcept;
438227825Stheraventemplate <class Integral>
439227825Stheraven    Integral
440227825Stheraven    atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
441234976Stheraven                              memory_order m) noexcept;
442227825Stheraven
443227825Stheraventemplate <class T>
444227825Stheraven    T*
445234976Stheraven    atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
446227825Stheraven
447227825Stheraventemplate <class T>
448227825Stheraven    T*
449234976Stheraven    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,
454234976Stheraven                              memory_order m) noexcept;
455227825Stheraventemplate <class T>
456227825Stheraven    T*
457234976Stheraven    atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
458227825Stheraven
459227825Stheraventemplate <class T>
460227825Stheraven    T*
461234976Stheraven    atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
462227825Stheraven
463227825Stheraventemplate <class T>
464227825Stheraven    T*
465234976Stheraven    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,
470234976Stheraven                              memory_order m) noexcept;
471227825Stheraventemplate <class T>
472227825Stheraven    T*
473234976Stheraven    atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
474227825Stheraven
475227825Stheraven// Atomics for standard typedef types
476227825Stheraven
477250514Sdimtypedef 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
520234976Stheravenvoid atomic_thread_fence(memory_order m) noexcept;
521234976Stheravenvoid 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
551234976Stheravenkill_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{
561243376Sdim    mutable _Atomic(_Tp) __a_;
562227825Stheraven
563227825Stheraven    _LIBCPP_INLINE_VISIBILITY
564234976Stheraven    bool is_lock_free() const volatile _NOEXCEPT
565234976Stheraven        {return __c11_atomic_is_lock_free(sizeof(_Tp));}
566227825Stheraven    _LIBCPP_INLINE_VISIBILITY
567234976Stheraven    bool is_lock_free() const _NOEXCEPT
568234976Stheraven        {return __c11_atomic_is_lock_free(sizeof(_Tp));}
569227825Stheraven    _LIBCPP_INLINE_VISIBILITY
570234976Stheraven    void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
571234976Stheraven        {__c11_atomic_store(&__a_, __d, __m);}
572227825Stheraven    _LIBCPP_INLINE_VISIBILITY
573234976Stheraven    void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
574234976Stheraven        {__c11_atomic_store(&__a_, __d, __m);}
575227825Stheraven    _LIBCPP_INLINE_VISIBILITY
576234976Stheraven    _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
577234976Stheraven        {return __c11_atomic_load(&__a_, __m);}
578227825Stheraven    _LIBCPP_INLINE_VISIBILITY
579234976Stheraven    _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
580234976Stheraven        {return __c11_atomic_load(&__a_, __m);}
581227825Stheraven    _LIBCPP_INLINE_VISIBILITY
582234976Stheraven    operator _Tp() const volatile _NOEXCEPT {return load();}
583227825Stheraven    _LIBCPP_INLINE_VISIBILITY
584234976Stheraven    operator _Tp() const _NOEXCEPT          {return load();}
585227825Stheraven    _LIBCPP_INLINE_VISIBILITY
586234976Stheraven    _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
587234976Stheraven        {return __c11_atomic_exchange(&__a_, __d, __m);}
588227825Stheraven    _LIBCPP_INLINE_VISIBILITY
589234976Stheraven    _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
590234976Stheraven        {return __c11_atomic_exchange(&__a_, __d, __m);}
591227825Stheraven    _LIBCPP_INLINE_VISIBILITY
592227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
593234976Stheraven                               memory_order __s, memory_order __f) volatile _NOEXCEPT
594234976Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
595227825Stheraven    _LIBCPP_INLINE_VISIBILITY
596227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
597234976Stheraven                               memory_order __s, memory_order __f) _NOEXCEPT
598234976Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
599227825Stheraven    _LIBCPP_INLINE_VISIBILITY
600227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
601234976Stheraven                                 memory_order __s, memory_order __f) volatile _NOEXCEPT
602234976Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
603227825Stheraven    _LIBCPP_INLINE_VISIBILITY
604227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
605234976Stheraven                                 memory_order __s, memory_order __f) _NOEXCEPT
606234976Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
607227825Stheraven    _LIBCPP_INLINE_VISIBILITY
608227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
609234976Stheraven                              memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
610234976Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
611227825Stheraven    _LIBCPP_INLINE_VISIBILITY
612227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
613234976Stheraven                               memory_order __m = memory_order_seq_cst) _NOEXCEPT
614234976Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
615227825Stheraven    _LIBCPP_INLINE_VISIBILITY
616227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
617234976Stheraven                              memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
618234976Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
619227825Stheraven    _LIBCPP_INLINE_VISIBILITY
620227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
621234976Stheraven                                 memory_order __m = memory_order_seq_cst) _NOEXCEPT
622234976Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
623227825Stheraven
624227825Stheraven    _LIBCPP_INLINE_VISIBILITY
625253222Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
626253222Sdim    __atomic_base() _NOEXCEPT = default;
627253222Sdim#else
628253222Sdim    __atomic_base() _NOEXCEPT : __a_() {}
629253222Sdim#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
630253222Sdim
631227825Stheraven    _LIBCPP_INLINE_VISIBILITY
632234976Stheraven    _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
653253222Sdim    __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
654227825Stheraven    _LIBCPP_INLINE_VISIBILITY
655234976Stheraven    _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
656227825Stheraven
657227825Stheraven    _LIBCPP_INLINE_VISIBILITY
658234976Stheraven    _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
659234976Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
660227825Stheraven    _LIBCPP_INLINE_VISIBILITY
661234976Stheraven    _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
662234976Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
663227825Stheraven    _LIBCPP_INLINE_VISIBILITY
664234976Stheraven    _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
665234976Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
666227825Stheraven    _LIBCPP_INLINE_VISIBILITY
667234976Stheraven    _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
668234976Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
669227825Stheraven    _LIBCPP_INLINE_VISIBILITY
670234976Stheraven    _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
671234976Stheraven        {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
672227825Stheraven    _LIBCPP_INLINE_VISIBILITY
673234976Stheraven    _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
674234976Stheraven        {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
675227825Stheraven    _LIBCPP_INLINE_VISIBILITY
676234976Stheraven    _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
677234976Stheraven        {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
678227825Stheraven    _LIBCPP_INLINE_VISIBILITY
679234976Stheraven    _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
680234976Stheraven        {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
681227825Stheraven    _LIBCPP_INLINE_VISIBILITY
682234976Stheraven    _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
683234976Stheraven        {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
684227825Stheraven    _LIBCPP_INLINE_VISIBILITY
685234976Stheraven    _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
686234976Stheraven        {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
687227825Stheraven
688227825Stheraven    _LIBCPP_INLINE_VISIBILITY
689234976Stheraven    _Tp operator++(int) volatile _NOEXCEPT      {return fetch_add(_Tp(1));}
690227825Stheraven    _LIBCPP_INLINE_VISIBILITY
691234976Stheraven    _Tp operator++(int) _NOEXCEPT               {return fetch_add(_Tp(1));}
692227825Stheraven    _LIBCPP_INLINE_VISIBILITY
693234976Stheraven    _Tp operator--(int) volatile _NOEXCEPT      {return fetch_sub(_Tp(1));}
694227825Stheraven    _LIBCPP_INLINE_VISIBILITY
695234976Stheraven    _Tp operator--(int) _NOEXCEPT               {return fetch_sub(_Tp(1));}
696227825Stheraven    _LIBCPP_INLINE_VISIBILITY
697234976Stheraven    _Tp operator++() volatile _NOEXCEPT         {return fetch_add(_Tp(1)) + _Tp(1);}
698227825Stheraven    _LIBCPP_INLINE_VISIBILITY
699234976Stheraven    _Tp operator++() _NOEXCEPT                  {return fetch_add(_Tp(1)) + _Tp(1);}
700227825Stheraven    _LIBCPP_INLINE_VISIBILITY
701234976Stheraven    _Tp operator--() volatile _NOEXCEPT         {return fetch_sub(_Tp(1)) - _Tp(1);}
702227825Stheraven    _LIBCPP_INLINE_VISIBILITY
703234976Stheraven    _Tp operator--() _NOEXCEPT                  {return fetch_sub(_Tp(1)) - _Tp(1);}
704227825Stheraven    _LIBCPP_INLINE_VISIBILITY
705234976Stheraven    _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
706227825Stheraven    _LIBCPP_INLINE_VISIBILITY
707234976Stheraven    _Tp operator+=(_Tp __op) _NOEXCEPT          {return fetch_add(__op) + __op;}
708227825Stheraven    _LIBCPP_INLINE_VISIBILITY
709234976Stheraven    _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
710227825Stheraven    _LIBCPP_INLINE_VISIBILITY
711234976Stheraven    _Tp operator-=(_Tp __op) _NOEXCEPT          {return fetch_sub(__op) - __op;}
712227825Stheraven    _LIBCPP_INLINE_VISIBILITY
713234976Stheraven    _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
714227825Stheraven    _LIBCPP_INLINE_VISIBILITY
715234976Stheraven    _Tp operator&=(_Tp __op) _NOEXCEPT          {return fetch_and(__op) & __op;}
716227825Stheraven    _LIBCPP_INLINE_VISIBILITY
717234976Stheraven    _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
718227825Stheraven    _LIBCPP_INLINE_VISIBILITY
719234976Stheraven    _Tp operator|=(_Tp __op) _NOEXCEPT          {return fetch_or(__op) | __op;}
720227825Stheraven    _LIBCPP_INLINE_VISIBILITY
721234976Stheraven    _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
722227825Stheraven    _LIBCPP_INLINE_VISIBILITY
723234976Stheraven    _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
734253222Sdim    atomic() _NOEXCEPT _LIBCPP_DEFAULT
735227825Stheraven    _LIBCPP_INLINE_VISIBILITY
736234976Stheraven    _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
737227825Stheraven
738227825Stheraven    _LIBCPP_INLINE_VISIBILITY
739234976Stheraven    _Tp operator=(_Tp __d) volatile _NOEXCEPT
740227825Stheraven        {__base::store(__d); return __d;}
741227825Stheraven    _LIBCPP_INLINE_VISIBILITY
742234976Stheraven    _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
754253222Sdim    atomic() _NOEXCEPT _LIBCPP_DEFAULT
755227825Stheraven    _LIBCPP_INLINE_VISIBILITY
756234976Stheraven    _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
757227825Stheraven
758227825Stheraven    _LIBCPP_INLINE_VISIBILITY
759234976Stheraven    _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
760227825Stheraven        {__base::store(__d); return __d;}
761227825Stheraven    _LIBCPP_INLINE_VISIBILITY
762234976Stheraven    _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)
767234976Stheraven                                                                        volatile _NOEXCEPT
768234976Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
769227825Stheraven    _LIBCPP_INLINE_VISIBILITY
770234976Stheraven    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
771234976Stheraven        {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)
774234976Stheraven                                                                        volatile _NOEXCEPT
775234976Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
776227825Stheraven    _LIBCPP_INLINE_VISIBILITY
777234976Stheraven    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
778234976Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
779227825Stheraven
780227825Stheraven    _LIBCPP_INLINE_VISIBILITY
781234976Stheraven    _Tp* operator++(int) volatile _NOEXCEPT            {return fetch_add(1);}
782227825Stheraven    _LIBCPP_INLINE_VISIBILITY
783234976Stheraven    _Tp* operator++(int) _NOEXCEPT                     {return fetch_add(1);}
784227825Stheraven    _LIBCPP_INLINE_VISIBILITY
785234976Stheraven    _Tp* operator--(int) volatile _NOEXCEPT            {return fetch_sub(1);}
786227825Stheraven    _LIBCPP_INLINE_VISIBILITY
787234976Stheraven    _Tp* operator--(int) _NOEXCEPT                     {return fetch_sub(1);}
788227825Stheraven    _LIBCPP_INLINE_VISIBILITY
789234976Stheraven    _Tp* operator++() volatile _NOEXCEPT               {return fetch_add(1) + 1;}
790227825Stheraven    _LIBCPP_INLINE_VISIBILITY
791234976Stheraven    _Tp* operator++() _NOEXCEPT                        {return fetch_add(1) + 1;}
792227825Stheraven    _LIBCPP_INLINE_VISIBILITY
793234976Stheraven    _Tp* operator--() volatile _NOEXCEPT               {return fetch_sub(1) - 1;}
794227825Stheraven    _LIBCPP_INLINE_VISIBILITY
795234976Stheraven    _Tp* operator--() _NOEXCEPT                        {return fetch_sub(1) - 1;}
796227825Stheraven    _LIBCPP_INLINE_VISIBILITY
797234976Stheraven    _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
798227825Stheraven    _LIBCPP_INLINE_VISIBILITY
799234976Stheraven    _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT          {return fetch_add(__op) + __op;}
800227825Stheraven    _LIBCPP_INLINE_VISIBILITY
801234976Stheraven    _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
802227825Stheraven    _LIBCPP_INLINE_VISIBILITY
803234976Stheraven    _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
811234976Stheravenatomic_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
819234976Stheravenatomic_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
829234976Stheravenatomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
830227825Stheraven{
831234976Stheraven    __c11_atomic_init(&__o->__a_, __d);
832227825Stheraven}
833227825Stheraven
834227825Stheraventemplate <class _Tp>
835227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
836227825Stheravenvoid
837234976Stheravenatomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
838227825Stheraven{
839234976Stheraven    __c11_atomic_init(&__o->__a_, __d);
840227825Stheraven}
841227825Stheraven
842227825Stheraven// atomic_store
843227825Stheraven
844227825Stheraventemplate <class _Tp>
845227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
846227825Stheravenvoid
847234976Stheravenatomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
848227825Stheraven{
849227825Stheraven    __o->store(__d);
850227825Stheraven}
851227825Stheraven
852227825Stheraventemplate <class _Tp>
853227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
854227825Stheravenvoid
855234976Stheravenatomic_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
865234976Stheravenatomic_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
873234976Stheravenatomic_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
883234976Stheravenatomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
884227825Stheraven{
885227825Stheraven    return __o->load();
886227825Stheraven}
887227825Stheraven
888227825Stheraventemplate <class _Tp>
889227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
890227825Stheraven_Tp
891234976Stheravenatomic_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
901234976Stheravenatomic_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
909234976Stheravenatomic_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
919234976Stheravenatomic_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
927234976Stheravenatomic_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
937234976Stheravenatomic_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
945234976Stheravenatomic_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
955234976Stheravenatomic_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
963234976Stheravenatomic_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
973234976Stheravenatomic_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
981234976Stheravenatomic_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,
993234976Stheraven                                      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,
1002234976Stheraven                                      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,
1014234976Stheraven                                        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,
1024234976Stheraven                                        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
1038234976Stheravenatomic_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
1050234976Stheravenatomic_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*
1058234976Stheravenatomic_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*
1066234976Stheravenatomic_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
1080234976Stheravenatomic_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
1092234976Stheravenatomic_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,
1101234976Stheraven                          memory_order __m) _NOEXCEPT
1102227825Stheraven{
1103227825Stheraven    return __o->fetch_add(__op, __m);
1104227825Stheraven}
1105227825Stheraven
1106227825Stheraventemplate <class _Tp>
1107227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1108227825Stheraven_Tp*
1109234976Stheravenatomic_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
1123234976Stheravenatomic_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
1135234976Stheravenatomic_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*
1143234976Stheravenatomic_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*
1151234976Stheravenatomic_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
1165234976Stheravenatomic_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
1177234976Stheravenatomic_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,
1186234976Stheraven                          memory_order __m) _NOEXCEPT
1187227825Stheraven{
1188227825Stheraven    return __o->fetch_sub(__op, __m);
1189227825Stheraven}
1190227825Stheraven
1191227825Stheraventemplate <class _Tp>
1192227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1193227825Stheraven_Tp*
1194234976Stheravenatomic_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
1208234976Stheravenatomic_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
1220234976Stheravenatomic_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
1234234976Stheravenatomic_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
1246234976Stheravenatomic_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
1260234976Stheravenatomic_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
1272234976Stheravenatomic_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
1286234976Stheravenatomic_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
1298234976Stheravenatomic_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
1312234976Stheravenatomic_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
1324234976Stheravenatomic_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
1338234976Stheravenatomic_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
1350234976Stheravenatomic_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{
1359232950Stheraven    _Atomic(bool) __a_;
1360227825Stheraven
1361227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1362234976Stheraven    bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
1363234976Stheraven        {return __c11_atomic_exchange(&__a_, true, __m);}
1364227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1365234976Stheraven    bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
1366234976Stheraven        {return __c11_atomic_exchange(&__a_, true, __m);}
1367227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1368234976Stheraven    void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
1369234976Stheraven        {__c11_atomic_store(&__a_, false, __m);}
1370227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1371234976Stheraven    void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
1372234976Stheraven        {__c11_atomic_store(&__a_, false, __m);}
1373227825Stheraven
1374227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1375253222Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1376253222Sdim    atomic_flag() _NOEXCEPT = default;
1377253222Sdim#else
1378253222Sdim    atomic_flag() _NOEXCEPT : __a_() {}
1379253222Sdim#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1380253222Sdim
1381227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1382234976Stheraven    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
1398234976Stheravenatomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
1399227825Stheraven{
1400227825Stheraven    return __o->test_and_set();
1401227825Stheraven}
1402227825Stheraven
1403227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1404227825Stheravenbool
1405234976Stheravenatomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
1406227825Stheraven{
1407227825Stheraven    return __o->test_and_set();
1408227825Stheraven}
1409227825Stheraven
1410227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1411227825Stheravenbool
1412234976Stheravenatomic_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
1419234976Stheravenatomic_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
1426234976Stheravenatomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
1427227825Stheraven{
1428227825Stheraven    __o->clear();
1429227825Stheraven}
1430227825Stheraven
1431227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1432227825Stheravenvoid
1433234976Stheravenatomic_flag_clear(atomic_flag* __o) _NOEXCEPT
1434227825Stheraven{
1435227825Stheraven    __o->clear();
1436227825Stheraven}
1437227825Stheraven
1438227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1439227825Stheravenvoid
1440234976Stheravenatomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
1441227825Stheraven{
1442227825Stheraven    __o->clear(__m);
1443227825Stheraven}
1444227825Stheraven
1445227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1446227825Stheravenvoid
1447234976Stheravenatomic_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
1456234976Stheravenatomic_thread_fence(memory_order __m) _NOEXCEPT
1457227825Stheraven{
1458234976Stheraven    __c11_atomic_thread_fence(__m);
1459227825Stheraven}
1460227825Stheraven
1461227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1462227825Stheravenvoid
1463234976Stheravenatomic_signal_fence(memory_order __m) _NOEXCEPT
1464227825Stheraven{
1465234976Stheraven    __c11_atomic_signal_fence(__m);
1466227825Stheraven}
1467227825Stheraven
1468227825Stheraven// Atomics for standard typedef types
1469227825Stheraven
1470250514Sdimtypedef 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
1516250514Sdim#define ATOMIC_BOOL_LOCK_FREE      __GCC_ATOMIC_BOOL_LOCK_FREE
1517250514Sdim#define ATOMIC_CHAR_LOCK_FREE      __GCC_ATOMIC_CHAR_LOCK_FREE
1518250514Sdim#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
1519250514Sdim#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
1520250514Sdim#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
1521250514Sdim#define ATOMIC_SHORT_LOCK_FREE     __GCC_ATOMIC_SHORT_LOCK_FREE
1522250514Sdim#define ATOMIC_INT_LOCK_FREE       __GCC_ATOMIC_INT_LOCK_FREE
1523250514Sdim#define ATOMIC_LONG_LOCK_FREE      __GCC_ATOMIC_LONG_LOCK_FREE
1524250514Sdim#define ATOMIC_LLONG_LOCK_FREE     __GCC_ATOMIC_LLONG_LOCK_FREE
1525250514Sdim#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
1526227825Stheraven
1527227825Stheraven#endif  //  !__has_feature(cxx_atomic)
1528227825Stheraven
1529227825Stheraven_LIBCPP_END_NAMESPACE_STD
1530227825Stheraven
1531227825Stheraven#endif  // _LIBCPP_ATOMIC
1532