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
536276792Sdim#ifdef _LIBCPP_HAS_NO_THREADS
537276792Sdim#error <atomic> is not supported on this single threaded system
538300770Sdim#endif
539300770Sdim#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
540300770Sdim#error <atomic> is not implemented
541300770Sdim#endif
542276792Sdim
543227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
544227825Stheraven
545227825Stheraventypedef enum memory_order
546227825Stheraven{
547227825Stheraven    memory_order_relaxed, memory_order_consume, memory_order_acquire,
548227825Stheraven    memory_order_release, memory_order_acq_rel, memory_order_seq_cst
549227825Stheraven} memory_order;
550227825Stheraven
551300770Sdim#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
552276792Sdimnamespace __gcc_atomic {
553288943Sdimtemplate <typename _Tp>
554276792Sdimstruct __gcc_atomic_t {
555296687Sdim
556296687Sdim#if _GNUC_VER >= 501
557296687Sdim    static_assert(is_trivially_copyable<_Tp>::value,
558296687Sdim      "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
559296687Sdim#endif
560296687Sdim
561296687Sdim  _LIBCPP_INLINE_VISIBILITY
562296687Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
563296687Sdim    __gcc_atomic_t() _NOEXCEPT = default;
564296687Sdim#else
565296687Sdim    __gcc_atomic_t() _NOEXCEPT : __a_value() {}
566296687Sdim#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
567288943Sdim  _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT
568288943Sdim    : __a_value(value) {}
569288943Sdim  _Tp __a_value;
570276792Sdim};
571276792Sdim#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x>
572276792Sdim
573288943Sdimtemplate <typename _Tp> _Tp __create();
574276792Sdim
575288943Sdimtemplate <typename _Tp, typename _Td>
576288943Sdimtypename enable_if<sizeof(_Tp()->__a_value = __create<_Td>()), char>::type
577276792Sdim    __test_atomic_assignable(int);
578288943Sdimtemplate <typename _Tp, typename _Up>
579276792Sdim__two __test_atomic_assignable(...);
580276792Sdim
581288943Sdimtemplate <typename _Tp, typename _Td>
582276792Sdimstruct __can_assign {
583276792Sdim  static const bool value =
584288943Sdim      sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char);
585276792Sdim};
586276792Sdim
587296687Sdimstatic inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
588276792Sdim  // Avoid switch statement to make this a constexpr.
589276792Sdim  return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
590276792Sdim         (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
591276792Sdim          (__order == memory_order_release ? __ATOMIC_RELEASE:
592276792Sdim           (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
593276792Sdim            (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
594276792Sdim              __ATOMIC_CONSUME))));
595276792Sdim}
596276792Sdim
597296687Sdimstatic inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
598288943Sdim  // Avoid switch statement to make this a constexpr.
599288943Sdim  return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
600288943Sdim         (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
601288943Sdim          (__order == memory_order_release ? __ATOMIC_RELAXED:
602288943Sdim           (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
603288943Sdim            (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE:
604288943Sdim              __ATOMIC_CONSUME))));
605288943Sdim}
606288943Sdim
607276792Sdim} // namespace __gcc_atomic
608276792Sdim
609276792Sdimtemplate <typename _Tp>
610276792Sdimstatic inline
611276792Sdimtypename enable_if<
612276792Sdim    __gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value>::type
613276792Sdim__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val) {
614276792Sdim  __a->__a_value = __val;
615276792Sdim}
616276792Sdim
617276792Sdimtemplate <typename _Tp>
618276792Sdimstatic inline
619276792Sdimtypename enable_if<
620276792Sdim    !__gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value &&
621276792Sdim     __gcc_atomic::__can_assign<         _Atomic(_Tp)*, _Tp>::value>::type
622276792Sdim__c11_atomic_init(volatile _Atomic(_Tp)* __a,  _Tp __val) {
623276792Sdim  // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
624276792Sdim  // the default operator= in an object is not volatile, a byte-by-byte copy
625276792Sdim  // is required.
626276792Sdim  volatile char* to = reinterpret_cast<volatile char*>(&__a->__a_value);
627276792Sdim  volatile char* end = to + sizeof(_Tp);
628276792Sdim  char* from = reinterpret_cast<char*>(&__val);
629276792Sdim  while (to != end) {
630276792Sdim    *to++ = *from++;
631276792Sdim  }
632276792Sdim}
633276792Sdim
634276792Sdimtemplate <typename _Tp>
635276792Sdimstatic inline void __c11_atomic_init(_Atomic(_Tp)* __a,  _Tp __val) {
636276792Sdim  __a->__a_value = __val;
637276792Sdim}
638276792Sdim
639276792Sdimstatic inline void __c11_atomic_thread_fence(memory_order __order) {
640276792Sdim  __atomic_thread_fence(__gcc_atomic::__to_gcc_order(__order));
641276792Sdim}
642276792Sdim
643276792Sdimstatic inline void __c11_atomic_signal_fence(memory_order __order) {
644276792Sdim  __atomic_signal_fence(__gcc_atomic::__to_gcc_order(__order));
645276792Sdim}
646276792Sdim
647276792Sdimtemplate <typename _Tp>
648276792Sdimstatic inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a,  _Tp __val,
649276792Sdim                                      memory_order __order) {
650276792Sdim  return __atomic_store(&__a->__a_value, &__val,
651276792Sdim                        __gcc_atomic::__to_gcc_order(__order));
652276792Sdim}
653276792Sdim
654276792Sdimtemplate <typename _Tp>
655276792Sdimstatic inline void __c11_atomic_store(_Atomic(_Tp)* __a,  _Tp __val,
656276792Sdim                                      memory_order __order) {
657288943Sdim  __atomic_store(&__a->__a_value, &__val,
658288943Sdim                 __gcc_atomic::__to_gcc_order(__order));
659276792Sdim}
660276792Sdim
661276792Sdimtemplate <typename _Tp>
662276792Sdimstatic inline _Tp __c11_atomic_load(volatile _Atomic(_Tp)* __a,
663276792Sdim                                    memory_order __order) {
664276792Sdim  _Tp __ret;
665276792Sdim  __atomic_load(&__a->__a_value, &__ret,
666276792Sdim                __gcc_atomic::__to_gcc_order(__order));
667276792Sdim  return __ret;
668276792Sdim}
669276792Sdim
670276792Sdimtemplate <typename _Tp>
671276792Sdimstatic inline _Tp __c11_atomic_load(_Atomic(_Tp)* __a, memory_order __order) {
672276792Sdim  _Tp __ret;
673276792Sdim  __atomic_load(&__a->__a_value, &__ret,
674276792Sdim                __gcc_atomic::__to_gcc_order(__order));
675276792Sdim  return __ret;
676276792Sdim}
677276792Sdim
678276792Sdimtemplate <typename _Tp>
679276792Sdimstatic inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a,
680276792Sdim                                        _Tp __value, memory_order __order) {
681276792Sdim  _Tp __ret;
682276792Sdim  __atomic_exchange(&__a->__a_value, &__value, &__ret,
683276792Sdim                    __gcc_atomic::__to_gcc_order(__order));
684276792Sdim  return __ret;
685276792Sdim}
686276792Sdim
687276792Sdimtemplate <typename _Tp>
688276792Sdimstatic inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value,
689276792Sdim                                        memory_order __order) {
690276792Sdim  _Tp __ret;
691276792Sdim  __atomic_exchange(&__a->__a_value, &__value, &__ret,
692276792Sdim                    __gcc_atomic::__to_gcc_order(__order));
693276792Sdim  return __ret;
694276792Sdim}
695276792Sdim
696276792Sdimtemplate <typename _Tp>
697276792Sdimstatic inline bool __c11_atomic_compare_exchange_strong(
698276792Sdim    volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
699276792Sdim    memory_order __success, memory_order __failure) {
700276792Sdim  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
701276792Sdim                                   false,
702276792Sdim                                   __gcc_atomic::__to_gcc_order(__success),
703288943Sdim                                   __gcc_atomic::__to_gcc_failure_order(__failure));
704276792Sdim}
705276792Sdim
706276792Sdimtemplate <typename _Tp>
707276792Sdimstatic inline bool __c11_atomic_compare_exchange_strong(
708276792Sdim    _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
709276792Sdim    memory_order __failure) {
710276792Sdim  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
711276792Sdim                                   false,
712276792Sdim                                   __gcc_atomic::__to_gcc_order(__success),
713288943Sdim                                   __gcc_atomic::__to_gcc_failure_order(__failure));
714276792Sdim}
715276792Sdim
716276792Sdimtemplate <typename _Tp>
717276792Sdimstatic inline bool __c11_atomic_compare_exchange_weak(
718276792Sdim    volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value,
719276792Sdim    memory_order __success, memory_order __failure) {
720276792Sdim  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
721276792Sdim                                   true,
722276792Sdim                                   __gcc_atomic::__to_gcc_order(__success),
723288943Sdim                                   __gcc_atomic::__to_gcc_failure_order(__failure));
724276792Sdim}
725276792Sdim
726276792Sdimtemplate <typename _Tp>
727276792Sdimstatic inline bool __c11_atomic_compare_exchange_weak(
728276792Sdim    _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success,
729276792Sdim    memory_order __failure) {
730276792Sdim  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
731276792Sdim                                   true,
732276792Sdim                                   __gcc_atomic::__to_gcc_order(__success),
733288943Sdim                                   __gcc_atomic::__to_gcc_failure_order(__failure));
734276792Sdim}
735276792Sdim
736276792Sdimtemplate <typename _Tp>
737276792Sdimstruct __skip_amt { enum {value = 1}; };
738276792Sdim
739276792Sdimtemplate <typename _Tp>
740276792Sdimstruct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
741276792Sdim
742276792Sdim// FIXME: Haven't figured out what the spec says about using arrays with
743276792Sdim// atomic_fetch_add. Force a failure rather than creating bad behavior.
744276792Sdimtemplate <typename _Tp>
745276792Sdimstruct __skip_amt<_Tp[]> { };
746276792Sdimtemplate <typename _Tp, int n>
747276792Sdimstruct __skip_amt<_Tp[n]> { };
748276792Sdim
749276792Sdimtemplate <typename _Tp, typename _Td>
750276792Sdimstatic inline _Tp __c11_atomic_fetch_add(volatile _Atomic(_Tp)* __a,
751276792Sdim                                         _Td __delta, memory_order __order) {
752276792Sdim  return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
753276792Sdim                            __gcc_atomic::__to_gcc_order(__order));
754276792Sdim}
755276792Sdim
756276792Sdimtemplate <typename _Tp, typename _Td>
757276792Sdimstatic inline _Tp __c11_atomic_fetch_add(_Atomic(_Tp)* __a, _Td __delta,
758276792Sdim                                         memory_order __order) {
759276792Sdim  return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
760276792Sdim                            __gcc_atomic::__to_gcc_order(__order));
761276792Sdim}
762276792Sdim
763276792Sdimtemplate <typename _Tp, typename _Td>
764276792Sdimstatic inline _Tp __c11_atomic_fetch_sub(volatile _Atomic(_Tp)* __a,
765276792Sdim                                         _Td __delta, memory_order __order) {
766276792Sdim  return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
767276792Sdim                            __gcc_atomic::__to_gcc_order(__order));
768276792Sdim}
769276792Sdim
770276792Sdimtemplate <typename _Tp, typename _Td>
771276792Sdimstatic inline _Tp __c11_atomic_fetch_sub(_Atomic(_Tp)* __a, _Td __delta,
772276792Sdim                                         memory_order __order) {
773276792Sdim  return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
774276792Sdim                            __gcc_atomic::__to_gcc_order(__order));
775276792Sdim}
776276792Sdim
777276792Sdimtemplate <typename _Tp>
778276792Sdimstatic inline _Tp __c11_atomic_fetch_and(volatile _Atomic(_Tp)* __a,
779276792Sdim                                         _Tp __pattern, memory_order __order) {
780276792Sdim  return __atomic_fetch_and(&__a->__a_value, __pattern,
781276792Sdim                            __gcc_atomic::__to_gcc_order(__order));
782276792Sdim}
783276792Sdim
784276792Sdimtemplate <typename _Tp>
785276792Sdimstatic inline _Tp __c11_atomic_fetch_and(_Atomic(_Tp)* __a,
786276792Sdim                                         _Tp __pattern, memory_order __order) {
787276792Sdim  return __atomic_fetch_and(&__a->__a_value, __pattern,
788276792Sdim                            __gcc_atomic::__to_gcc_order(__order));
789276792Sdim}
790276792Sdim
791276792Sdimtemplate <typename _Tp>
792276792Sdimstatic inline _Tp __c11_atomic_fetch_or(volatile _Atomic(_Tp)* __a,
793276792Sdim                                        _Tp __pattern, memory_order __order) {
794276792Sdim  return __atomic_fetch_or(&__a->__a_value, __pattern,
795276792Sdim                           __gcc_atomic::__to_gcc_order(__order));
796276792Sdim}
797276792Sdim
798276792Sdimtemplate <typename _Tp>
799276792Sdimstatic inline _Tp __c11_atomic_fetch_or(_Atomic(_Tp)* __a, _Tp __pattern,
800276792Sdim                                        memory_order __order) {
801276792Sdim  return __atomic_fetch_or(&__a->__a_value, __pattern,
802276792Sdim                           __gcc_atomic::__to_gcc_order(__order));
803276792Sdim}
804276792Sdim
805276792Sdimtemplate <typename _Tp>
806276792Sdimstatic inline _Tp __c11_atomic_fetch_xor(volatile _Atomic(_Tp)* __a,
807276792Sdim                                         _Tp __pattern, memory_order __order) {
808276792Sdim  return __atomic_fetch_xor(&__a->__a_value, __pattern,
809276792Sdim                            __gcc_atomic::__to_gcc_order(__order));
810276792Sdim}
811276792Sdim
812276792Sdimtemplate <typename _Tp>
813276792Sdimstatic inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern,
814276792Sdim                                         memory_order __order) {
815276792Sdim  return __atomic_fetch_xor(&__a->__a_value, __pattern,
816276792Sdim                            __gcc_atomic::__to_gcc_order(__order));
817276792Sdim}
818300770Sdim#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP
819276792Sdim
820227825Stheraventemplate <class _Tp>
821227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
822227825Stheraven_Tp
823234959Stheravenkill_dependency(_Tp __y) _NOEXCEPT
824227825Stheraven{
825227825Stheraven    return __y;
826227825Stheraven}
827227825Stheraven
828227825Stheraven// general atomic<T>
829227825Stheraven
830227825Stheraventemplate <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
831227825Stheravenstruct __atomic_base  // false
832227825Stheraven{
833241900Sdim    mutable _Atomic(_Tp) __a_;
834227825Stheraven
835227825Stheraven    _LIBCPP_INLINE_VISIBILITY
836234959Stheraven    bool is_lock_free() const volatile _NOEXCEPT
837288943Sdim    {
838300770Sdim#if defined(_LIBCPP_HAS_C_ATOMIC_IMP)
839288943Sdim    return __c11_atomic_is_lock_free(sizeof(_Tp));
840288943Sdim#else
841288943Sdim    return __atomic_is_lock_free(sizeof(_Tp), 0);
842288943Sdim#endif
843288943Sdim    }
844227825Stheraven    _LIBCPP_INLINE_VISIBILITY
845234959Stheraven    bool is_lock_free() const _NOEXCEPT
846288943Sdim        {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();}
847227825Stheraven    _LIBCPP_INLINE_VISIBILITY
848234959Stheraven    void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
849234959Stheraven        {__c11_atomic_store(&__a_, __d, __m);}
850227825Stheraven    _LIBCPP_INLINE_VISIBILITY
851234959Stheraven    void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
852234959Stheraven        {__c11_atomic_store(&__a_, __d, __m);}
853227825Stheraven    _LIBCPP_INLINE_VISIBILITY
854234959Stheraven    _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
855234959Stheraven        {return __c11_atomic_load(&__a_, __m);}
856227825Stheraven    _LIBCPP_INLINE_VISIBILITY
857234959Stheraven    _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
858234959Stheraven        {return __c11_atomic_load(&__a_, __m);}
859227825Stheraven    _LIBCPP_INLINE_VISIBILITY
860234959Stheraven    operator _Tp() const volatile _NOEXCEPT {return load();}
861227825Stheraven    _LIBCPP_INLINE_VISIBILITY
862234959Stheraven    operator _Tp() const _NOEXCEPT          {return load();}
863227825Stheraven    _LIBCPP_INLINE_VISIBILITY
864234959Stheraven    _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
865234959Stheraven        {return __c11_atomic_exchange(&__a_, __d, __m);}
866227825Stheraven    _LIBCPP_INLINE_VISIBILITY
867234959Stheraven    _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
868234959Stheraven        {return __c11_atomic_exchange(&__a_, __d, __m);}
869227825Stheraven    _LIBCPP_INLINE_VISIBILITY
870227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
871234959Stheraven                               memory_order __s, memory_order __f) volatile _NOEXCEPT
872234959Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
873227825Stheraven    _LIBCPP_INLINE_VISIBILITY
874227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
875234959Stheraven                               memory_order __s, memory_order __f) _NOEXCEPT
876234959Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
877227825Stheraven    _LIBCPP_INLINE_VISIBILITY
878227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
879234959Stheraven                                 memory_order __s, memory_order __f) volatile _NOEXCEPT
880234959Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
881227825Stheraven    _LIBCPP_INLINE_VISIBILITY
882227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
883234959Stheraven                                 memory_order __s, memory_order __f) _NOEXCEPT
884234959Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
885227825Stheraven    _LIBCPP_INLINE_VISIBILITY
886227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
887234959Stheraven                              memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
888234959Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
889227825Stheraven    _LIBCPP_INLINE_VISIBILITY
890227825Stheraven    bool compare_exchange_weak(_Tp& __e, _Tp __d,
891234959Stheraven                               memory_order __m = memory_order_seq_cst) _NOEXCEPT
892234959Stheraven        {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
893227825Stheraven    _LIBCPP_INLINE_VISIBILITY
894227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
895234959Stheraven                              memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
896234959Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
897227825Stheraven    _LIBCPP_INLINE_VISIBILITY
898227825Stheraven    bool compare_exchange_strong(_Tp& __e, _Tp __d,
899234959Stheraven                                 memory_order __m = memory_order_seq_cst) _NOEXCEPT
900234959Stheraven        {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
901227825Stheraven
902227825Stheraven    _LIBCPP_INLINE_VISIBILITY
903253146Stheraven#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
904253146Stheraven    __atomic_base() _NOEXCEPT = default;
905253146Stheraven#else
906253146Stheraven    __atomic_base() _NOEXCEPT : __a_() {}
907253146Stheraven#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
908253146Stheraven
909227825Stheraven    _LIBCPP_INLINE_VISIBILITY
910234959Stheraven    _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
911227825Stheraven#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
912227825Stheraven    __atomic_base(const __atomic_base&) = delete;
913227825Stheraven    __atomic_base& operator=(const __atomic_base&) = delete;
914227825Stheraven    __atomic_base& operator=(const __atomic_base&) volatile = delete;
915227825Stheraven#else  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
916227825Stheravenprivate:
917227825Stheraven    __atomic_base(const __atomic_base&);
918227825Stheraven    __atomic_base& operator=(const __atomic_base&);
919227825Stheraven    __atomic_base& operator=(const __atomic_base&) volatile;
920227825Stheraven#endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
921227825Stheraven};
922227825Stheraven
923227825Stheraven// atomic<Integral>
924227825Stheraven
925227825Stheraventemplate <class _Tp>
926227825Stheravenstruct __atomic_base<_Tp, true>
927227825Stheraven    : public __atomic_base<_Tp, false>
928227825Stheraven{
929227825Stheraven    typedef __atomic_base<_Tp, false> __base;
930227825Stheraven    _LIBCPP_INLINE_VISIBILITY
931253146Stheraven    __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
932227825Stheraven    _LIBCPP_INLINE_VISIBILITY
933234959Stheraven    _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
934227825Stheraven
935227825Stheraven    _LIBCPP_INLINE_VISIBILITY
936234959Stheraven    _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
937234959Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
938227825Stheraven    _LIBCPP_INLINE_VISIBILITY
939234959Stheraven    _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
940234959Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
941227825Stheraven    _LIBCPP_INLINE_VISIBILITY
942234959Stheraven    _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
943234959Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
944227825Stheraven    _LIBCPP_INLINE_VISIBILITY
945234959Stheraven    _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
946234959Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
947227825Stheraven    _LIBCPP_INLINE_VISIBILITY
948234959Stheraven    _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
949234959Stheraven        {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
950227825Stheraven    _LIBCPP_INLINE_VISIBILITY
951234959Stheraven    _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
952234959Stheraven        {return __c11_atomic_fetch_and(&this->__a_, __op, __m);}
953227825Stheraven    _LIBCPP_INLINE_VISIBILITY
954234959Stheraven    _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
955234959Stheraven        {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
956227825Stheraven    _LIBCPP_INLINE_VISIBILITY
957234959Stheraven    _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
958234959Stheraven        {return __c11_atomic_fetch_or(&this->__a_, __op, __m);}
959227825Stheraven    _LIBCPP_INLINE_VISIBILITY
960234959Stheraven    _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
961234959Stheraven        {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
962227825Stheraven    _LIBCPP_INLINE_VISIBILITY
963234959Stheraven    _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
964234959Stheraven        {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);}
965227825Stheraven
966227825Stheraven    _LIBCPP_INLINE_VISIBILITY
967234959Stheraven    _Tp operator++(int) volatile _NOEXCEPT      {return fetch_add(_Tp(1));}
968227825Stheraven    _LIBCPP_INLINE_VISIBILITY
969234959Stheraven    _Tp operator++(int) _NOEXCEPT               {return fetch_add(_Tp(1));}
970227825Stheraven    _LIBCPP_INLINE_VISIBILITY
971234959Stheraven    _Tp operator--(int) volatile _NOEXCEPT      {return fetch_sub(_Tp(1));}
972227825Stheraven    _LIBCPP_INLINE_VISIBILITY
973234959Stheraven    _Tp operator--(int) _NOEXCEPT               {return fetch_sub(_Tp(1));}
974227825Stheraven    _LIBCPP_INLINE_VISIBILITY
975234959Stheraven    _Tp operator++() volatile _NOEXCEPT         {return fetch_add(_Tp(1)) + _Tp(1);}
976227825Stheraven    _LIBCPP_INLINE_VISIBILITY
977234959Stheraven    _Tp operator++() _NOEXCEPT                  {return fetch_add(_Tp(1)) + _Tp(1);}
978227825Stheraven    _LIBCPP_INLINE_VISIBILITY
979234959Stheraven    _Tp operator--() volatile _NOEXCEPT         {return fetch_sub(_Tp(1)) - _Tp(1);}
980227825Stheraven    _LIBCPP_INLINE_VISIBILITY
981234959Stheraven    _Tp operator--() _NOEXCEPT                  {return fetch_sub(_Tp(1)) - _Tp(1);}
982227825Stheraven    _LIBCPP_INLINE_VISIBILITY
983234959Stheraven    _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
984227825Stheraven    _LIBCPP_INLINE_VISIBILITY
985234959Stheraven    _Tp operator+=(_Tp __op) _NOEXCEPT          {return fetch_add(__op) + __op;}
986227825Stheraven    _LIBCPP_INLINE_VISIBILITY
987234959Stheraven    _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
988227825Stheraven    _LIBCPP_INLINE_VISIBILITY
989234959Stheraven    _Tp operator-=(_Tp __op) _NOEXCEPT          {return fetch_sub(__op) - __op;}
990227825Stheraven    _LIBCPP_INLINE_VISIBILITY
991234959Stheraven    _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
992227825Stheraven    _LIBCPP_INLINE_VISIBILITY
993234959Stheraven    _Tp operator&=(_Tp __op) _NOEXCEPT          {return fetch_and(__op) & __op;}
994227825Stheraven    _LIBCPP_INLINE_VISIBILITY
995234959Stheraven    _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
996227825Stheraven    _LIBCPP_INLINE_VISIBILITY
997234959Stheraven    _Tp operator|=(_Tp __op) _NOEXCEPT          {return fetch_or(__op) | __op;}
998227825Stheraven    _LIBCPP_INLINE_VISIBILITY
999234959Stheraven    _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
1000227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1001234959Stheraven    _Tp operator^=(_Tp __op) _NOEXCEPT          {return fetch_xor(__op) ^ __op;}
1002227825Stheraven};
1003227825Stheraven
1004227825Stheraven// atomic<T>
1005227825Stheraven
1006227825Stheraventemplate <class _Tp>
1007227825Stheravenstruct atomic
1008227825Stheraven    : public __atomic_base<_Tp>
1009227825Stheraven{
1010227825Stheraven    typedef __atomic_base<_Tp> __base;
1011227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1012253146Stheraven    atomic() _NOEXCEPT _LIBCPP_DEFAULT
1013227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1014234959Stheraven    _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
1015227825Stheraven
1016227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1017234959Stheraven    _Tp operator=(_Tp __d) volatile _NOEXCEPT
1018227825Stheraven        {__base::store(__d); return __d;}
1019227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1020234959Stheraven    _Tp operator=(_Tp __d) _NOEXCEPT
1021227825Stheraven        {__base::store(__d); return __d;}
1022227825Stheraven};
1023227825Stheraven
1024227825Stheraven// atomic<T*>
1025227825Stheraven
1026227825Stheraventemplate <class _Tp>
1027227825Stheravenstruct atomic<_Tp*>
1028227825Stheraven    : public __atomic_base<_Tp*>
1029227825Stheraven{
1030227825Stheraven    typedef __atomic_base<_Tp*> __base;
1031227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1032253146Stheraven    atomic() _NOEXCEPT _LIBCPP_DEFAULT
1033227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1034234959Stheraven    _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
1035227825Stheraven
1036227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1037234959Stheraven    _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
1038227825Stheraven        {__base::store(__d); return __d;}
1039227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1040234959Stheraven    _Tp* operator=(_Tp* __d) _NOEXCEPT
1041227825Stheraven        {__base::store(__d); return __d;}
1042227825Stheraven
1043227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1044227825Stheraven    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
1045234959Stheraven                                                                        volatile _NOEXCEPT
1046234959Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
1047227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1048234959Stheraven    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
1049234959Stheraven        {return __c11_atomic_fetch_add(&this->__a_, __op, __m);}
1050227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1051227825Stheraven    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
1052234959Stheraven                                                                        volatile _NOEXCEPT
1053234959Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
1054227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1055234959Stheraven    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
1056234959Stheraven        {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);}
1057227825Stheraven
1058227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1059234959Stheraven    _Tp* operator++(int) volatile _NOEXCEPT            {return fetch_add(1);}
1060227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1061234959Stheraven    _Tp* operator++(int) _NOEXCEPT                     {return fetch_add(1);}
1062227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1063234959Stheraven    _Tp* operator--(int) volatile _NOEXCEPT            {return fetch_sub(1);}
1064227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1065234959Stheraven    _Tp* operator--(int) _NOEXCEPT                     {return fetch_sub(1);}
1066227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1067234959Stheraven    _Tp* operator++() volatile _NOEXCEPT               {return fetch_add(1) + 1;}
1068227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1069234959Stheraven    _Tp* operator++() _NOEXCEPT                        {return fetch_add(1) + 1;}
1070227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1071234959Stheraven    _Tp* operator--() volatile _NOEXCEPT               {return fetch_sub(1) - 1;}
1072227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1073234959Stheraven    _Tp* operator--() _NOEXCEPT                        {return fetch_sub(1) - 1;}
1074227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1075234959Stheraven    _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
1076227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1077234959Stheraven    _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT          {return fetch_add(__op) + __op;}
1078227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1079234959Stheraven    _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
1080227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1081234959Stheraven    _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT          {return fetch_sub(__op) - __op;}
1082227825Stheraven};
1083227825Stheraven
1084227825Stheraven// atomic_is_lock_free
1085227825Stheraven
1086227825Stheraventemplate <class _Tp>
1087227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1088227825Stheravenbool
1089234959Stheravenatomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
1090227825Stheraven{
1091227825Stheraven    return __o->is_lock_free();
1092227825Stheraven}
1093227825Stheraven
1094227825Stheraventemplate <class _Tp>
1095227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1096227825Stheravenbool
1097234959Stheravenatomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
1098227825Stheraven{
1099227825Stheraven    return __o->is_lock_free();
1100227825Stheraven}
1101227825Stheraven
1102227825Stheraven// atomic_init
1103227825Stheraven
1104227825Stheraventemplate <class _Tp>
1105227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1106227825Stheravenvoid
1107234959Stheravenatomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
1108227825Stheraven{
1109234959Stheraven    __c11_atomic_init(&__o->__a_, __d);
1110227825Stheraven}
1111227825Stheraven
1112227825Stheraventemplate <class _Tp>
1113227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1114227825Stheravenvoid
1115234959Stheravenatomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
1116227825Stheraven{
1117234959Stheraven    __c11_atomic_init(&__o->__a_, __d);
1118227825Stheraven}
1119227825Stheraven
1120227825Stheraven// atomic_store
1121227825Stheraven
1122227825Stheraventemplate <class _Tp>
1123227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1124227825Stheravenvoid
1125234959Stheravenatomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
1126227825Stheraven{
1127227825Stheraven    __o->store(__d);
1128227825Stheraven}
1129227825Stheraven
1130227825Stheraventemplate <class _Tp>
1131227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1132227825Stheravenvoid
1133234959Stheravenatomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
1134227825Stheraven{
1135227825Stheraven    __o->store(__d);
1136227825Stheraven}
1137227825Stheraven
1138227825Stheraven// atomic_store_explicit
1139227825Stheraven
1140227825Stheraventemplate <class _Tp>
1141227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1142227825Stheravenvoid
1143234959Stheravenatomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
1144227825Stheraven{
1145227825Stheraven    __o->store(__d, __m);
1146227825Stheraven}
1147227825Stheraven
1148227825Stheraventemplate <class _Tp>
1149227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1150227825Stheravenvoid
1151234959Stheravenatomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
1152227825Stheraven{
1153227825Stheraven    __o->store(__d, __m);
1154227825Stheraven}
1155227825Stheraven
1156227825Stheraven// atomic_load
1157227825Stheraven
1158227825Stheraventemplate <class _Tp>
1159227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1160227825Stheraven_Tp
1161234959Stheravenatomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
1162227825Stheraven{
1163227825Stheraven    return __o->load();
1164227825Stheraven}
1165227825Stheraven
1166227825Stheraventemplate <class _Tp>
1167227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1168227825Stheraven_Tp
1169234959Stheravenatomic_load(const atomic<_Tp>* __o) _NOEXCEPT
1170227825Stheraven{
1171227825Stheraven    return __o->load();
1172227825Stheraven}
1173227825Stheraven
1174227825Stheraven// atomic_load_explicit
1175227825Stheraven
1176227825Stheraventemplate <class _Tp>
1177227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1178227825Stheraven_Tp
1179234959Stheravenatomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
1180227825Stheraven{
1181227825Stheraven    return __o->load(__m);
1182227825Stheraven}
1183227825Stheraven
1184227825Stheraventemplate <class _Tp>
1185227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1186227825Stheraven_Tp
1187234959Stheravenatomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
1188227825Stheraven{
1189227825Stheraven    return __o->load(__m);
1190227825Stheraven}
1191227825Stheraven
1192227825Stheraven// atomic_exchange
1193227825Stheraven
1194227825Stheraventemplate <class _Tp>
1195227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1196227825Stheraven_Tp
1197234959Stheravenatomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
1198227825Stheraven{
1199227825Stheraven    return __o->exchange(__d);
1200227825Stheraven}
1201227825Stheraven
1202227825Stheraventemplate <class _Tp>
1203227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1204227825Stheraven_Tp
1205234959Stheravenatomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
1206227825Stheraven{
1207227825Stheraven    return __o->exchange(__d);
1208227825Stheraven}
1209227825Stheraven
1210227825Stheraven// atomic_exchange_explicit
1211227825Stheraven
1212227825Stheraventemplate <class _Tp>
1213227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1214227825Stheraven_Tp
1215234959Stheravenatomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
1216227825Stheraven{
1217227825Stheraven    return __o->exchange(__d, __m);
1218227825Stheraven}
1219227825Stheraven
1220227825Stheraventemplate <class _Tp>
1221227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1222227825Stheraven_Tp
1223234959Stheravenatomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
1224227825Stheraven{
1225227825Stheraven    return __o->exchange(__d, __m);
1226227825Stheraven}
1227227825Stheraven
1228227825Stheraven// atomic_compare_exchange_weak
1229227825Stheraven
1230227825Stheraventemplate <class _Tp>
1231227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1232227825Stheravenbool
1233234959Stheravenatomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
1234227825Stheraven{
1235227825Stheraven    return __o->compare_exchange_weak(*__e, __d);
1236227825Stheraven}
1237227825Stheraven
1238227825Stheraventemplate <class _Tp>
1239227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1240227825Stheravenbool
1241234959Stheravenatomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
1242227825Stheraven{
1243227825Stheraven    return __o->compare_exchange_weak(*__e, __d);
1244227825Stheraven}
1245227825Stheraven
1246227825Stheraven// atomic_compare_exchange_strong
1247227825Stheraven
1248227825Stheraventemplate <class _Tp>
1249227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1250227825Stheravenbool
1251234959Stheravenatomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
1252227825Stheraven{
1253227825Stheraven    return __o->compare_exchange_strong(*__e, __d);
1254227825Stheraven}
1255227825Stheraven
1256227825Stheraventemplate <class _Tp>
1257227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1258227825Stheravenbool
1259234959Stheravenatomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
1260227825Stheraven{
1261227825Stheraven    return __o->compare_exchange_strong(*__e, __d);
1262227825Stheraven}
1263227825Stheraven
1264227825Stheraven// atomic_compare_exchange_weak_explicit
1265227825Stheraven
1266227825Stheraventemplate <class _Tp>
1267227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1268227825Stheravenbool
1269227825Stheravenatomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
1270227825Stheraven                                      _Tp __d,
1271234959Stheraven                                      memory_order __s, memory_order __f) _NOEXCEPT
1272227825Stheraven{
1273227825Stheraven    return __o->compare_exchange_weak(*__e, __d, __s, __f);
1274227825Stheraven}
1275227825Stheraven
1276227825Stheraventemplate <class _Tp>
1277227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1278227825Stheravenbool
1279227825Stheravenatomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
1280234959Stheraven                                      memory_order __s, memory_order __f) _NOEXCEPT
1281227825Stheraven{
1282227825Stheraven    return __o->compare_exchange_weak(*__e, __d, __s, __f);
1283227825Stheraven}
1284227825Stheraven
1285227825Stheraven// atomic_compare_exchange_strong_explicit
1286227825Stheraven
1287227825Stheraventemplate <class _Tp>
1288227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1289227825Stheravenbool
1290227825Stheravenatomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
1291227825Stheraven                                        _Tp* __e, _Tp __d,
1292234959Stheraven                                        memory_order __s, memory_order __f) _NOEXCEPT
1293227825Stheraven{
1294227825Stheraven    return __o->compare_exchange_strong(*__e, __d, __s, __f);
1295227825Stheraven}
1296227825Stheraven
1297227825Stheraventemplate <class _Tp>
1298227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1299227825Stheravenbool
1300227825Stheravenatomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
1301227825Stheraven                                        _Tp __d,
1302234959Stheraven                                        memory_order __s, memory_order __f) _NOEXCEPT
1303227825Stheraven{
1304227825Stheraven    return __o->compare_exchange_strong(*__e, __d, __s, __f);
1305227825Stheraven}
1306227825Stheraven
1307227825Stheraven// atomic_fetch_add
1308227825Stheraven
1309227825Stheraventemplate <class _Tp>
1310227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1311227825Stheraventypename enable_if
1312227825Stheraven<
1313227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1314227825Stheraven    _Tp
1315227825Stheraven>::type
1316234959Stheravenatomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1317227825Stheraven{
1318227825Stheraven    return __o->fetch_add(__op);
1319227825Stheraven}
1320227825Stheraven
1321227825Stheraventemplate <class _Tp>
1322227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1323227825Stheraventypename enable_if
1324227825Stheraven<
1325227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1326227825Stheraven    _Tp
1327227825Stheraven>::type
1328234959Stheravenatomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1329227825Stheraven{
1330227825Stheraven    return __o->fetch_add(__op);
1331227825Stheraven}
1332227825Stheraven
1333227825Stheraventemplate <class _Tp>
1334227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1335227825Stheraven_Tp*
1336234959Stheravenatomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1337227825Stheraven{
1338227825Stheraven    return __o->fetch_add(__op);
1339227825Stheraven}
1340227825Stheraven
1341227825Stheraventemplate <class _Tp>
1342227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1343227825Stheraven_Tp*
1344234959Stheravenatomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1345227825Stheraven{
1346227825Stheraven    return __o->fetch_add(__op);
1347227825Stheraven}
1348227825Stheraven
1349227825Stheraven// atomic_fetch_add_explicit
1350227825Stheraven
1351227825Stheraventemplate <class _Tp>
1352227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1353227825Stheraventypename enable_if
1354227825Stheraven<
1355227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1356227825Stheraven    _Tp
1357227825Stheraven>::type
1358234959Stheravenatomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1359227825Stheraven{
1360227825Stheraven    return __o->fetch_add(__op, __m);
1361227825Stheraven}
1362227825Stheraven
1363227825Stheraventemplate <class _Tp>
1364227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1365227825Stheraventypename enable_if
1366227825Stheraven<
1367227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1368227825Stheraven    _Tp
1369227825Stheraven>::type
1370234959Stheravenatomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1371227825Stheraven{
1372227825Stheraven    return __o->fetch_add(__op, __m);
1373227825Stheraven}
1374227825Stheraven
1375227825Stheraventemplate <class _Tp>
1376227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1377227825Stheraven_Tp*
1378227825Stheravenatomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
1379234959Stheraven                          memory_order __m) _NOEXCEPT
1380227825Stheraven{
1381227825Stheraven    return __o->fetch_add(__op, __m);
1382227825Stheraven}
1383227825Stheraven
1384227825Stheraventemplate <class _Tp>
1385227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1386227825Stheraven_Tp*
1387234959Stheravenatomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
1388227825Stheraven{
1389227825Stheraven    return __o->fetch_add(__op, __m);
1390227825Stheraven}
1391227825Stheraven
1392227825Stheraven// atomic_fetch_sub
1393227825Stheraven
1394227825Stheraventemplate <class _Tp>
1395227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1396227825Stheraventypename enable_if
1397227825Stheraven<
1398227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1399227825Stheraven    _Tp
1400227825Stheraven>::type
1401234959Stheravenatomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1402227825Stheraven{
1403227825Stheraven    return __o->fetch_sub(__op);
1404227825Stheraven}
1405227825Stheraven
1406227825Stheraventemplate <class _Tp>
1407227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1408227825Stheraventypename enable_if
1409227825Stheraven<
1410227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1411227825Stheraven    _Tp
1412227825Stheraven>::type
1413234959Stheravenatomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1414227825Stheraven{
1415227825Stheraven    return __o->fetch_sub(__op);
1416227825Stheraven}
1417227825Stheraven
1418227825Stheraventemplate <class _Tp>
1419227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1420227825Stheraven_Tp*
1421234959Stheravenatomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1422227825Stheraven{
1423227825Stheraven    return __o->fetch_sub(__op);
1424227825Stheraven}
1425227825Stheraven
1426227825Stheraventemplate <class _Tp>
1427227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1428227825Stheraven_Tp*
1429234959Stheravenatomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
1430227825Stheraven{
1431227825Stheraven    return __o->fetch_sub(__op);
1432227825Stheraven}
1433227825Stheraven
1434227825Stheraven// atomic_fetch_sub_explicit
1435227825Stheraven
1436227825Stheraventemplate <class _Tp>
1437227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1438227825Stheraventypename enable_if
1439227825Stheraven<
1440227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1441227825Stheraven    _Tp
1442227825Stheraven>::type
1443234959Stheravenatomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1444227825Stheraven{
1445227825Stheraven    return __o->fetch_sub(__op, __m);
1446227825Stheraven}
1447227825Stheraven
1448227825Stheraventemplate <class _Tp>
1449227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1450227825Stheraventypename enable_if
1451227825Stheraven<
1452227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1453227825Stheraven    _Tp
1454227825Stheraven>::type
1455234959Stheravenatomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1456227825Stheraven{
1457227825Stheraven    return __o->fetch_sub(__op, __m);
1458227825Stheraven}
1459227825Stheraven
1460227825Stheraventemplate <class _Tp>
1461227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1462227825Stheraven_Tp*
1463227825Stheravenatomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
1464234959Stheraven                          memory_order __m) _NOEXCEPT
1465227825Stheraven{
1466227825Stheraven    return __o->fetch_sub(__op, __m);
1467227825Stheraven}
1468227825Stheraven
1469227825Stheraventemplate <class _Tp>
1470227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1471227825Stheraven_Tp*
1472234959Stheravenatomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
1473227825Stheraven{
1474227825Stheraven    return __o->fetch_sub(__op, __m);
1475227825Stheraven}
1476227825Stheraven
1477227825Stheraven// atomic_fetch_and
1478227825Stheraven
1479227825Stheraventemplate <class _Tp>
1480227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1481227825Stheraventypename enable_if
1482227825Stheraven<
1483227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1484227825Stheraven    _Tp
1485227825Stheraven>::type
1486234959Stheravenatomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1487227825Stheraven{
1488227825Stheraven    return __o->fetch_and(__op);
1489227825Stheraven}
1490227825Stheraven
1491227825Stheraventemplate <class _Tp>
1492227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1493227825Stheraventypename enable_if
1494227825Stheraven<
1495227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1496227825Stheraven    _Tp
1497227825Stheraven>::type
1498234959Stheravenatomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1499227825Stheraven{
1500227825Stheraven    return __o->fetch_and(__op);
1501227825Stheraven}
1502227825Stheraven
1503227825Stheraven// atomic_fetch_and_explicit
1504227825Stheraven
1505227825Stheraventemplate <class _Tp>
1506227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1507227825Stheraventypename enable_if
1508227825Stheraven<
1509227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1510227825Stheraven    _Tp
1511227825Stheraven>::type
1512234959Stheravenatomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1513227825Stheraven{
1514227825Stheraven    return __o->fetch_and(__op, __m);
1515227825Stheraven}
1516227825Stheraven
1517227825Stheraventemplate <class _Tp>
1518227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1519227825Stheraventypename enable_if
1520227825Stheraven<
1521227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1522227825Stheraven    _Tp
1523227825Stheraven>::type
1524234959Stheravenatomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1525227825Stheraven{
1526227825Stheraven    return __o->fetch_and(__op, __m);
1527227825Stheraven}
1528227825Stheraven
1529227825Stheraven// atomic_fetch_or
1530227825Stheraven
1531227825Stheraventemplate <class _Tp>
1532227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1533227825Stheraventypename enable_if
1534227825Stheraven<
1535227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1536227825Stheraven    _Tp
1537227825Stheraven>::type
1538234959Stheravenatomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1539227825Stheraven{
1540227825Stheraven    return __o->fetch_or(__op);
1541227825Stheraven}
1542227825Stheraven
1543227825Stheraventemplate <class _Tp>
1544227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1545227825Stheraventypename enable_if
1546227825Stheraven<
1547227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1548227825Stheraven    _Tp
1549227825Stheraven>::type
1550234959Stheravenatomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1551227825Stheraven{
1552227825Stheraven    return __o->fetch_or(__op);
1553227825Stheraven}
1554227825Stheraven
1555227825Stheraven// atomic_fetch_or_explicit
1556227825Stheraven
1557227825Stheraventemplate <class _Tp>
1558227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1559227825Stheraventypename enable_if
1560227825Stheraven<
1561227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1562227825Stheraven    _Tp
1563227825Stheraven>::type
1564234959Stheravenatomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1565227825Stheraven{
1566227825Stheraven    return __o->fetch_or(__op, __m);
1567227825Stheraven}
1568227825Stheraven
1569227825Stheraventemplate <class _Tp>
1570227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1571227825Stheraventypename enable_if
1572227825Stheraven<
1573227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1574227825Stheraven    _Tp
1575227825Stheraven>::type
1576234959Stheravenatomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1577227825Stheraven{
1578227825Stheraven    return __o->fetch_or(__op, __m);
1579227825Stheraven}
1580227825Stheraven
1581227825Stheraven// atomic_fetch_xor
1582227825Stheraven
1583227825Stheraventemplate <class _Tp>
1584227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1585227825Stheraventypename enable_if
1586227825Stheraven<
1587227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1588227825Stheraven    _Tp
1589227825Stheraven>::type
1590234959Stheravenatomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1591227825Stheraven{
1592227825Stheraven    return __o->fetch_xor(__op);
1593227825Stheraven}
1594227825Stheraven
1595227825Stheraventemplate <class _Tp>
1596227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1597227825Stheraventypename enable_if
1598227825Stheraven<
1599227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1600227825Stheraven    _Tp
1601227825Stheraven>::type
1602234959Stheravenatomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
1603227825Stheraven{
1604227825Stheraven    return __o->fetch_xor(__op);
1605227825Stheraven}
1606227825Stheraven
1607227825Stheraven// atomic_fetch_xor_explicit
1608227825Stheraven
1609227825Stheraventemplate <class _Tp>
1610227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1611227825Stheraventypename enable_if
1612227825Stheraven<
1613227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1614227825Stheraven    _Tp
1615227825Stheraven>::type
1616234959Stheravenatomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1617227825Stheraven{
1618227825Stheraven    return __o->fetch_xor(__op, __m);
1619227825Stheraven}
1620227825Stheraven
1621227825Stheraventemplate <class _Tp>
1622227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1623227825Stheraventypename enable_if
1624227825Stheraven<
1625227825Stheraven    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
1626227825Stheraven    _Tp
1627227825Stheraven>::type
1628234959Stheravenatomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
1629227825Stheraven{
1630227825Stheraven    return __o->fetch_xor(__op, __m);
1631227825Stheraven}
1632227825Stheraven
1633227825Stheraven// flag type and operations
1634227825Stheraven
1635227825Stheraventypedef struct atomic_flag
1636227825Stheraven{
1637232924Stheraven    _Atomic(bool) __a_;
1638227825Stheraven
1639227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1640234959Stheraven    bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
1641234959Stheraven        {return __c11_atomic_exchange(&__a_, true, __m);}
1642227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1643234959Stheraven    bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
1644234959Stheraven        {return __c11_atomic_exchange(&__a_, true, __m);}
1645227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1646234959Stheraven    void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
1647234959Stheraven        {__c11_atomic_store(&__a_, false, __m);}
1648227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1649234959Stheraven    void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
1650234959Stheraven        {__c11_atomic_store(&__a_, false, __m);}
1651227825Stheraven
1652227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1653253146Stheraven#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1654253146Stheraven    atomic_flag() _NOEXCEPT = default;
1655253146Stheraven#else
1656253146Stheraven    atomic_flag() _NOEXCEPT : __a_() {}
1657253146Stheraven#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1658253146Stheraven
1659227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1660234959Stheraven    atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {}
1661227825Stheraven
1662227825Stheraven#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1663227825Stheraven    atomic_flag(const atomic_flag&) = delete;
1664227825Stheraven    atomic_flag& operator=(const atomic_flag&) = delete;
1665227825Stheraven    atomic_flag& operator=(const atomic_flag&) volatile = delete;
1666227825Stheraven#else  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1667227825Stheravenprivate:
1668227825Stheraven    atomic_flag(const atomic_flag&);
1669227825Stheraven    atomic_flag& operator=(const atomic_flag&);
1670227825Stheraven    atomic_flag& operator=(const atomic_flag&) volatile;
1671227825Stheraven#endif  // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1672227825Stheraven} atomic_flag;
1673227825Stheraven
1674227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1675227825Stheravenbool
1676234959Stheravenatomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
1677227825Stheraven{
1678227825Stheraven    return __o->test_and_set();
1679227825Stheraven}
1680227825Stheraven
1681227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1682227825Stheravenbool
1683234959Stheravenatomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
1684227825Stheraven{
1685227825Stheraven    return __o->test_and_set();
1686227825Stheraven}
1687227825Stheraven
1688227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1689227825Stheravenbool
1690234959Stheravenatomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
1691227825Stheraven{
1692227825Stheraven    return __o->test_and_set(__m);
1693227825Stheraven}
1694227825Stheraven
1695227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1696227825Stheravenbool
1697234959Stheravenatomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
1698227825Stheraven{
1699227825Stheraven    return __o->test_and_set(__m);
1700227825Stheraven}
1701227825Stheraven
1702227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1703227825Stheravenvoid
1704234959Stheravenatomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
1705227825Stheraven{
1706227825Stheraven    __o->clear();
1707227825Stheraven}
1708227825Stheraven
1709227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1710227825Stheravenvoid
1711234959Stheravenatomic_flag_clear(atomic_flag* __o) _NOEXCEPT
1712227825Stheraven{
1713227825Stheraven    __o->clear();
1714227825Stheraven}
1715227825Stheraven
1716227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1717227825Stheravenvoid
1718234959Stheravenatomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
1719227825Stheraven{
1720227825Stheraven    __o->clear(__m);
1721227825Stheraven}
1722227825Stheraven
1723227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1724227825Stheravenvoid
1725234959Stheravenatomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
1726227825Stheraven{
1727227825Stheraven    __o->clear(__m);
1728227825Stheraven}
1729227825Stheraven
1730227825Stheraven// fences
1731227825Stheraven
1732227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1733227825Stheravenvoid
1734234959Stheravenatomic_thread_fence(memory_order __m) _NOEXCEPT
1735227825Stheraven{
1736234959Stheraven    __c11_atomic_thread_fence(__m);
1737227825Stheraven}
1738227825Stheraven
1739227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1740227825Stheravenvoid
1741234959Stheravenatomic_signal_fence(memory_order __m) _NOEXCEPT
1742227825Stheraven{
1743234959Stheraven    __c11_atomic_signal_fence(__m);
1744227825Stheraven}
1745227825Stheraven
1746227825Stheraven// Atomics for standard typedef types
1747227825Stheraven
1748246468Stheraventypedef atomic<bool>               atomic_bool;
1749227825Stheraventypedef atomic<char>               atomic_char;
1750227825Stheraventypedef atomic<signed char>        atomic_schar;
1751227825Stheraventypedef atomic<unsigned char>      atomic_uchar;
1752227825Stheraventypedef atomic<short>              atomic_short;
1753227825Stheraventypedef atomic<unsigned short>     atomic_ushort;
1754227825Stheraventypedef atomic<int>                atomic_int;
1755227825Stheraventypedef atomic<unsigned int>       atomic_uint;
1756227825Stheraventypedef atomic<long>               atomic_long;
1757227825Stheraventypedef atomic<unsigned long>      atomic_ulong;
1758227825Stheraventypedef atomic<long long>          atomic_llong;
1759227825Stheraventypedef atomic<unsigned long long> atomic_ullong;
1760227825Stheraventypedef atomic<char16_t>           atomic_char16_t;
1761227825Stheraventypedef atomic<char32_t>           atomic_char32_t;
1762227825Stheraventypedef atomic<wchar_t>            atomic_wchar_t;
1763227825Stheraven
1764227825Stheraventypedef atomic<int_least8_t>   atomic_int_least8_t;
1765227825Stheraventypedef atomic<uint_least8_t>  atomic_uint_least8_t;
1766227825Stheraventypedef atomic<int_least16_t>  atomic_int_least16_t;
1767227825Stheraventypedef atomic<uint_least16_t> atomic_uint_least16_t;
1768227825Stheraventypedef atomic<int_least32_t>  atomic_int_least32_t;
1769227825Stheraventypedef atomic<uint_least32_t> atomic_uint_least32_t;
1770227825Stheraventypedef atomic<int_least64_t>  atomic_int_least64_t;
1771227825Stheraventypedef atomic<uint_least64_t> atomic_uint_least64_t;
1772227825Stheraven
1773227825Stheraventypedef atomic<int_fast8_t>   atomic_int_fast8_t;
1774227825Stheraventypedef atomic<uint_fast8_t>  atomic_uint_fast8_t;
1775227825Stheraventypedef atomic<int_fast16_t>  atomic_int_fast16_t;
1776227825Stheraventypedef atomic<uint_fast16_t> atomic_uint_fast16_t;
1777227825Stheraventypedef atomic<int_fast32_t>  atomic_int_fast32_t;
1778227825Stheraventypedef atomic<uint_fast32_t> atomic_uint_fast32_t;
1779227825Stheraventypedef atomic<int_fast64_t>  atomic_int_fast64_t;
1780227825Stheraventypedef atomic<uint_fast64_t> atomic_uint_fast64_t;
1781227825Stheraven
1782227825Stheraventypedef atomic<intptr_t>  atomic_intptr_t;
1783227825Stheraventypedef atomic<uintptr_t> atomic_uintptr_t;
1784227825Stheraventypedef atomic<size_t>    atomic_size_t;
1785227825Stheraventypedef atomic<ptrdiff_t> atomic_ptrdiff_t;
1786227825Stheraventypedef atomic<intmax_t>  atomic_intmax_t;
1787227825Stheraventypedef atomic<uintmax_t> atomic_uintmax_t;
1788227825Stheraven
1789227825Stheraven#define ATOMIC_FLAG_INIT {false}
1790227825Stheraven#define ATOMIC_VAR_INIT(__v) {__v}
1791227825Stheraven
1792246468Stheraven#define ATOMIC_BOOL_LOCK_FREE      __GCC_ATOMIC_BOOL_LOCK_FREE
1793246468Stheraven#define ATOMIC_CHAR_LOCK_FREE      __GCC_ATOMIC_CHAR_LOCK_FREE
1794246468Stheraven#define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
1795246468Stheraven#define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
1796246468Stheraven#define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
1797246468Stheraven#define ATOMIC_SHORT_LOCK_FREE     __GCC_ATOMIC_SHORT_LOCK_FREE
1798246468Stheraven#define ATOMIC_INT_LOCK_FREE       __GCC_ATOMIC_INT_LOCK_FREE
1799246468Stheraven#define ATOMIC_LONG_LOCK_FREE      __GCC_ATOMIC_LONG_LOCK_FREE
1800246468Stheraven#define ATOMIC_LLONG_LOCK_FREE     __GCC_ATOMIC_LLONG_LOCK_FREE
1801246468Stheraven#define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
1802227825Stheraven
1803227825Stheraven_LIBCPP_END_NAMESPACE_STD
1804227825Stheraven
1805227825Stheraven#endif  // _LIBCPP_ATOMIC
1806