atomic revision 246468
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
32234959Stheraventemplate <class T> T kill_dependency(T y) noexcept;
33227825Stheraven
34227825Stheraven// lock-free property
35227825Stheraven
36246468Stheraven#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
45246468Stheraven#define ATOMIC_POINTER_LOCK_FREE unspecified
46227825Stheraven
47227825Stheraven// flag type and operations
48227825Stheraven
49227825Stheraventypedef struct atomic_flag
50227825Stheraven{
51234959Stheraven    bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
52234959Stheraven    bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
53234959Stheraven    void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
54234959Stheraven    void clear(memory_order m = memory_order_seq_cst) noexcept;
55234959Stheraven    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
62234959Stheraven    atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
63227825Stheraven
64227825Stheravenbool
65234959Stheraven    atomic_flag_test_and_set(atomic_flag* obj) noexcept;
66227825Stheraven
67227825Stheravenbool
68227825Stheraven    atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
69234959Stheraven                                      memory_order m) noexcept;
70227825Stheraven
71227825Stheravenbool
72234959Stheraven    atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
73227825Stheraven
74227825Stheravenvoid
75234959Stheraven    atomic_flag_clear(volatile atomic_flag* obj) noexcept;
76227825Stheraven
77227825Stheravenvoid
78234959Stheraven    atomic_flag_clear(atomic_flag* obj) noexcept;
79227825Stheraven
80227825Stheravenvoid
81234959Stheraven    atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
82227825Stheraven
83227825Stheravenvoid
84234959Stheraven    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{
92234959Stheraven    bool is_lock_free() const volatile noexcept;
93234959Stheraven    bool is_lock_free() const noexcept;
94234959Stheraven    void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
95234959Stheraven    void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
96234959Stheraven    T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
97234959Stheraven    T load(memory_order m = memory_order_seq_cst) const noexcept;
98234959Stheraven    operator T() const volatile noexcept;
99234959Stheraven    operator T() const noexcept;
100234959Stheraven    T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
101234959Stheraven    T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
102227825Stheraven    bool compare_exchange_weak(T& expc, T desr,
103234959Stheraven                               memory_order s, memory_order f) volatile noexcept;
104234959Stheraven    bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept;
105227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
106234959Stheraven                                 memory_order s, memory_order f) volatile noexcept;
107227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
108234959Stheraven                                 memory_order s, memory_order f) noexcept;
109227825Stheraven    bool compare_exchange_weak(T& expc, T desr,
110234959Stheraven                               memory_order m = memory_order_seq_cst) volatile noexcept;
111227825Stheraven    bool compare_exchange_weak(T& expc, T desr,
112234959Stheraven                               memory_order m = memory_order_seq_cst) noexcept;
113227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
114234959Stheraven                                memory_order m = memory_order_seq_cst) volatile noexcept;
115227825Stheraven    bool compare_exchange_strong(T& expc, T desr,
116234959Stheraven                                 memory_order m = memory_order_seq_cst) noexcept;
117227825Stheraven
118234959Stheraven    atomic() noexcept = default;
119234959Stheraven    constexpr atomic(T desr) noexcept;
120227825Stheraven    atomic(const atomic&) = delete;
121227825Stheraven    atomic& operator=(const atomic&) = delete;
122227825Stheraven    atomic& operator=(const atomic&) volatile = delete;
123234959Stheraven    T operator=(T) volatile noexcept;
124234959Stheraven    T operator=(T) noexcept;
125227825Stheraven};
126227825Stheraven
127227825Stheraventemplate <>
128227825Stheravenstruct atomic<integral>
129227825Stheraven{
130234959Stheraven    bool is_lock_free() const volatile noexcept;
131234959Stheraven    bool is_lock_free() const noexcept;
132234959Stheraven    void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
133234959Stheraven    void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
134234959Stheraven    integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
135234959Stheraven    integral load(memory_order m = memory_order_seq_cst) const noexcept;
136234959Stheraven    operator integral() const volatile noexcept;
137234959Stheraven    operator integral() const noexcept;
138227825Stheraven    integral exchange(integral desr,
139234959Stheraven                      memory_order m = memory_order_seq_cst) volatile noexcept;
140234959Stheraven    integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
141227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
142234959Stheraven                               memory_order s, memory_order f) volatile noexcept;
143227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
144234959Stheraven                               memory_order s, memory_order f) noexcept;
145227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
146234959Stheraven                                 memory_order s, memory_order f) volatile noexcept;
147227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
148234959Stheraven                                 memory_order s, memory_order f) noexcept;
149227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
150234959Stheraven                               memory_order m = memory_order_seq_cst) volatile noexcept;
151227825Stheraven    bool compare_exchange_weak(integral& expc, integral desr,
152234959Stheraven                               memory_order m = memory_order_seq_cst) noexcept;
153227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
154234959Stheraven                                memory_order m = memory_order_seq_cst) volatile noexcept;
155227825Stheraven    bool compare_exchange_strong(integral& expc, integral desr,
156234959Stheraven                                 memory_order m = memory_order_seq_cst) noexcept;
157227825Stheraven
158227825Stheraven    integral
159234959Stheraven        fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
160234959Stheraven    integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
161227825Stheraven    integral
162234959Stheraven        fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
163234959Stheraven    integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
164227825Stheraven    integral
165234959Stheraven        fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
166234959Stheraven    integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
167227825Stheraven    integral
168234959Stheraven        fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
169234959Stheraven    integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
170227825Stheraven    integral
171234959Stheraven        fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
172234959Stheraven    integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
173227825Stheraven
174234959Stheraven    atomic() noexcept = default;
175234959Stheraven    constexpr atomic(integral desr) noexcept;
176227825Stheraven    atomic(const atomic&) = delete;
177227825Stheraven    atomic& operator=(const atomic&) = delete;
178227825Stheraven    atomic& operator=(const atomic&) volatile = delete;
179234959Stheraven    integral operator=(integral desr) volatile noexcept;
180234959Stheraven    integral operator=(integral desr) noexcept;
181227825Stheraven
182234959Stheraven    integral operator++(int) volatile noexcept;
183234959Stheraven    integral operator++(int) noexcept;
184234959Stheraven    integral operator--(int) volatile noexcept;
185234959Stheraven    integral operator--(int) noexcept;
186234959Stheraven    integral operator++() volatile noexcept;
187234959Stheraven    integral operator++() noexcept;
188234959Stheraven    integral operator--() volatile noexcept;
189234959Stheraven    integral operator--() noexcept;
190234959Stheraven    integral operator+=(integral op) volatile noexcept;
191234959Stheraven    integral operator+=(integral op) noexcept;
192234959Stheraven    integral operator-=(integral op) volatile noexcept;
193234959Stheraven    integral operator-=(integral op) noexcept;
194234959Stheraven    integral operator&=(integral op) volatile noexcept;
195234959Stheraven    integral operator&=(integral op) noexcept;
196234959Stheraven    integral operator|=(integral op) volatile noexcept;
197234959Stheraven    integral operator|=(integral op) noexcept;
198234959Stheraven    integral operator^=(integral op) volatile noexcept;
199234959Stheraven    integral operator^=(integral op) noexcept;
200227825Stheraven};
201227825Stheraven
202227825Stheraventemplate <class T>
203227825Stheravenstruct atomic<T*>
204227825Stheraven{
205234959Stheraven    bool is_lock_free() const volatile noexcept;
206234959Stheraven    bool is_lock_free() const noexcept;
207234959Stheraven    void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
208234959Stheraven    void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
209234959Stheraven    T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
210234959Stheraven    T* load(memory_order m = memory_order_seq_cst) const noexcept;
211234959Stheraven    operator T*() const volatile noexcept;
212234959Stheraven    operator T*() const noexcept;
213234959Stheraven    T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
214234959Stheraven    T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
215227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
216234959Stheraven                               memory_order s, memory_order f) volatile noexcept;
217227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
218234959Stheraven                               memory_order s, memory_order f) noexcept;
219227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
220234959Stheraven                                 memory_order s, memory_order f) volatile noexcept;
221227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
222234959Stheraven                                 memory_order s, memory_order f) noexcept;
223227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
224234959Stheraven                               memory_order m = memory_order_seq_cst) volatile noexcept;
225227825Stheraven    bool compare_exchange_weak(T*& expc, T* desr,
226234959Stheraven                               memory_order m = memory_order_seq_cst) noexcept;
227227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
228234959Stheraven                                memory_order m = memory_order_seq_cst) volatile noexcept;
229227825Stheraven    bool compare_exchange_strong(T*& expc, T* desr,
230234959Stheraven                                 memory_order m = memory_order_seq_cst) noexcept;
231234959Stheraven    T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
232234959Stheraven    T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
233234959Stheraven    T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
234234959Stheraven    T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
235227825Stheraven
236234959Stheraven    atomic() noexcept = default;
237234959Stheraven    constexpr atomic(T* desr) noexcept;
238227825Stheraven    atomic(const atomic&) = delete;
239227825Stheraven    atomic& operator=(const atomic&) = delete;
240227825Stheraven    atomic& operator=(const atomic&) volatile = delete;
241227825Stheraven
242234959Stheraven    T* operator=(T*) volatile noexcept;
243234959Stheraven    T* operator=(T*) noexcept;
244234959Stheraven    T* operator++(int) volatile noexcept;
245234959Stheraven    T* operator++(int) noexcept;
246234959Stheraven    T* operator--(int) volatile noexcept;
247234959Stheraven    T* operator--(int) noexcept;
248234959Stheraven    T* operator++() volatile noexcept;
249234959Stheraven    T* operator++() noexcept;
250234959Stheraven    T* operator--() volatile noexcept;
251234959Stheraven    T* operator--() noexcept;
252234959Stheraven    T* operator+=(ptrdiff_t op) volatile noexcept;
253234959Stheraven    T* operator+=(ptrdiff_t op) noexcept;
254234959Stheraven    T* operator-=(ptrdiff_t op) volatile noexcept;
255234959Stheraven    T* operator-=(ptrdiff_t op) noexcept;
256227825Stheraven};
257227825Stheraven
258227825Stheraven
259227825Stheraventemplate <class T>
260227825Stheraven    bool
261234959Stheraven    atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
262227825Stheraven
263227825Stheraventemplate <class T>
264227825Stheraven    bool
265234959Stheraven    atomic_is_lock_free(const atomic<T>* obj) noexcept;
266227825Stheraven
267227825Stheraventemplate <class T>
268227825Stheraven    void
269234959Stheraven    atomic_init(volatile atomic<T>* obj, T desr) noexcept;
270227825Stheraven
271227825Stheraventemplate <class T>
272227825Stheraven    void
273234959Stheraven    atomic_init(atomic<T>* obj, T desr) noexcept;
274227825Stheraven
275227825Stheraventemplate <class T>
276227825Stheraven    void
277234959Stheraven    atomic_store(volatile atomic<T>* obj, T desr) noexcept;
278227825Stheraven
279227825Stheraventemplate <class T>
280227825Stheraven    void
281234959Stheraven    atomic_store(atomic<T>* obj, T desr) noexcept;
282227825Stheraven
283227825Stheraventemplate <class T>
284227825Stheraven    void
285234959Stheraven    atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
286227825Stheraven
287227825Stheraventemplate <class T>
288227825Stheraven    void
289234959Stheraven    atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
290227825Stheraven
291227825Stheraventemplate <class T>
292227825Stheraven    T
293234959Stheraven    atomic_load(const volatile atomic<T>* obj) noexcept;
294227825Stheraven
295227825Stheraventemplate <class T>
296227825Stheraven    T
297234959Stheraven    atomic_load(const atomic<T>* obj) noexcept;
298227825Stheraven
299227825Stheraventemplate <class T>
300227825Stheraven    T
301234959Stheraven    atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
302227825Stheraven
303227825Stheraventemplate <class T>
304227825Stheraven    T
305234959Stheraven    atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
306227825Stheraven
307227825Stheraventemplate <class T>
308227825Stheraven    T
309234959Stheraven    atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
310227825Stheraven
311227825Stheraventemplate <class T>
312227825Stheraven    T
313234959Stheraven    atomic_exchange(atomic<T>* obj, T desr) noexcept;
314227825Stheraven
315227825Stheraventemplate <class T>
316227825Stheraven    T
317234959Stheraven    atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
318227825Stheraven
319227825Stheraventemplate <class T>
320227825Stheraven    T
321234959Stheraven    atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
322227825Stheraven
323227825Stheraventemplate <class T>
324227825Stheraven    bool
325234959Stheraven    atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
326227825Stheraven
327227825Stheraventemplate <class T>
328227825Stheraven    bool
329234959Stheraven    atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
330227825Stheraven
331227825Stheraventemplate <class T>
332227825Stheraven    bool
333234959Stheraven    atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
334227825Stheraven
335227825Stheraventemplate <class T>
336227825Stheraven    bool
337234959Stheraven    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,
343234959Stheraven                                          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,
348234959Stheraven                                          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,
354234959Stheraven                                            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,
360234959Stheraven                                            memory_order s, memory_order f) noexcept;
361227825Stheraven
362227825Stheraventemplate <class Integral>
363227825Stheraven    Integral
364234959Stheraven    atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
365227825Stheraven
366227825Stheraventemplate <class Integral>
367227825Stheraven    Integral
368234959Stheraven    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,
373234959Stheraven                              memory_order m) noexcept;
374227825Stheraventemplate <class Integral>
375227825Stheraven    Integral
376227825Stheraven    atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
377234959Stheraven                              memory_order m) noexcept;
378227825Stheraventemplate <class Integral>
379227825Stheraven    Integral
380234959Stheraven    atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
381227825Stheraven
382227825Stheraventemplate <class Integral>
383227825Stheraven    Integral
384234959Stheraven    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,
389234959Stheraven                              memory_order m) noexcept;
390227825Stheraventemplate <class Integral>
391227825Stheraven    Integral
392227825Stheraven    atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
393234959Stheraven                              memory_order m) noexcept;
394227825Stheraventemplate <class Integral>
395227825Stheraven    Integral
396234959Stheraven    atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
397227825Stheraven
398227825Stheraventemplate <class Integral>
399227825Stheraven    Integral
400234959Stheraven    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,
405234959Stheraven                              memory_order m) noexcept;
406227825Stheraventemplate <class Integral>
407227825Stheraven    Integral
408227825Stheraven    atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
409234959Stheraven                              memory_order m) noexcept;
410227825Stheraventemplate <class Integral>
411227825Stheraven    Integral
412234959Stheraven    atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
413227825Stheraven
414227825Stheraventemplate <class Integral>
415227825Stheraven    Integral
416234959Stheraven    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,
421234959Stheraven                             memory_order m) noexcept;
422227825Stheraventemplate <class Integral>
423227825Stheraven    Integral
424227825Stheraven    atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
425234959Stheraven                             memory_order m) noexcept;
426227825Stheraventemplate <class Integral>
427227825Stheraven    Integral
428234959Stheraven    atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
429227825Stheraven
430227825Stheraventemplate <class Integral>
431227825Stheraven    Integral
432234959Stheraven    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,
437234959Stheraven                              memory_order m) noexcept;
438227825Stheraventemplate <class Integral>
439227825Stheraven    Integral
440227825Stheraven    atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
441234959Stheraven                              memory_order m) noexcept;
442227825Stheraven
443227825Stheraventemplate <class T>
444227825Stheraven    T*
445234959Stheraven    atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
446227825Stheraven
447227825Stheraventemplate <class T>
448227825Stheraven    T*
449234959Stheraven    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,
454234959Stheraven                              memory_order m) noexcept;
455227825Stheraventemplate <class T>
456227825Stheraven    T*
457234959Stheraven    atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
458227825Stheraven
459227825Stheraventemplate <class T>
460227825Stheraven    T*
461234959Stheraven    atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
462227825Stheraven
463227825Stheraventemplate <class T>
464227825Stheraven    T*
465234959Stheraven    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,
470234959Stheraven                              memory_order m) noexcept;
471227825Stheraventemplate <class T>
472227825Stheraven    T*
473234959Stheraven    atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
474227825Stheraven
475227825Stheraven// Atomics for standard typedef types
476227825Stheraven
477246468Stheraventypedef 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
520234959Stheravenvoid atomic_thread_fence(memory_order m) noexcept;
521234959Stheravenvoid 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
551234959Stheravenkill_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{
561241900Sdim    mutable _Atomic(_Tp) __a_;
562227825Stheraven
563227825Stheraven    _LIBCPP_INLINE_VISIBILITY
564234959Stheraven    bool is_lock_free() const volatile _NOEXCEPT
565234959Stheraven        {return __c11_atomic_is_lock_free(sizeof(_Tp));}
566227825Stheraven    _LIBCPP_INLINE_VISIBILITY
567234959Stheraven    bool is_lock_free() const _NOEXCEPT
568234959Stheraven        {return __c11_atomic_is_lock_free(sizeof(_Tp));}
569227825Stheraven    _LIBCPP_INLINE_VISIBILITY
570234959Stheraven    void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
571234959Stheraven        {__c11_atomic_store(&__a_, __d, __m);}
572227825Stheraven    _LIBCPP_INLINE_VISIBILITY
573234959Stheraven    void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
574234959Stheraven        {__c11_atomic_store(&__a_, __d, __m);}
575227825Stheraven    _LIBCPP_INLINE_VISIBILITY
576234959Stheraven    _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
577234959Stheraven        {return __c11_atomic_load(&__a_, __m);}
578227825Stheraven    _LIBCPP_INLINE_VISIBILITY
579234959Stheraven    _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
580234959Stheraven        {return __c11_atomic_load(&__a_, __m);}
581227825Stheraven    _LIBCPP_INLINE_VISIBILITY
582234959Stheraven    operator _Tp() const volatile _NOEXCEPT {return load();}
583227825Stheraven    _LIBCPP_INLINE_VISIBILITY
584234959Stheraven    operator _Tp() const _NOEXCEPT          {return load();}
585227825Stheraven    _LIBCPP_INLINE_VISIBILITY
586234959Stheraven    _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
587234959Stheraven        {return __c11_atomic_exchange(&__a_, __d, __m);}
588227825Stheraven    _LIBCPP_INLINE_VISIBILITY
589234959Stheraven    _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
590234959Stheraven        {return __c11_atomic_exchange(&__a_, __d, __m);}
591227825Stheraven    _LIBCPP_INLINE_VISIBILITY
592227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
593234959Stheraven                               memory_order __s, memory_order __f) volatile _NOEXCEPT
594234959Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
595227825Stheraven    _LIBCPP_INLINE_VISIBILITY
596227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
597234959Stheraven                               memory_order __s, memory_order __f) _NOEXCEPT
598234959Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
599227825Stheraven    _LIBCPP_INLINE_VISIBILITY
600227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
601234959Stheraven                                 memory_order __s, memory_order __f) volatile _NOEXCEPT
602234959Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
603227825Stheraven    _LIBCPP_INLINE_VISIBILITY
604227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
605234959Stheraven                                 memory_order __s, memory_order __f) _NOEXCEPT
606234959Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
607227825Stheraven    _LIBCPP_INLINE_VISIBILITY
608227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
609234959Stheraven                              memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
610234959Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
611227825Stheraven    _LIBCPP_INLINE_VISIBILITY
612227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
613234959Stheraven                               memory_order __m = memory_order_seq_cst) _NOEXCEPT
614234959Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
615227825Stheraven    _LIBCPP_INLINE_VISIBILITY
616227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
617234959Stheraven                              memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
618234959Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
619227825Stheraven    _LIBCPP_INLINE_VISIBILITY
620227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
621234959Stheraven                                 memory_order __m = memory_order_seq_cst) _NOEXCEPT
622234959Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
623227825Stheraven
624227825Stheraven    _LIBCPP_INLINE_VISIBILITY
625234959Stheraven    __atomic_base() _NOEXCEPT {} // = default;
626227825Stheraven    _LIBCPP_INLINE_VISIBILITY
627234959Stheraven    _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
628227825Stheraven#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
629227825Stheraven    __atomic_base(const __atomic_base&) = delete;
630227825Stheraven    __atomic_base& operator=(const __atomic_base&) = delete;
631227825Stheraven    __atomic_base& operator=(const __atomic_base&) volatile = delete;
632227825Stheraven#else  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
633227825Stheravenprivate:
634227825Stheraven    __atomic_base(const __atomic_base&);
635227825Stheraven    __atomic_base& operator=(const __atomic_base&);
636227825Stheraven    __atomic_base& operator=(const __atomic_base&) volatile;
637227825Stheraven#endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
638227825Stheraven};
639227825Stheraven
640227825Stheraven// atomic<Integral>
641227825Stheraven
642227825Stheraventemplate <class _Tp>
643227825Stheravenstruct __atomic_base<_Tp, true>
644227825Stheraven    : public __atomic_base<_Tp, false>
645227825Stheraven{
646227825Stheraven    typedef __atomic_base<_Tp, false> __base;
647227825Stheraven    _LIBCPP_INLINE_VISIBILITY
648234959Stheraven    __atomic_base() _NOEXCEPT {} // = default;
649227825Stheraven    _LIBCPP_INLINE_VISIBILITY
650234959Stheraven    _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
651227825Stheraven
652227825Stheraven    _LIBCPP_INLINE_VISIBILITY
653234959Stheraven    _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
654234959Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
655227825Stheraven    _LIBCPP_INLINE_VISIBILITY
656234959Stheraven    _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
657234959Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
658227825Stheraven    _LIBCPP_INLINE_VISIBILITY
659234959Stheraven    _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
660234959Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
661227825Stheraven    _LIBCPP_INLINE_VISIBILITY
662234959Stheraven    _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
663234959Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
664227825Stheraven    _LIBCPP_INLINE_VISIBILITY
665234959Stheraven    _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
666234959Stheraven        {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
667227825Stheraven    _LIBCPP_INLINE_VISIBILITY
668234959Stheraven    _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
669234959Stheraven        {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
670227825Stheraven    _LIBCPP_INLINE_VISIBILITY
671234959Stheraven    _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
672234959Stheraven        {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
673227825Stheraven    _LIBCPP_INLINE_VISIBILITY
674234959Stheraven    _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
675234959Stheraven        {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
676227825Stheraven    _LIBCPP_INLINE_VISIBILITY
677234959Stheraven    _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
678234959Stheraven        {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
679227825Stheraven    _LIBCPP_INLINE_VISIBILITY
680234959Stheraven    _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
681234959Stheraven        {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
682227825Stheraven
683227825Stheraven    _LIBCPP_INLINE_VISIBILITY
684234959Stheraven    _Tp operator++(int) volatile _NOEXCEPT      {return fetch_add(_Tp(1));}
685227825Stheraven    _LIBCPP_INLINE_VISIBILITY
686234959Stheraven    _Tp operator++(int) _NOEXCEPT               {return fetch_add(_Tp(1));}
687227825Stheraven    _LIBCPP_INLINE_VISIBILITY
688234959Stheraven    _Tp operator--(int) volatile _NOEXCEPT      {return fetch_sub(_Tp(1));}
689227825Stheraven    _LIBCPP_INLINE_VISIBILITY
690234959Stheraven    _Tp operator--(int) _NOEXCEPT               {return fetch_sub(_Tp(1));}
691227825Stheraven    _LIBCPP_INLINE_VISIBILITY
692234959Stheraven    _Tp operator++() volatile _NOEXCEPT         {return fetch_add(_Tp(1)) + _Tp(1);}
693227825Stheraven    _LIBCPP_INLINE_VISIBILITY
694234959Stheraven    _Tp operator++() _NOEXCEPT                  {return fetch_add(_Tp(1)) + _Tp(1);}
695227825Stheraven    _LIBCPP_INLINE_VISIBILITY
696234959Stheraven    _Tp operator--() volatile _NOEXCEPT         {return fetch_sub(_Tp(1)) - _Tp(1);}
697227825Stheraven    _LIBCPP_INLINE_VISIBILITY
698234959Stheraven    _Tp operator--() _NOEXCEPT                  {return fetch_sub(_Tp(1)) - _Tp(1);}
699227825Stheraven    _LIBCPP_INLINE_VISIBILITY
700234959Stheraven    _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
701227825Stheraven    _LIBCPP_INLINE_VISIBILITY
702234959Stheraven    _Tp operator+=(_Tp __op) _NOEXCEPT          {return fetch_add(__op) + __op;}
703227825Stheraven    _LIBCPP_INLINE_VISIBILITY
704234959Stheraven    _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
705227825Stheraven    _LIBCPP_INLINE_VISIBILITY
706234959Stheraven    _Tp operator-=(_Tp __op) _NOEXCEPT          {return fetch_sub(__op) - __op;}
707227825Stheraven    _LIBCPP_INLINE_VISIBILITY
708234959Stheraven    _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
709227825Stheraven    _LIBCPP_INLINE_VISIBILITY
710234959Stheraven    _Tp operator&=(_Tp __op) _NOEXCEPT          {return fetch_and(__op) & __op;}
711227825Stheraven    _LIBCPP_INLINE_VISIBILITY
712234959Stheraven    _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
713227825Stheraven    _LIBCPP_INLINE_VISIBILITY
714234959Stheraven    _Tp operator|=(_Tp __op) _NOEXCEPT          {return fetch_or(__op) | __op;}
715227825Stheraven    _LIBCPP_INLINE_VISIBILITY
716234959Stheraven    _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
717227825Stheraven    _LIBCPP_INLINE_VISIBILITY
718234959Stheraven    _Tp operator^=(_Tp __op) _NOEXCEPT          {return fetch_xor(__op) ^ __op;}
719227825Stheraven};
720227825Stheraven
721227825Stheraven// atomic<T>
722227825Stheraven
723227825Stheraventemplate <class _Tp>
724227825Stheravenstruct atomic
725227825Stheraven    : public __atomic_base<_Tp>
726227825Stheraven{
727227825Stheraven    typedef __atomic_base<_Tp> __base;
728227825Stheraven    _LIBCPP_INLINE_VISIBILITY
729234959Stheraven    atomic() _NOEXCEPT {} // = default;
730227825Stheraven    _LIBCPP_INLINE_VISIBILITY
731234959Stheraven    _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
732227825Stheraven
733227825Stheraven    _LIBCPP_INLINE_VISIBILITY
734234959Stheraven    _Tp operator=(_Tp __d) volatile _NOEXCEPT
735227825Stheraven        {__base::store(__d); return __d;}
736227825Stheraven    _LIBCPP_INLINE_VISIBILITY
737234959Stheraven    _Tp operator=(_Tp __d) _NOEXCEPT
738227825Stheraven        {__base::store(__d); return __d;}
739227825Stheraven};
740227825Stheraven
741227825Stheraven// atomic<T*>
742227825Stheraven
743227825Stheraventemplate <class _Tp>
744227825Stheravenstruct atomic<_Tp*>
745227825Stheraven    : public __atomic_base<_Tp*>
746227825Stheraven{
747227825Stheraven    typedef __atomic_base<_Tp*> __base;
748227825Stheraven    _LIBCPP_INLINE_VISIBILITY
749234959Stheraven    atomic() _NOEXCEPT {} // = default;
750227825Stheraven    _LIBCPP_INLINE_VISIBILITY
751234959Stheraven    _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
752227825Stheraven
753227825Stheraven    _LIBCPP_INLINE_VISIBILITY
754234959Stheraven    _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
755227825Stheraven        {__base::store(__d); return __d;}
756227825Stheraven    _LIBCPP_INLINE_VISIBILITY
757234959Stheraven    _Tp* operator=(_Tp* __d) _NOEXCEPT
758227825Stheraven        {__base::store(__d); return __d;}
759227825Stheraven
760227825Stheraven    _LIBCPP_INLINE_VISIBILITY
761227825Stheraven    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
762234959Stheraven                                                                        volatile _NOEXCEPT
763234959Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
764227825Stheraven    _LIBCPP_INLINE_VISIBILITY
765234959Stheraven    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
766234959Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
767227825Stheraven    _LIBCPP_INLINE_VISIBILITY
768227825Stheraven    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
769234959Stheraven                                                                        volatile _NOEXCEPT
770234959Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
771227825Stheraven    _LIBCPP_INLINE_VISIBILITY
772234959Stheraven    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
773234959Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
774227825Stheraven
775227825Stheraven    _LIBCPP_INLINE_VISIBILITY
776234959Stheraven    _Tp* operator++(int) volatile _NOEXCEPT            {return fetch_add(1);}
777227825Stheraven    _LIBCPP_INLINE_VISIBILITY
778234959Stheraven    _Tp* operator++(int) _NOEXCEPT                     {return fetch_add(1);}
779227825Stheraven    _LIBCPP_INLINE_VISIBILITY
780234959Stheraven    _Tp* operator--(int) volatile _NOEXCEPT            {return fetch_sub(1);}
781227825Stheraven    _LIBCPP_INLINE_VISIBILITY
782234959Stheraven    _Tp* operator--(int) _NOEXCEPT                     {return fetch_sub(1);}
783227825Stheraven    _LIBCPP_INLINE_VISIBILITY
784234959Stheraven    _Tp* operator++() volatile _NOEXCEPT               {return fetch_add(1) + 1;}
785227825Stheraven    _LIBCPP_INLINE_VISIBILITY
786234959Stheraven    _Tp* operator++() _NOEXCEPT                        {return fetch_add(1) + 1;}
787227825Stheraven    _LIBCPP_INLINE_VISIBILITY
788234959Stheraven    _Tp* operator--() volatile _NOEXCEPT               {return fetch_sub(1) - 1;}
789227825Stheraven    _LIBCPP_INLINE_VISIBILITY
790234959Stheraven    _Tp* operator--() _NOEXCEPT                        {return fetch_sub(1) - 1;}
791227825Stheraven    _LIBCPP_INLINE_VISIBILITY
792234959Stheraven    _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
793227825Stheraven    _LIBCPP_INLINE_VISIBILITY
794234959Stheraven    _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT          {return fetch_add(__op) + __op;}
795227825Stheraven    _LIBCPP_INLINE_VISIBILITY
796234959Stheraven    _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
797227825Stheraven    _LIBCPP_INLINE_VISIBILITY
798234959Stheraven    _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT          {return fetch_sub(__op) - __op;}
799227825Stheraven};
800227825Stheraven
801227825Stheraven// atomic_is_lock_free
802227825Stheraven
803227825Stheraventemplate <class _Tp>
804227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
805227825Stheravenbool
806234959Stheravenatomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
807227825Stheraven{
808227825Stheraven    return __o->is_lock_free();
809227825Stheraven}
810227825Stheraven
811227825Stheraventemplate <class _Tp>
812227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
813227825Stheravenbool
814234959Stheravenatomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
815227825Stheraven{
816227825Stheraven    return __o->is_lock_free();
817227825Stheraven}
818227825Stheraven
819227825Stheraven// atomic_init
820227825Stheraven
821227825Stheraventemplate <class _Tp>
822227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
823227825Stheravenvoid
824234959Stheravenatomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
825227825Stheraven{
826234959Stheraven    __c11_atomic_init(&__o->__a_, __d);
827227825Stheraven}
828227825Stheraven
829227825Stheraventemplate <class _Tp>
830227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
831227825Stheravenvoid
832234959Stheravenatomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
833227825Stheraven{
834234959Stheraven    __c11_atomic_init(&__o->__a_, __d);
835227825Stheraven}
836227825Stheraven
837227825Stheraven// atomic_store
838227825Stheraven
839227825Stheraventemplate <class _Tp>
840227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
841227825Stheravenvoid
842234959Stheravenatomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
843227825Stheraven{
844227825Stheraven    __o->store(__d);
845227825Stheraven}
846227825Stheraven
847227825Stheraventemplate <class _Tp>
848227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
849227825Stheravenvoid
850234959Stheravenatomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
851227825Stheraven{
852227825Stheraven    __o->store(__d);
853227825Stheraven}
854227825Stheraven
855227825Stheraven// atomic_store_explicit
856227825Stheraven
857227825Stheraventemplate <class _Tp>
858227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
859227825Stheravenvoid
860234959Stheravenatomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
861227825Stheraven{
862227825Stheraven    __o->store(__d, __m);
863227825Stheraven}
864227825Stheraven
865227825Stheraventemplate <class _Tp>
866227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
867227825Stheravenvoid
868234959Stheravenatomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
869227825Stheraven{
870227825Stheraven    __o->store(__d, __m);
871227825Stheraven}
872227825Stheraven
873227825Stheraven// atomic_load
874227825Stheraven
875227825Stheraventemplate <class _Tp>
876227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
877227825Stheraven_Tp
878234959Stheravenatomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
879227825Stheraven{
880227825Stheraven    return __o->load();
881227825Stheraven}
882227825Stheraven
883227825Stheraventemplate <class _Tp>
884227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
885227825Stheraven_Tp
886234959Stheravenatomic_load(const atomic<_Tp>* __o) _NOEXCEPT
887227825Stheraven{
888227825Stheraven    return __o->load();
889227825Stheraven}
890227825Stheraven
891227825Stheraven// atomic_load_explicit
892227825Stheraven
893227825Stheraventemplate <class _Tp>
894227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
895227825Stheraven_Tp
896234959Stheravenatomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
897227825Stheraven{
898227825Stheraven    return __o->load(__m);
899227825Stheraven}
900227825Stheraven
901227825Stheraventemplate <class _Tp>
902227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
903227825Stheraven_Tp
904234959Stheravenatomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
905227825Stheraven{
906227825Stheraven    return __o->load(__m);
907227825Stheraven}
908227825Stheraven
909227825Stheraven// atomic_exchange
910227825Stheraven
911227825Stheraventemplate <class _Tp>
912227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
913227825Stheraven_Tp
914234959Stheravenatomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
915227825Stheraven{
916227825Stheraven    return __o->exchange(__d);
917227825Stheraven}
918227825Stheraven
919227825Stheraventemplate <class _Tp>
920227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
921227825Stheraven_Tp
922234959Stheravenatomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
923227825Stheraven{
924227825Stheraven    return __o->exchange(__d);
925227825Stheraven}
926227825Stheraven
927227825Stheraven// atomic_exchange_explicit
928227825Stheraven
929227825Stheraventemplate <class _Tp>
930227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
931227825Stheraven_Tp
932234959Stheravenatomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
933227825Stheraven{
934227825Stheraven    return __o->exchange(__d, __m);
935227825Stheraven}
936227825Stheraven
937227825Stheraventemplate <class _Tp>
938227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
939227825Stheraven_Tp
940234959Stheravenatomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
941227825Stheraven{
942227825Stheraven    return __o->exchange(__d, __m);
943227825Stheraven}
944227825Stheraven
945227825Stheraven// atomic_compare_exchange_weak
946227825Stheraven
947227825Stheraventemplate <class _Tp>
948227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
949227825Stheravenbool
950234959Stheravenatomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
951227825Stheraven{
952227825Stheraven    return __o->compare_exchange_weak(*__e, __d);
953227825Stheraven}
954227825Stheraven
955227825Stheraventemplate <class _Tp>
956227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
957227825Stheravenbool
958234959Stheravenatomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
959227825Stheraven{
960227825Stheraven    return __o->compare_exchange_weak(*__e, __d);
961227825Stheraven}
962227825Stheraven
963227825Stheraven// atomic_compare_exchange_strong
964227825Stheraven
965227825Stheraventemplate <class _Tp>
966227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
967227825Stheravenbool
968234959Stheravenatomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
969227825Stheraven{
970227825Stheraven    return __o->compare_exchange_strong(*__e, __d);
971227825Stheraven}
972227825Stheraven
973227825Stheraventemplate <class _Tp>
974227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
975227825Stheravenbool
976234959Stheravenatomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
977227825Stheraven{
978227825Stheraven    return __o->compare_exchange_strong(*__e, __d);
979227825Stheraven}
980227825Stheraven
981227825Stheraven// atomic_compare_exchange_weak_explicit
982227825Stheraven
983227825Stheraventemplate <class _Tp>
984227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
985227825Stheravenbool
986227825Stheravenatomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
987227825Stheraven                                      _Tp __d,
988234959Stheraven                                      memory_order __s, memory_order __f) _NOEXCEPT
989227825Stheraven{
990227825Stheraven    return __o->compare_exchange_weak(*__e, __d, __s, __f);
991227825Stheraven}
992227825Stheraven
993227825Stheraventemplate <class _Tp>
994227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
995227825Stheravenbool
996227825Stheravenatomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
997234959Stheraven                                      memory_order __s, memory_order __f) _NOEXCEPT
998227825Stheraven{
999227825Stheraven    return __o->compare_exchange_weak(*__e, __d, __s, __f);
1000227825Stheraven}
1001227825Stheraven
1002227825Stheraven// atomic_compare_exchange_strong_explicit
1003227825Stheraven
1004227825Stheraventemplate <class _Tp>
1005227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1006227825Stheravenbool
1007227825Stheravenatomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
1008227825Stheraven                                        _Tp* __e, _Tp __d,
1009234959Stheraven                                        memory_order __s, memory_order __f) _NOEXCEPT
1010227825Stheraven{
1011227825Stheraven    return __o->compare_exchange_strong(*__e, __d, __s, __f);
1012227825Stheraven}
1013227825Stheraven
1014227825Stheraventemplate <class _Tp>
1015227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1016227825Stheravenbool
1017227825Stheravenatomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
1018227825Stheraven                                        _Tp __d,
1019234959Stheraven                                        memory_order __s, memory_order __f) _NOEXCEPT
1020227825Stheraven{
1021227825Stheraven    return __o->compare_exchange_strong(*__e, __d, __s, __f);
1022227825Stheraven}
1023227825Stheraven
1024227825Stheraven// atomic_fetch_add
1025227825Stheraven
1026227825Stheraventemplate <class _Tp>
1027227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1028227825Stheraventypename enable_if
1029227825Stheraven<
1030227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1031227825Stheraven    _Tp
1032227825Stheraven>::type
1033234959Stheravenatomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1034227825Stheraven{
1035227825Stheraven    return __o->fetch_add(__op);
1036227825Stheraven}
1037227825Stheraven
1038227825Stheraventemplate <class _Tp>
1039227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1040227825Stheraventypename enable_if
1041227825Stheraven<
1042227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1043227825Stheraven    _Tp
1044227825Stheraven>::type
1045234959Stheravenatomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1046227825Stheraven{
1047227825Stheraven    return __o->fetch_add(__op);
1048227825Stheraven}
1049227825Stheraven
1050227825Stheraventemplate <class _Tp>
1051227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1052227825Stheraven_Tp*
1053234959Stheravenatomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1054227825Stheraven{
1055227825Stheraven    return __o->fetch_add(__op);
1056227825Stheraven}
1057227825Stheraven
1058227825Stheraventemplate <class _Tp>
1059227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1060227825Stheraven_Tp*
1061234959Stheravenatomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1062227825Stheraven{
1063227825Stheraven    return __o->fetch_add(__op);
1064227825Stheraven}
1065227825Stheraven
1066227825Stheraven// atomic_fetch_add_explicit
1067227825Stheraven
1068227825Stheraventemplate <class _Tp>
1069227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1070227825Stheraventypename enable_if
1071227825Stheraven<
1072227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1073227825Stheraven    _Tp
1074227825Stheraven>::type
1075234959Stheravenatomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1076227825Stheraven{
1077227825Stheraven    return __o->fetch_add(__op, __m);
1078227825Stheraven}
1079227825Stheraven
1080227825Stheraventemplate <class _Tp>
1081227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1082227825Stheraventypename enable_if
1083227825Stheraven<
1084227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1085227825Stheraven    _Tp
1086227825Stheraven>::type
1087234959Stheravenatomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1088227825Stheraven{
1089227825Stheraven    return __o->fetch_add(__op, __m);
1090227825Stheraven}
1091227825Stheraven
1092227825Stheraventemplate <class _Tp>
1093227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1094227825Stheraven_Tp*
1095227825Stheravenatomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
1096234959Stheraven                          memory_order __m) _NOEXCEPT
1097227825Stheraven{
1098227825Stheraven    return __o->fetch_add(__op, __m);
1099227825Stheraven}
1100227825Stheraven
1101227825Stheraventemplate <class _Tp>
1102227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1103227825Stheraven_Tp*
1104234959Stheravenatomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
1105227825Stheraven{
1106227825Stheraven    return __o->fetch_add(__op, __m);
1107227825Stheraven}
1108227825Stheraven
1109227825Stheraven// atomic_fetch_sub
1110227825Stheraven
1111227825Stheraventemplate <class _Tp>
1112227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1113227825Stheraventypename enable_if
1114227825Stheraven<
1115227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1116227825Stheraven    _Tp
1117227825Stheraven>::type
1118234959Stheravenatomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1119227825Stheraven{
1120227825Stheraven    return __o->fetch_sub(__op);
1121227825Stheraven}
1122227825Stheraven
1123227825Stheraventemplate <class _Tp>
1124227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1125227825Stheraventypename enable_if
1126227825Stheraven<
1127227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1128227825Stheraven    _Tp
1129227825Stheraven>::type
1130234959Stheravenatomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1131227825Stheraven{
1132227825Stheraven    return __o->fetch_sub(__op);
1133227825Stheraven}
1134227825Stheraven
1135227825Stheraventemplate <class _Tp>
1136227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1137227825Stheraven_Tp*
1138234959Stheravenatomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1139227825Stheraven{
1140227825Stheraven    return __o->fetch_sub(__op);
1141227825Stheraven}
1142227825Stheraven
1143227825Stheraventemplate <class _Tp>
1144227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1145227825Stheraven_Tp*
1146234959Stheravenatomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1147227825Stheraven{
1148227825Stheraven    return __o->fetch_sub(__op);
1149227825Stheraven}
1150227825Stheraven
1151227825Stheraven// atomic_fetch_sub_explicit
1152227825Stheraven
1153227825Stheraventemplate <class _Tp>
1154227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1155227825Stheraventypename enable_if
1156227825Stheraven<
1157227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1158227825Stheraven    _Tp
1159227825Stheraven>::type
1160234959Stheravenatomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1161227825Stheraven{
1162227825Stheraven    return __o->fetch_sub(__op, __m);
1163227825Stheraven}
1164227825Stheraven
1165227825Stheraventemplate <class _Tp>
1166227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1167227825Stheraventypename enable_if
1168227825Stheraven<
1169227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1170227825Stheraven    _Tp
1171227825Stheraven>::type
1172234959Stheravenatomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1173227825Stheraven{
1174227825Stheraven    return __o->fetch_sub(__op, __m);
1175227825Stheraven}
1176227825Stheraven
1177227825Stheraventemplate <class _Tp>
1178227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1179227825Stheraven_Tp*
1180227825Stheravenatomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
1181234959Stheraven                          memory_order __m) _NOEXCEPT
1182227825Stheraven{
1183227825Stheraven    return __o->fetch_sub(__op, __m);
1184227825Stheraven}
1185227825Stheraven
1186227825Stheraventemplate <class _Tp>
1187227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1188227825Stheraven_Tp*
1189234959Stheravenatomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
1190227825Stheraven{
1191227825Stheraven    return __o->fetch_sub(__op, __m);
1192227825Stheraven}
1193227825Stheraven
1194227825Stheraven// atomic_fetch_and
1195227825Stheraven
1196227825Stheraventemplate <class _Tp>
1197227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1198227825Stheraventypename enable_if
1199227825Stheraven<
1200227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1201227825Stheraven    _Tp
1202227825Stheraven>::type
1203234959Stheravenatomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1204227825Stheraven{
1205227825Stheraven    return __o->fetch_and(__op);
1206227825Stheraven}
1207227825Stheraven
1208227825Stheraventemplate <class _Tp>
1209227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1210227825Stheraventypename enable_if
1211227825Stheraven<
1212227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1213227825Stheraven    _Tp
1214227825Stheraven>::type
1215234959Stheravenatomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1216227825Stheraven{
1217227825Stheraven    return __o->fetch_and(__op);
1218227825Stheraven}
1219227825Stheraven
1220227825Stheraven// atomic_fetch_and_explicit
1221227825Stheraven
1222227825Stheraventemplate <class _Tp>
1223227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1224227825Stheraventypename enable_if
1225227825Stheraven<
1226227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1227227825Stheraven    _Tp
1228227825Stheraven>::type
1229234959Stheravenatomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1230227825Stheraven{
1231227825Stheraven    return __o->fetch_and(__op, __m);
1232227825Stheraven}
1233227825Stheraven
1234227825Stheraventemplate <class _Tp>
1235227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1236227825Stheraventypename enable_if
1237227825Stheraven<
1238227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1239227825Stheraven    _Tp
1240227825Stheraven>::type
1241234959Stheravenatomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1242227825Stheraven{
1243227825Stheraven    return __o->fetch_and(__op, __m);
1244227825Stheraven}
1245227825Stheraven
1246227825Stheraven// atomic_fetch_or
1247227825Stheraven
1248227825Stheraventemplate <class _Tp>
1249227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1250227825Stheraventypename enable_if
1251227825Stheraven<
1252227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1253227825Stheraven    _Tp
1254227825Stheraven>::type
1255234959Stheravenatomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1256227825Stheraven{
1257227825Stheraven    return __o->fetch_or(__op);
1258227825Stheraven}
1259227825Stheraven
1260227825Stheraventemplate <class _Tp>
1261227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1262227825Stheraventypename enable_if
1263227825Stheraven<
1264227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1265227825Stheraven    _Tp
1266227825Stheraven>::type
1267234959Stheravenatomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1268227825Stheraven{
1269227825Stheraven    return __o->fetch_or(__op);
1270227825Stheraven}
1271227825Stheraven
1272227825Stheraven// atomic_fetch_or_explicit
1273227825Stheraven
1274227825Stheraventemplate <class _Tp>
1275227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1276227825Stheraventypename enable_if
1277227825Stheraven<
1278227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1279227825Stheraven    _Tp
1280227825Stheraven>::type
1281234959Stheravenatomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1282227825Stheraven{
1283227825Stheraven    return __o->fetch_or(__op, __m);
1284227825Stheraven}
1285227825Stheraven
1286227825Stheraventemplate <class _Tp>
1287227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1288227825Stheraventypename enable_if
1289227825Stheraven<
1290227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1291227825Stheraven    _Tp
1292227825Stheraven>::type
1293234959Stheravenatomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1294227825Stheraven{
1295227825Stheraven    return __o->fetch_or(__op, __m);
1296227825Stheraven}
1297227825Stheraven
1298227825Stheraven// atomic_fetch_xor
1299227825Stheraven
1300227825Stheraventemplate <class _Tp>
1301227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1302227825Stheraventypename enable_if
1303227825Stheraven<
1304227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1305227825Stheraven    _Tp
1306227825Stheraven>::type
1307234959Stheravenatomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1308227825Stheraven{
1309227825Stheraven    return __o->fetch_xor(__op);
1310227825Stheraven}
1311227825Stheraven
1312227825Stheraventemplate <class _Tp>
1313227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1314227825Stheraventypename enable_if
1315227825Stheraven<
1316227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1317227825Stheraven    _Tp
1318227825Stheraven>::type
1319234959Stheravenatomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1320227825Stheraven{
1321227825Stheraven    return __o->fetch_xor(__op);
1322227825Stheraven}
1323227825Stheraven
1324227825Stheraven// atomic_fetch_xor_explicit
1325227825Stheraven
1326227825Stheraventemplate <class _Tp>
1327227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1328227825Stheraventypename enable_if
1329227825Stheraven<
1330227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1331227825Stheraven    _Tp
1332227825Stheraven>::type
1333234959Stheravenatomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1334227825Stheraven{
1335227825Stheraven    return __o->fetch_xor(__op, __m);
1336227825Stheraven}
1337227825Stheraven
1338227825Stheraventemplate <class _Tp>
1339227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1340227825Stheraventypename enable_if
1341227825Stheraven<
1342227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1343227825Stheraven    _Tp
1344227825Stheraven>::type
1345234959Stheravenatomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1346227825Stheraven{
1347227825Stheraven    return __o->fetch_xor(__op, __m);
1348227825Stheraven}
1349227825Stheraven
1350227825Stheraven// flag type and operations
1351227825Stheraven
1352227825Stheraventypedef struct atomic_flag
1353227825Stheraven{
1354232924Stheraven    _Atomic(bool) __a_;
1355227825Stheraven
1356227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1357234959Stheraven    bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
1358234959Stheraven        {return __c11_atomic_exchange(&__a_, true, __m);}
1359227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1360234959Stheraven    bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
1361234959Stheraven        {return __c11_atomic_exchange(&__a_, true, __m);}
1362227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1363234959Stheraven    void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
1364234959Stheraven        {__c11_atomic_store(&__a_, false, __m);}
1365227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1366234959Stheraven    void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
1367234959Stheraven        {__c11_atomic_store(&__a_, false, __m);}
1368227825Stheraven
1369227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1370234959Stheraven    atomic_flag() _NOEXCEPT {} // = default;
1371227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1372234959Stheraven    atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {}
1373227825Stheraven
1374227825Stheraven#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1375227825Stheraven    atomic_flag(const atomic_flag&) = delete;
1376227825Stheraven    atomic_flag& operator=(const atomic_flag&) = delete;
1377227825Stheraven    atomic_flag& operator=(const atomic_flag&) volatile = delete;
1378227825Stheraven#else  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1379227825Stheravenprivate:
1380227825Stheraven    atomic_flag(const atomic_flag&);
1381227825Stheraven    atomic_flag& operator=(const atomic_flag&);
1382227825Stheraven    atomic_flag& operator=(const atomic_flag&) volatile;
1383227825Stheraven#endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1384227825Stheraven} atomic_flag;
1385227825Stheraven
1386227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1387227825Stheravenbool
1388234959Stheravenatomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
1389227825Stheraven{
1390227825Stheraven    return __o->test_and_set();
1391227825Stheraven}
1392227825Stheraven
1393227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1394227825Stheravenbool
1395234959Stheravenatomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
1396227825Stheraven{
1397227825Stheraven    return __o->test_and_set();
1398227825Stheraven}
1399227825Stheraven
1400227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1401227825Stheravenbool
1402234959Stheravenatomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
1403227825Stheraven{
1404227825Stheraven    return __o->test_and_set(__m);
1405227825Stheraven}
1406227825Stheraven
1407227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1408227825Stheravenbool
1409234959Stheravenatomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
1410227825Stheraven{
1411227825Stheraven    return __o->test_and_set(__m);
1412227825Stheraven}
1413227825Stheraven
1414227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1415227825Stheravenvoid
1416234959Stheravenatomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
1417227825Stheraven{
1418227825Stheraven    __o->clear();
1419227825Stheraven}
1420227825Stheraven
1421227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1422227825Stheravenvoid
1423234959Stheravenatomic_flag_clear(atomic_flag* __o) _NOEXCEPT
1424227825Stheraven{
1425227825Stheraven    __o->clear();
1426227825Stheraven}
1427227825Stheraven
1428227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1429227825Stheravenvoid
1430234959Stheravenatomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
1431227825Stheraven{
1432227825Stheraven    __o->clear(__m);
1433227825Stheraven}
1434227825Stheraven
1435227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1436227825Stheravenvoid
1437234959Stheravenatomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
1438227825Stheraven{
1439227825Stheraven    __o->clear(__m);
1440227825Stheraven}
1441227825Stheraven
1442227825Stheraven// fences
1443227825Stheraven
1444227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1445227825Stheravenvoid
1446234959Stheravenatomic_thread_fence(memory_order __m) _NOEXCEPT
1447227825Stheraven{
1448234959Stheraven    __c11_atomic_thread_fence(__m);
1449227825Stheraven}
1450227825Stheraven
1451227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1452227825Stheravenvoid
1453234959Stheravenatomic_signal_fence(memory_order __m) _NOEXCEPT
1454227825Stheraven{
1455234959Stheraven    __c11_atomic_signal_fence(__m);
1456227825Stheraven}
1457227825Stheraven
1458227825Stheraven// Atomics for standard typedef types
1459227825Stheraven
1460246468Stheraventypedef atomic<bool>               atomic_bool;
1461227825Stheraventypedef atomic<char>               atomic_char;
1462227825Stheraventypedef atomic<signed char>        atomic_schar;
1463227825Stheraventypedef atomic<unsigned char>      atomic_uchar;
1464227825Stheraventypedef atomic<short>              atomic_short;
1465227825Stheraventypedef atomic<unsigned short>     atomic_ushort;
1466227825Stheraventypedef atomic<int>                atomic_int;
1467227825Stheraventypedef atomic<unsigned int>       atomic_uint;
1468227825Stheraventypedef atomic<long>               atomic_long;
1469227825Stheraventypedef atomic<unsigned long>      atomic_ulong;
1470227825Stheraventypedef atomic<long long>          atomic_llong;
1471227825Stheraventypedef atomic<unsigned long long> atomic_ullong;
1472227825Stheraventypedef atomic<char16_t>           atomic_char16_t;
1473227825Stheraventypedef atomic<char32_t>           atomic_char32_t;
1474227825Stheraventypedef atomic<wchar_t>            atomic_wchar_t;
1475227825Stheraven
1476227825Stheraventypedef atomic<int_least8_t>   atomic_int_least8_t;
1477227825Stheraventypedef atomic<uint_least8_t>  atomic_uint_least8_t;
1478227825Stheraventypedef atomic<int_least16_t>  atomic_int_least16_t;
1479227825Stheraventypedef atomic<uint_least16_t> atomic_uint_least16_t;
1480227825Stheraventypedef atomic<int_least32_t>  atomic_int_least32_t;
1481227825Stheraventypedef atomic<uint_least32_t> atomic_uint_least32_t;
1482227825Stheraventypedef atomic<int_least64_t>  atomic_int_least64_t;
1483227825Stheraventypedef atomic<uint_least64_t> atomic_uint_least64_t;
1484227825Stheraven
1485227825Stheraventypedef atomic<int_fast8_t>   atomic_int_fast8_t;
1486227825Stheraventypedef atomic<uint_fast8_t>  atomic_uint_fast8_t;
1487227825Stheraventypedef atomic<int_fast16_t>  atomic_int_fast16_t;
1488227825Stheraventypedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1489227825Stheraventypedef atomic<int_fast32_t>  atomic_int_fast32_t;
1490227825Stheraventypedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1491227825Stheraventypedef atomic<int_fast64_t>  atomic_int_fast64_t;
1492227825Stheraventypedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1493227825Stheraven
1494227825Stheraventypedef atomic<intptr_t>  atomic_intptr_t;
1495227825Stheraventypedef atomic<uintptr_t> atomic_uintptr_t;
1496227825Stheraventypedef atomic<size_t>    atomic_size_t;
1497227825Stheraventypedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1498227825Stheraventypedef atomic<intmax_t>  atomic_intmax_t;
1499227825Stheraventypedef atomic<uintmax_t> atomic_uintmax_t;
1500227825Stheraven
1501227825Stheraven#define ATOMIC_FLAG_INIT {false}
1502227825Stheraven#define ATOMIC_VAR_INIT(__v) {__v}
1503227825Stheraven
1504227825Stheraven// lock-free property
1505227825Stheraven
1506246468Stheraven#define ATOMIC_BOOL_LOCK_FREE      __GCC_ATOMIC_BOOL_LOCK_FREE
1507246468Stheraven#define ATOMIC_CHAR_LOCK_FREE      __GCC_ATOMIC_CHAR_LOCK_FREE
1508246468Stheraven#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
1509246468Stheraven#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
1510246468Stheraven#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
1511246468Stheraven#define ATOMIC_SHORT_LOCK_FREE     __GCC_ATOMIC_SHORT_LOCK_FREE
1512246468Stheraven#define ATOMIC_INT_LOCK_FREE       __GCC_ATOMIC_INT_LOCK_FREE
1513246468Stheraven#define ATOMIC_LONG_LOCK_FREE      __GCC_ATOMIC_LONG_LOCK_FREE
1514246468Stheraven#define ATOMIC_LLONG_LOCK_FREE     __GCC_ATOMIC_LLONG_LOCK_FREE
1515246468Stheraven#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
1516227825Stheraven
1517227825Stheraven#endif  //  !__has_feature(cxx_atomic)
1518227825Stheraven
1519227825Stheraven_LIBCPP_END_NAMESPACE_STD
1520227825Stheraven
1521227825Stheraven#endif  // _LIBCPP_ATOMIC
1522