xref: /freebsd/contrib/llvm-project/libcxx/include/atomic (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric// -*- C++ -*-
20b57cec5SDimitry Andric//===--------------------------- atomic -----------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_ATOMIC
110b57cec5SDimitry Andric#define _LIBCPP_ATOMIC
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    atomic synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
19*e8d8bef9SDimitry Andric// feature test macro [version.syn]
200b57cec5SDimitry Andric
21*e8d8bef9SDimitry Andric#define __cpp_lib_atomic_is_always_lock_free
22*e8d8bef9SDimitry Andric#define __cpp_lib_atomic_flag_test
23*e8d8bef9SDimitry Andric#define __cpp_lib_atomic_lock_free_type_aliases
24*e8d8bef9SDimitry Andric#define __cpp_lib_atomic_wait
250b57cec5SDimitry Andric
260b57cec5SDimitry Andric // order and consistency
270b57cec5SDimitry Andric
280b57cec5SDimitry Andric enum memory_order: unspecified // enum class in C++20
290b57cec5SDimitry Andric {
300b57cec5SDimitry Andric    relaxed,
310b57cec5SDimitry Andric    consume, // load-consume
320b57cec5SDimitry Andric    acquire, // load-acquire
330b57cec5SDimitry Andric    release, // store-release
340b57cec5SDimitry Andric    acq_rel, // store-release load-acquire
350b57cec5SDimitry Andric    seq_cst // store-release load-acquire
360b57cec5SDimitry Andric };
370b57cec5SDimitry Andric
380b57cec5SDimitry Andric inline constexpr auto memory_order_relaxed = memory_order::relaxed;
390b57cec5SDimitry Andric inline constexpr auto memory_order_consume = memory_order::consume;
400b57cec5SDimitry Andric inline constexpr auto memory_order_acquire = memory_order::acquire;
410b57cec5SDimitry Andric inline constexpr auto memory_order_release = memory_order::release;
420b57cec5SDimitry Andric inline constexpr auto memory_order_acq_rel = memory_order::acq_rel;
430b57cec5SDimitry Andric inline constexpr auto memory_order_seq_cst = memory_order::seq_cst;
440b57cec5SDimitry Andric
450b57cec5SDimitry Andrictemplate <class T> T kill_dependency(T y) noexcept;
460b57cec5SDimitry Andric
470b57cec5SDimitry Andric// lock-free property
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric#define ATOMIC_BOOL_LOCK_FREE unspecified
500b57cec5SDimitry Andric#define ATOMIC_CHAR_LOCK_FREE unspecified
51*e8d8bef9SDimitry Andric#define ATOMIC_CHAR8_T_LOCK_FREE unspecified // C++20
520b57cec5SDimitry Andric#define ATOMIC_CHAR16_T_LOCK_FREE unspecified
530b57cec5SDimitry Andric#define ATOMIC_CHAR32_T_LOCK_FREE unspecified
540b57cec5SDimitry Andric#define ATOMIC_WCHAR_T_LOCK_FREE unspecified
550b57cec5SDimitry Andric#define ATOMIC_SHORT_LOCK_FREE unspecified
560b57cec5SDimitry Andric#define ATOMIC_INT_LOCK_FREE unspecified
570b57cec5SDimitry Andric#define ATOMIC_LONG_LOCK_FREE unspecified
580b57cec5SDimitry Andric#define ATOMIC_LLONG_LOCK_FREE unspecified
590b57cec5SDimitry Andric#define ATOMIC_POINTER_LOCK_FREE unspecified
600b57cec5SDimitry Andric
610b57cec5SDimitry Andrictemplate <class T>
620b57cec5SDimitry Andricstruct atomic
630b57cec5SDimitry Andric{
645ffd83dbSDimitry Andric    using value_type = T;
655ffd83dbSDimitry Andric
660b57cec5SDimitry Andric    static constexpr bool is_always_lock_free;
670b57cec5SDimitry Andric    bool is_lock_free() const volatile noexcept;
680b57cec5SDimitry Andric    bool is_lock_free() const noexcept;
695ffd83dbSDimitry Andric
705ffd83dbSDimitry Andric    atomic() noexcept = default;
715ffd83dbSDimitry Andric    constexpr atomic(T desr) noexcept;
725ffd83dbSDimitry Andric    atomic(const atomic&) = delete;
735ffd83dbSDimitry Andric    atomic& operator=(const atomic&) = delete;
745ffd83dbSDimitry Andric    atomic& operator=(const atomic&) volatile = delete;
755ffd83dbSDimitry Andric
760b57cec5SDimitry Andric    T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
770b57cec5SDimitry Andric    T load(memory_order m = memory_order_seq_cst) const noexcept;
780b57cec5SDimitry Andric    operator T() const volatile noexcept;
790b57cec5SDimitry Andric    operator T() const noexcept;
805ffd83dbSDimitry Andric    void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
815ffd83dbSDimitry Andric    void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
825ffd83dbSDimitry Andric    T operator=(T) volatile noexcept;
835ffd83dbSDimitry Andric    T operator=(T) noexcept;
845ffd83dbSDimitry Andric
850b57cec5SDimitry Andric    T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
860b57cec5SDimitry Andric    T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
870b57cec5SDimitry Andric    bool compare_exchange_weak(T& expc, T desr,
880b57cec5SDimitry Andric                               memory_order s, memory_order f) volatile noexcept;
890b57cec5SDimitry Andric    bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept;
900b57cec5SDimitry Andric    bool compare_exchange_strong(T& expc, T desr,
910b57cec5SDimitry Andric                                 memory_order s, memory_order f) volatile noexcept;
920b57cec5SDimitry Andric    bool compare_exchange_strong(T& expc, T desr,
930b57cec5SDimitry Andric                                 memory_order s, memory_order f) noexcept;
940b57cec5SDimitry Andric    bool compare_exchange_weak(T& expc, T desr,
950b57cec5SDimitry Andric                               memory_order m = memory_order_seq_cst) volatile noexcept;
960b57cec5SDimitry Andric    bool compare_exchange_weak(T& expc, T desr,
970b57cec5SDimitry Andric                               memory_order m = memory_order_seq_cst) noexcept;
980b57cec5SDimitry Andric    bool compare_exchange_strong(T& expc, T desr,
990b57cec5SDimitry Andric                                memory_order m = memory_order_seq_cst) volatile noexcept;
1000b57cec5SDimitry Andric    bool compare_exchange_strong(T& expc, T desr,
1010b57cec5SDimitry Andric                                 memory_order m = memory_order_seq_cst) noexcept;
1020b57cec5SDimitry Andric
1035ffd83dbSDimitry Andric    void wait(T, memory_order = memory_order::seq_cst) const volatile noexcept;
1045ffd83dbSDimitry Andric    void wait(T, memory_order = memory_order::seq_cst) const noexcept;
1055ffd83dbSDimitry Andric    void notify_one() volatile noexcept;
1065ffd83dbSDimitry Andric    void notify_one() noexcept;
1075ffd83dbSDimitry Andric    void notify_all() volatile noexcept;
1085ffd83dbSDimitry Andric    void notify_all() noexcept;
1090b57cec5SDimitry Andric};
1100b57cec5SDimitry Andric
1110b57cec5SDimitry Andrictemplate <>
1120b57cec5SDimitry Andricstruct atomic<integral>
1130b57cec5SDimitry Andric{
1145ffd83dbSDimitry Andric    using value_type = integral;
115*e8d8bef9SDimitry Andric    using difference_type = value_type;
1165ffd83dbSDimitry Andric
1170b57cec5SDimitry Andric    static constexpr bool is_always_lock_free;
1180b57cec5SDimitry Andric    bool is_lock_free() const volatile noexcept;
1190b57cec5SDimitry Andric    bool is_lock_free() const noexcept;
1205ffd83dbSDimitry Andric
1215ffd83dbSDimitry Andric    atomic() noexcept = default;
1225ffd83dbSDimitry Andric    constexpr atomic(integral desr) noexcept;
1235ffd83dbSDimitry Andric    atomic(const atomic&) = delete;
1245ffd83dbSDimitry Andric    atomic& operator=(const atomic&) = delete;
1255ffd83dbSDimitry Andric    atomic& operator=(const atomic&) volatile = delete;
1265ffd83dbSDimitry Andric
1270b57cec5SDimitry Andric    integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
1280b57cec5SDimitry Andric    integral load(memory_order m = memory_order_seq_cst) const noexcept;
1290b57cec5SDimitry Andric    operator integral() const volatile noexcept;
1300b57cec5SDimitry Andric    operator integral() const noexcept;
1315ffd83dbSDimitry Andric    void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
1325ffd83dbSDimitry Andric    void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
1335ffd83dbSDimitry Andric    integral operator=(integral desr) volatile noexcept;
1345ffd83dbSDimitry Andric    integral operator=(integral desr) noexcept;
1355ffd83dbSDimitry Andric
1360b57cec5SDimitry Andric    integral exchange(integral desr,
1370b57cec5SDimitry Andric                      memory_order m = memory_order_seq_cst) volatile noexcept;
1380b57cec5SDimitry Andric    integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
1390b57cec5SDimitry Andric    bool compare_exchange_weak(integral& expc, integral desr,
1400b57cec5SDimitry Andric                               memory_order s, memory_order f) volatile noexcept;
1410b57cec5SDimitry Andric    bool compare_exchange_weak(integral& expc, integral desr,
1420b57cec5SDimitry Andric                               memory_order s, memory_order f) noexcept;
1430b57cec5SDimitry Andric    bool compare_exchange_strong(integral& expc, integral desr,
1440b57cec5SDimitry Andric                                 memory_order s, memory_order f) volatile noexcept;
1450b57cec5SDimitry Andric    bool compare_exchange_strong(integral& expc, integral desr,
1460b57cec5SDimitry Andric                                 memory_order s, memory_order f) noexcept;
1470b57cec5SDimitry Andric    bool compare_exchange_weak(integral& expc, integral desr,
1480b57cec5SDimitry Andric                               memory_order m = memory_order_seq_cst) volatile noexcept;
1490b57cec5SDimitry Andric    bool compare_exchange_weak(integral& expc, integral desr,
1500b57cec5SDimitry Andric                               memory_order m = memory_order_seq_cst) noexcept;
1510b57cec5SDimitry Andric    bool compare_exchange_strong(integral& expc, integral desr,
1520b57cec5SDimitry Andric                                memory_order m = memory_order_seq_cst) volatile noexcept;
1530b57cec5SDimitry Andric    bool compare_exchange_strong(integral& expc, integral desr,
1540b57cec5SDimitry Andric                                 memory_order m = memory_order_seq_cst) noexcept;
1550b57cec5SDimitry Andric
1565ffd83dbSDimitry Andric    integral fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
1570b57cec5SDimitry Andric    integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
1585ffd83dbSDimitry Andric    integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
1590b57cec5SDimitry Andric    integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
1605ffd83dbSDimitry Andric    integral fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
1610b57cec5SDimitry Andric    integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
1625ffd83dbSDimitry Andric    integral fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
1630b57cec5SDimitry Andric    integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
1645ffd83dbSDimitry Andric    integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
1650b57cec5SDimitry Andric    integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andric    integral operator++(int) volatile noexcept;
1680b57cec5SDimitry Andric    integral operator++(int) noexcept;
1690b57cec5SDimitry Andric    integral operator--(int) volatile noexcept;
1700b57cec5SDimitry Andric    integral operator--(int) noexcept;
1710b57cec5SDimitry Andric    integral operator++() volatile noexcept;
1720b57cec5SDimitry Andric    integral operator++() noexcept;
1730b57cec5SDimitry Andric    integral operator--() volatile noexcept;
1740b57cec5SDimitry Andric    integral operator--() noexcept;
1750b57cec5SDimitry Andric    integral operator+=(integral op) volatile noexcept;
1760b57cec5SDimitry Andric    integral operator+=(integral op) noexcept;
1770b57cec5SDimitry Andric    integral operator-=(integral op) volatile noexcept;
1780b57cec5SDimitry Andric    integral operator-=(integral op) noexcept;
1790b57cec5SDimitry Andric    integral operator&=(integral op) volatile noexcept;
1800b57cec5SDimitry Andric    integral operator&=(integral op) noexcept;
1810b57cec5SDimitry Andric    integral operator|=(integral op) volatile noexcept;
1820b57cec5SDimitry Andric    integral operator|=(integral op) noexcept;
1830b57cec5SDimitry Andric    integral operator^=(integral op) volatile noexcept;
1840b57cec5SDimitry Andric    integral operator^=(integral op) noexcept;
1855ffd83dbSDimitry Andric
1865ffd83dbSDimitry Andric    void wait(integral, memory_order = memory_order::seq_cst) const volatile noexcept;
1875ffd83dbSDimitry Andric    void wait(integral, memory_order = memory_order::seq_cst) const noexcept;
1885ffd83dbSDimitry Andric    void notify_one() volatile noexcept;
1895ffd83dbSDimitry Andric    void notify_one() noexcept;
1905ffd83dbSDimitry Andric    void notify_all() volatile noexcept;
1915ffd83dbSDimitry Andric    void notify_all() noexcept;
1920b57cec5SDimitry Andric};
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andrictemplate <class T>
1950b57cec5SDimitry Andricstruct atomic<T*>
1960b57cec5SDimitry Andric{
1975ffd83dbSDimitry Andric    using value_type = T*;
198*e8d8bef9SDimitry Andric    using difference_type = ptrdiff_t;
1995ffd83dbSDimitry Andric
2000b57cec5SDimitry Andric    static constexpr bool is_always_lock_free;
2010b57cec5SDimitry Andric    bool is_lock_free() const volatile noexcept;
2020b57cec5SDimitry Andric    bool is_lock_free() const noexcept;
2035ffd83dbSDimitry Andric
2045ffd83dbSDimitry Andric    atomic() noexcept = default;
2055ffd83dbSDimitry Andric    constexpr atomic(T* desr) noexcept;
2065ffd83dbSDimitry Andric    atomic(const atomic&) = delete;
2075ffd83dbSDimitry Andric    atomic& operator=(const atomic&) = delete;
2085ffd83dbSDimitry Andric    atomic& operator=(const atomic&) volatile = delete;
2095ffd83dbSDimitry Andric
2100b57cec5SDimitry Andric    T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
2110b57cec5SDimitry Andric    T* load(memory_order m = memory_order_seq_cst) const noexcept;
2120b57cec5SDimitry Andric    operator T*() const volatile noexcept;
2130b57cec5SDimitry Andric    operator T*() const noexcept;
2145ffd83dbSDimitry Andric    void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
2155ffd83dbSDimitry Andric    void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
2165ffd83dbSDimitry Andric    T* operator=(T*) volatile noexcept;
2175ffd83dbSDimitry Andric    T* operator=(T*) noexcept;
2185ffd83dbSDimitry Andric
2190b57cec5SDimitry Andric    T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
2200b57cec5SDimitry Andric    T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
2210b57cec5SDimitry Andric    bool compare_exchange_weak(T*& expc, T* desr,
2220b57cec5SDimitry Andric                               memory_order s, memory_order f) volatile noexcept;
2230b57cec5SDimitry Andric    bool compare_exchange_weak(T*& expc, T* desr,
2240b57cec5SDimitry Andric                               memory_order s, memory_order f) noexcept;
2250b57cec5SDimitry Andric    bool compare_exchange_strong(T*& expc, T* desr,
2260b57cec5SDimitry Andric                                 memory_order s, memory_order f) volatile noexcept;
2270b57cec5SDimitry Andric    bool compare_exchange_strong(T*& expc, T* desr,
2280b57cec5SDimitry Andric                                 memory_order s, memory_order f) noexcept;
2290b57cec5SDimitry Andric    bool compare_exchange_weak(T*& expc, T* desr,
2300b57cec5SDimitry Andric                               memory_order m = memory_order_seq_cst) volatile noexcept;
2310b57cec5SDimitry Andric    bool compare_exchange_weak(T*& expc, T* desr,
2320b57cec5SDimitry Andric                               memory_order m = memory_order_seq_cst) noexcept;
2330b57cec5SDimitry Andric    bool compare_exchange_strong(T*& expc, T* desr,
2340b57cec5SDimitry Andric                                memory_order m = memory_order_seq_cst) volatile noexcept;
2350b57cec5SDimitry Andric    bool compare_exchange_strong(T*& expc, T* desr,
2360b57cec5SDimitry Andric                                 memory_order m = memory_order_seq_cst) noexcept;
2370b57cec5SDimitry Andric    T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
2380b57cec5SDimitry Andric    T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
2390b57cec5SDimitry Andric    T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
2400b57cec5SDimitry Andric    T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
2410b57cec5SDimitry Andric
2420b57cec5SDimitry Andric    T* operator++(int) volatile noexcept;
2430b57cec5SDimitry Andric    T* operator++(int) noexcept;
2440b57cec5SDimitry Andric    T* operator--(int) volatile noexcept;
2450b57cec5SDimitry Andric    T* operator--(int) noexcept;
2460b57cec5SDimitry Andric    T* operator++() volatile noexcept;
2470b57cec5SDimitry Andric    T* operator++() noexcept;
2480b57cec5SDimitry Andric    T* operator--() volatile noexcept;
2490b57cec5SDimitry Andric    T* operator--() noexcept;
2500b57cec5SDimitry Andric    T* operator+=(ptrdiff_t op) volatile noexcept;
2510b57cec5SDimitry Andric    T* operator+=(ptrdiff_t op) noexcept;
2520b57cec5SDimitry Andric    T* operator-=(ptrdiff_t op) volatile noexcept;
2530b57cec5SDimitry Andric    T* operator-=(ptrdiff_t op) noexcept;
2545ffd83dbSDimitry Andric
2555ffd83dbSDimitry Andric    void wait(T*, memory_order = memory_order::seq_cst) const volatile noexcept;
2565ffd83dbSDimitry Andric    void wait(T*, memory_order = memory_order::seq_cst) const noexcept;
2575ffd83dbSDimitry Andric    void notify_one() volatile noexcept;
2585ffd83dbSDimitry Andric    void notify_one() noexcept;
2595ffd83dbSDimitry Andric    void notify_all() volatile noexcept;
2605ffd83dbSDimitry Andric    void notify_all() noexcept;
2610b57cec5SDimitry Andric};
2620b57cec5SDimitry Andric
2630b57cec5SDimitry Andric
2640b57cec5SDimitry Andrictemplate <class T>
2655ffd83dbSDimitry Andric  bool atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
2660b57cec5SDimitry Andric
2670b57cec5SDimitry Andrictemplate <class T>
2685ffd83dbSDimitry Andric  bool atomic_is_lock_free(const atomic<T>* obj) noexcept;
2690b57cec5SDimitry Andric
2700b57cec5SDimitry Andrictemplate <class T>
2715ffd83dbSDimitry Andric  void atomic_store(volatile atomic<T>* obj, T desr) noexcept;
2720b57cec5SDimitry Andric
2730b57cec5SDimitry Andrictemplate <class T>
2745ffd83dbSDimitry Andric  void atomic_store(atomic<T>* obj, T desr) noexcept;
2750b57cec5SDimitry Andric
2760b57cec5SDimitry Andrictemplate <class T>
2775ffd83dbSDimitry Andric  void atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
2780b57cec5SDimitry Andric
2790b57cec5SDimitry Andrictemplate <class T>
2805ffd83dbSDimitry Andric  void atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
2810b57cec5SDimitry Andric
2820b57cec5SDimitry Andrictemplate <class T>
2835ffd83dbSDimitry Andric  T atomic_load(const volatile atomic<T>* obj) noexcept;
2840b57cec5SDimitry Andric
2850b57cec5SDimitry Andrictemplate <class T>
2865ffd83dbSDimitry Andric  T atomic_load(const atomic<T>* obj) noexcept;
2870b57cec5SDimitry Andric
2880b57cec5SDimitry Andrictemplate <class T>
2895ffd83dbSDimitry Andric  T atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
2900b57cec5SDimitry Andric
2910b57cec5SDimitry Andrictemplate <class T>
2925ffd83dbSDimitry Andric  T atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
2930b57cec5SDimitry Andric
2940b57cec5SDimitry Andrictemplate <class T>
2955ffd83dbSDimitry Andric  T atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
2960b57cec5SDimitry Andric
2970b57cec5SDimitry Andrictemplate <class T>
2985ffd83dbSDimitry Andric  T atomic_exchange(atomic<T>* obj, T desr) noexcept;
2990b57cec5SDimitry Andric
3000b57cec5SDimitry Andrictemplate <class T>
3015ffd83dbSDimitry Andric  T atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
3020b57cec5SDimitry Andric
3030b57cec5SDimitry Andrictemplate <class T>
3045ffd83dbSDimitry Andric  T atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
3050b57cec5SDimitry Andric
3060b57cec5SDimitry Andrictemplate <class T>
3075ffd83dbSDimitry Andric  bool atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
3080b57cec5SDimitry Andric
3090b57cec5SDimitry Andrictemplate <class T>
3105ffd83dbSDimitry Andric  bool atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
3110b57cec5SDimitry Andric
3120b57cec5SDimitry Andrictemplate <class T>
3135ffd83dbSDimitry Andric  bool atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
3140b57cec5SDimitry Andric
3150b57cec5SDimitry Andrictemplate <class T>
3165ffd83dbSDimitry Andric  bool atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
3170b57cec5SDimitry Andric
3180b57cec5SDimitry Andrictemplate <class T>
3195ffd83dbSDimitry Andric  bool atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
3200b57cec5SDimitry Andric                                             T desr,
3210b57cec5SDimitry Andric                                             memory_order s, memory_order f) noexcept;
3220b57cec5SDimitry Andric
3230b57cec5SDimitry Andrictemplate <class T>
3245ffd83dbSDimitry Andric  bool atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
3250b57cec5SDimitry Andric                                             memory_order s, memory_order f) noexcept;
3260b57cec5SDimitry Andric
3270b57cec5SDimitry Andrictemplate <class T>
3285ffd83dbSDimitry Andric  bool atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
3290b57cec5SDimitry Andric                                               T* expc, T desr,
3300b57cec5SDimitry Andric                                               memory_order s, memory_order f) noexcept;
3310b57cec5SDimitry Andric
3320b57cec5SDimitry Andrictemplate <class T>
3335ffd83dbSDimitry Andric  bool atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
3340b57cec5SDimitry Andric                                               T desr,
3350b57cec5SDimitry Andric                                               memory_order s, memory_order f) noexcept;
3360b57cec5SDimitry Andric
3375ffd83dbSDimitry Andrictemplate <class T>
3385ffd83dbSDimitry Andric  void atomic_wait(const volatile atomic<T>* obj, T old) noexcept;
3395ffd83dbSDimitry Andric
3405ffd83dbSDimitry Andrictemplate <class T>
3415ffd83dbSDimitry Andric  void atomic_wait(const atomic<T>* obj, T old) noexcept;
3425ffd83dbSDimitry Andric
3435ffd83dbSDimitry Andrictemplate <class T>
3445ffd83dbSDimitry Andric  void atomic_wait_explicit(const volatile atomic<T>* obj, T old, memory_order m) noexcept;
3455ffd83dbSDimitry Andric
3465ffd83dbSDimitry Andrictemplate <class T>
3475ffd83dbSDimitry Andric  void atomic_wait_explicit(const atomic<T>* obj, T old, memory_order m) noexcept;
3485ffd83dbSDimitry Andric
3495ffd83dbSDimitry Andrictemplate <class T>
3505ffd83dbSDimitry Andric  void atomic_one(volatile atomic<T>* obj) noexcept;
3515ffd83dbSDimitry Andric
3525ffd83dbSDimitry Andrictemplate <class T>
3535ffd83dbSDimitry Andric  void atomic_one(atomic<T>* obj) noexcept;
3545ffd83dbSDimitry Andric
3555ffd83dbSDimitry Andrictemplate <class T>
3565ffd83dbSDimitry Andric  void atomic_all(volatile atomic<T>* obj) noexcept;
3575ffd83dbSDimitry Andric
3585ffd83dbSDimitry Andrictemplate <class T>
3595ffd83dbSDimitry Andric  void atomic_all(atomic<T>* obj) noexcept;
3600b57cec5SDimitry Andric
3610b57cec5SDimitry Andrictemplate <class Integral>
3625ffd83dbSDimitry Andric  Integral atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
3630b57cec5SDimitry Andric
3640b57cec5SDimitry Andrictemplate <class Integral>
3655ffd83dbSDimitry Andric  Integral atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
3665ffd83dbSDimitry Andric
3675ffd83dbSDimitry Andrictemplate <class Integral>
3685ffd83dbSDimitry Andric  Integral atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
3690b57cec5SDimitry Andric                              memory_order m) noexcept;
3700b57cec5SDimitry Andrictemplate <class Integral>
3715ffd83dbSDimitry Andric  Integral atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
3720b57cec5SDimitry Andric                              memory_order m) noexcept;
3730b57cec5SDimitry Andrictemplate <class Integral>
3745ffd83dbSDimitry Andric  Integral atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
3750b57cec5SDimitry Andric
3760b57cec5SDimitry Andrictemplate <class Integral>
3775ffd83dbSDimitry Andric  Integral atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
3780b57cec5SDimitry Andric
3790b57cec5SDimitry Andrictemplate <class Integral>
3805ffd83dbSDimitry Andric  Integral atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
3810b57cec5SDimitry Andric                                     memory_order m) noexcept;
3820b57cec5SDimitry Andric
3830b57cec5SDimitry Andrictemplate <class Integral>
3845ffd83dbSDimitry Andric  Integral atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
3855ffd83dbSDimitry Andric                                     memory_order m) noexcept;
3860b57cec5SDimitry Andric
3870b57cec5SDimitry Andrictemplate <class Integral>
3885ffd83dbSDimitry Andric  Integral atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
3890b57cec5SDimitry Andric
3900b57cec5SDimitry Andrictemplate <class Integral>
3915ffd83dbSDimitry Andric  Integral atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
3920b57cec5SDimitry Andric
3930b57cec5SDimitry Andrictemplate <class Integral>
3945ffd83dbSDimitry Andric  Integral atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
3950b57cec5SDimitry Andric                                     memory_order m) noexcept;
3960b57cec5SDimitry Andric
3970b57cec5SDimitry Andrictemplate <class Integral>
3985ffd83dbSDimitry Andric  Integral atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
3995ffd83dbSDimitry Andric                                     memory_order m) noexcept;
4000b57cec5SDimitry Andric
4010b57cec5SDimitry Andrictemplate <class Integral>
4025ffd83dbSDimitry Andric  Integral atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
4035ffd83dbSDimitry Andric
4040b57cec5SDimitry Andrictemplate <class Integral>
4055ffd83dbSDimitry Andric  Integral atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
4065ffd83dbSDimitry Andric
4075ffd83dbSDimitry Andrictemplate <class Integral>
4085ffd83dbSDimitry Andric  Integral atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
4095ffd83dbSDimitry Andric                             memory_order m) noexcept;
4105ffd83dbSDimitry Andric
4115ffd83dbSDimitry Andrictemplate <class Integral>
4125ffd83dbSDimitry Andric  Integral atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
4135ffd83dbSDimitry Andric                             memory_order m) noexcept;
4145ffd83dbSDimitry Andric
4155ffd83dbSDimitry Andrictemplate <class Integral>
4165ffd83dbSDimitry Andric  Integral atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
4175ffd83dbSDimitry Andric
4185ffd83dbSDimitry Andrictemplate <class Integral>
4195ffd83dbSDimitry Andric  Integral atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
4205ffd83dbSDimitry Andric
4215ffd83dbSDimitry Andrictemplate <class Integral>
4225ffd83dbSDimitry Andric  Integral atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
4235ffd83dbSDimitry Andric                                     memory_order m) noexcept;
4245ffd83dbSDimitry Andric
4255ffd83dbSDimitry Andrictemplate <class Integral>
4265ffd83dbSDimitry Andric  Integral atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
4270b57cec5SDimitry Andric                                     memory_order m) noexcept;
4280b57cec5SDimitry Andric
4290b57cec5SDimitry Andrictemplate <class T>
4305ffd83dbSDimitry Andric  T* atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
4310b57cec5SDimitry Andric
4320b57cec5SDimitry Andrictemplate <class T>
4335ffd83dbSDimitry Andric  T* atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
4340b57cec5SDimitry Andric
4350b57cec5SDimitry Andrictemplate <class T>
4365ffd83dbSDimitry Andric  T* atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
4370b57cec5SDimitry Andric                               memory_order m) noexcept;
4380b57cec5SDimitry Andric
4390b57cec5SDimitry Andrictemplate <class T>
4405ffd83dbSDimitry Andric  T* atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
4410b57cec5SDimitry Andric
4420b57cec5SDimitry Andrictemplate <class T>
4435ffd83dbSDimitry Andric  T* atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
4440b57cec5SDimitry Andric
4450b57cec5SDimitry Andrictemplate <class T>
4465ffd83dbSDimitry Andric  T* atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
4475ffd83dbSDimitry Andric
4485ffd83dbSDimitry Andrictemplate <class T>
4495ffd83dbSDimitry Andric  T* atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
4500b57cec5SDimitry Andric                               memory_order m) noexcept;
4515ffd83dbSDimitry Andric
4520b57cec5SDimitry Andrictemplate <class T>
4535ffd83dbSDimitry Andric  T* atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
4540b57cec5SDimitry Andric
4550b57cec5SDimitry Andric// Atomics for standard typedef types
4560b57cec5SDimitry Andric
4570b57cec5SDimitry Andrictypedef atomic<bool>               atomic_bool;
4580b57cec5SDimitry Andrictypedef atomic<char>               atomic_char;
4590b57cec5SDimitry Andrictypedef atomic<signed char>        atomic_schar;
4600b57cec5SDimitry Andrictypedef atomic<unsigned char>      atomic_uchar;
4610b57cec5SDimitry Andrictypedef atomic<short>              atomic_short;
4620b57cec5SDimitry Andrictypedef atomic<unsigned short>     atomic_ushort;
4630b57cec5SDimitry Andrictypedef atomic<int>                atomic_int;
4640b57cec5SDimitry Andrictypedef atomic<unsigned int>       atomic_uint;
4650b57cec5SDimitry Andrictypedef atomic<long>               atomic_long;
4660b57cec5SDimitry Andrictypedef atomic<unsigned long>      atomic_ulong;
4670b57cec5SDimitry Andrictypedef atomic<long long>          atomic_llong;
4680b57cec5SDimitry Andrictypedef atomic<unsigned long long> atomic_ullong;
469*e8d8bef9SDimitry Andrictypedef atomic<char8_t>            atomic_char8_t; // C++20
4700b57cec5SDimitry Andrictypedef atomic<char16_t>           atomic_char16_t;
4710b57cec5SDimitry Andrictypedef atomic<char32_t>           atomic_char32_t;
4720b57cec5SDimitry Andrictypedef atomic<wchar_t>            atomic_wchar_t;
4730b57cec5SDimitry Andric
4740b57cec5SDimitry Andrictypedef atomic<int_least8_t>   atomic_int_least8_t;
4750b57cec5SDimitry Andrictypedef atomic<uint_least8_t>  atomic_uint_least8_t;
4760b57cec5SDimitry Andrictypedef atomic<int_least16_t>  atomic_int_least16_t;
4770b57cec5SDimitry Andrictypedef atomic<uint_least16_t> atomic_uint_least16_t;
4780b57cec5SDimitry Andrictypedef atomic<int_least32_t>  atomic_int_least32_t;
4790b57cec5SDimitry Andrictypedef atomic<uint_least32_t> atomic_uint_least32_t;
4800b57cec5SDimitry Andrictypedef atomic<int_least64_t>  atomic_int_least64_t;
4810b57cec5SDimitry Andrictypedef atomic<uint_least64_t> atomic_uint_least64_t;
4820b57cec5SDimitry Andric
4830b57cec5SDimitry Andrictypedef atomic<int_fast8_t>   atomic_int_fast8_t;
4840b57cec5SDimitry Andrictypedef atomic<uint_fast8_t>  atomic_uint_fast8_t;
4850b57cec5SDimitry Andrictypedef atomic<int_fast16_t>  atomic_int_fast16_t;
4860b57cec5SDimitry Andrictypedef atomic<uint_fast16_t> atomic_uint_fast16_t;
4870b57cec5SDimitry Andrictypedef atomic<int_fast32_t>  atomic_int_fast32_t;
4880b57cec5SDimitry Andrictypedef atomic<uint_fast32_t> atomic_uint_fast32_t;
4890b57cec5SDimitry Andrictypedef atomic<int_fast64_t>  atomic_int_fast64_t;
4900b57cec5SDimitry Andrictypedef atomic<uint_fast64_t> atomic_uint_fast64_t;
4910b57cec5SDimitry Andric
4920b57cec5SDimitry Andrictypedef atomic<int8_t>   atomic_int8_t;
4930b57cec5SDimitry Andrictypedef atomic<uint8_t>  atomic_uint8_t;
4940b57cec5SDimitry Andrictypedef atomic<int16_t>  atomic_int16_t;
4950b57cec5SDimitry Andrictypedef atomic<uint16_t> atomic_uint16_t;
4960b57cec5SDimitry Andrictypedef atomic<int32_t>  atomic_int32_t;
4970b57cec5SDimitry Andrictypedef atomic<uint32_t> atomic_uint32_t;
4980b57cec5SDimitry Andrictypedef atomic<int64_t>  atomic_int64_t;
4990b57cec5SDimitry Andrictypedef atomic<uint64_t> atomic_uint64_t;
5000b57cec5SDimitry Andric
5010b57cec5SDimitry Andrictypedef atomic<intptr_t>  atomic_intptr_t;
5020b57cec5SDimitry Andrictypedef atomic<uintptr_t> atomic_uintptr_t;
5030b57cec5SDimitry Andrictypedef atomic<size_t>    atomic_size_t;
5040b57cec5SDimitry Andrictypedef atomic<ptrdiff_t> atomic_ptrdiff_t;
5050b57cec5SDimitry Andrictypedef atomic<intmax_t>  atomic_intmax_t;
5060b57cec5SDimitry Andrictypedef atomic<uintmax_t> atomic_uintmax_t;
5070b57cec5SDimitry Andric
5085ffd83dbSDimitry Andric// flag type and operations
5095ffd83dbSDimitry Andric
5105ffd83dbSDimitry Andrictypedef struct atomic_flag
5115ffd83dbSDimitry Andric{
5125ffd83dbSDimitry Andric    atomic_flag() noexcept = default;
5135ffd83dbSDimitry Andric    atomic_flag(const atomic_flag&) = delete;
5145ffd83dbSDimitry Andric    atomic_flag& operator=(const atomic_flag&) = delete;
5155ffd83dbSDimitry Andric    atomic_flag& operator=(const atomic_flag&) volatile = delete;
5165ffd83dbSDimitry Andric
5175ffd83dbSDimitry Andric    bool test(memory_order m = memory_order_seq_cst) volatile noexcept;
5185ffd83dbSDimitry Andric    bool test(memory_order m = memory_order_seq_cst) noexcept;
5195ffd83dbSDimitry Andric    bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
5205ffd83dbSDimitry Andric    bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
5215ffd83dbSDimitry Andric    void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
5225ffd83dbSDimitry Andric    void clear(memory_order m = memory_order_seq_cst) noexcept;
5235ffd83dbSDimitry Andric
5245ffd83dbSDimitry Andric    void wait(bool, memory_order = memory_order::seq_cst) const volatile noexcept;
5255ffd83dbSDimitry Andric    void wait(bool, memory_order = memory_order::seq_cst) const noexcept;
5265ffd83dbSDimitry Andric    void notify_one() volatile noexcept;
5275ffd83dbSDimitry Andric    void notify_one() noexcept;
5285ffd83dbSDimitry Andric    void notify_all() volatile noexcept;
5295ffd83dbSDimitry Andric    void notify_all() noexcept;
5305ffd83dbSDimitry Andric} atomic_flag;
5315ffd83dbSDimitry Andric
5325ffd83dbSDimitry Andricbool atomic_flag_test(volatile atomic_flag* obj) noexcept;
5335ffd83dbSDimitry Andricbool atomic_flag_test(atomic_flag* obj) noexcept;
5345ffd83dbSDimitry Andricbool atomic_flag_test_explicit(volatile atomic_flag* obj,
5355ffd83dbSDimitry Andric                               memory_order m) noexcept;
5365ffd83dbSDimitry Andricbool atomic_flag_test_explicit(atomic_flag* obj, memory_order m) noexcept;
5375ffd83dbSDimitry Andricbool atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
5385ffd83dbSDimitry Andricbool atomic_flag_test_and_set(atomic_flag* obj) noexcept;
5395ffd83dbSDimitry Andricbool atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
5405ffd83dbSDimitry Andric                                       memory_order m) noexcept;
5415ffd83dbSDimitry Andricbool atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
5425ffd83dbSDimitry Andricvoid atomic_flag_clear(volatile atomic_flag* obj) noexcept;
5435ffd83dbSDimitry Andricvoid atomic_flag_clear(atomic_flag* obj) noexcept;
5445ffd83dbSDimitry Andricvoid atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
5455ffd83dbSDimitry Andricvoid atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
5465ffd83dbSDimitry Andric
5475ffd83dbSDimitry Andricvoid atomic_wait(const volatile atomic_flag* obj, T old) noexcept;
5485ffd83dbSDimitry Andricvoid atomic_wait(const atomic_flag* obj, T old) noexcept;
5495ffd83dbSDimitry Andricvoid atomic_wait_explicit(const volatile atomic_flag* obj, T old, memory_order m) noexcept;
5505ffd83dbSDimitry Andricvoid atomic_wait_explicit(const atomic_flag* obj, T old, memory_order m) noexcept;
5515ffd83dbSDimitry Andricvoid atomic_one(volatile atomic_flag* obj) noexcept;
5525ffd83dbSDimitry Andricvoid atomic_one(atomic_flag* obj) noexcept;
5535ffd83dbSDimitry Andricvoid atomic_all(volatile atomic_flag* obj) noexcept;
5545ffd83dbSDimitry Andricvoid atomic_all(atomic_flag* obj) noexcept;
5555ffd83dbSDimitry Andric
5560b57cec5SDimitry Andric// fences
5570b57cec5SDimitry Andric
5580b57cec5SDimitry Andricvoid atomic_thread_fence(memory_order m) noexcept;
5590b57cec5SDimitry Andricvoid atomic_signal_fence(memory_order m) noexcept;
5600b57cec5SDimitry Andric
5615ffd83dbSDimitry Andric// deprecated
5625ffd83dbSDimitry Andric
5635ffd83dbSDimitry Andrictemplate <class T>
5645ffd83dbSDimitry Andric  void atomic_init(volatile atomic<T>* obj, typename atomic<T>::value_type desr) noexcept;
5655ffd83dbSDimitry Andric
5665ffd83dbSDimitry Andrictemplate <class T>
5675ffd83dbSDimitry Andric  void atomic_init(atomic<T>* obj, typename atomic<T>::value_type desr) noexcept;
5685ffd83dbSDimitry Andric
5695ffd83dbSDimitry Andric#define ATOMIC_VAR_INIT(value) see below
5705ffd83dbSDimitry Andric
5715ffd83dbSDimitry Andric#define ATOMIC_FLAG_INIT see below
5725ffd83dbSDimitry Andric
5730b57cec5SDimitry Andric}  // std
5740b57cec5SDimitry Andric
5750b57cec5SDimitry Andric*/
5760b57cec5SDimitry Andric
5770b57cec5SDimitry Andric#include <__config>
578*e8d8bef9SDimitry Andric#include <__availability>
5795ffd83dbSDimitry Andric#include <__threading_support>
5800b57cec5SDimitry Andric#include <cstddef>
5810b57cec5SDimitry Andric#include <cstdint>
5825ffd83dbSDimitry Andric#include <cstring>
5830b57cec5SDimitry Andric#include <type_traits>
5840b57cec5SDimitry Andric#include <version>
5850b57cec5SDimitry Andric
5860b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5870b57cec5SDimitry Andric#pragma GCC system_header
5880b57cec5SDimitry Andric#endif
5890b57cec5SDimitry Andric
5900b57cec5SDimitry Andric#ifdef _LIBCPP_HAS_NO_THREADS
5910b57cec5SDimitry Andric# error <atomic> is not supported on this single threaded system
5920b57cec5SDimitry Andric#endif
5930b57cec5SDimitry Andric#ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER
5940b57cec5SDimitry Andric# error <atomic> is not implemented
5950b57cec5SDimitry Andric#endif
5960b57cec5SDimitry Andric#ifdef kill_dependency
5970b57cec5SDimitry Andric# error C++ standard library is incompatible with <stdatomic.h>
5980b57cec5SDimitry Andric#endif
5990b57cec5SDimitry Andric
6000b57cec5SDimitry Andric#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
6010b57cec5SDimitry Andric  _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \
6020b57cec5SDimitry Andric                           __m == memory_order_acquire || \
6030b57cec5SDimitry Andric                           __m == memory_order_acq_rel,   \
6040b57cec5SDimitry Andric                        "memory order argument to atomic operation is invalid")
6050b57cec5SDimitry Andric
6060b57cec5SDimitry Andric#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
6070b57cec5SDimitry Andric  _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \
6080b57cec5SDimitry Andric                           __m == memory_order_acq_rel,   \
6090b57cec5SDimitry Andric                        "memory order argument to atomic operation is invalid")
6100b57cec5SDimitry Andric
6110b57cec5SDimitry Andric#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
6120b57cec5SDimitry Andric  _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \
6130b57cec5SDimitry Andric                           __f == memory_order_acq_rel,   \
6140b57cec5SDimitry Andric                        "memory order argument to atomic operation is invalid")
6150b57cec5SDimitry Andric
6160b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
6170b57cec5SDimitry Andric
6180b57cec5SDimitry Andric// Figure out what the underlying type for `memory_order` would be if it were
6190b57cec5SDimitry Andric// declared as an unscoped enum (accounting for -fshort-enums). Use this result
6200b57cec5SDimitry Andric// to pin the underlying type in C++20.
6210b57cec5SDimitry Andricenum __legacy_memory_order {
6220b57cec5SDimitry Andric    __mo_relaxed,
6230b57cec5SDimitry Andric    __mo_consume,
6240b57cec5SDimitry Andric    __mo_acquire,
6250b57cec5SDimitry Andric    __mo_release,
6260b57cec5SDimitry Andric    __mo_acq_rel,
6270b57cec5SDimitry Andric    __mo_seq_cst
6280b57cec5SDimitry Andric};
6290b57cec5SDimitry Andric
6300b57cec5SDimitry Andrictypedef underlying_type<__legacy_memory_order>::type __memory_order_underlying_t;
6310b57cec5SDimitry Andric
6320b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
6330b57cec5SDimitry Andric
6340b57cec5SDimitry Andricenum class memory_order : __memory_order_underlying_t {
6350b57cec5SDimitry Andric  relaxed = __mo_relaxed,
6360b57cec5SDimitry Andric  consume = __mo_consume,
6370b57cec5SDimitry Andric  acquire = __mo_acquire,
6380b57cec5SDimitry Andric  release = __mo_release,
6390b57cec5SDimitry Andric  acq_rel = __mo_acq_rel,
6400b57cec5SDimitry Andric  seq_cst = __mo_seq_cst
6410b57cec5SDimitry Andric};
6420b57cec5SDimitry Andric
6430b57cec5SDimitry Andricinline constexpr auto memory_order_relaxed = memory_order::relaxed;
6440b57cec5SDimitry Andricinline constexpr auto memory_order_consume = memory_order::consume;
6450b57cec5SDimitry Andricinline constexpr auto memory_order_acquire = memory_order::acquire;
6460b57cec5SDimitry Andricinline constexpr auto memory_order_release = memory_order::release;
6470b57cec5SDimitry Andricinline constexpr auto memory_order_acq_rel = memory_order::acq_rel;
6480b57cec5SDimitry Andricinline constexpr auto memory_order_seq_cst = memory_order::seq_cst;
6490b57cec5SDimitry Andric
6500b57cec5SDimitry Andric#else
6510b57cec5SDimitry Andric
6520b57cec5SDimitry Andrictypedef enum memory_order {
6530b57cec5SDimitry Andric  memory_order_relaxed = __mo_relaxed,
6540b57cec5SDimitry Andric  memory_order_consume = __mo_consume,
6550b57cec5SDimitry Andric  memory_order_acquire = __mo_acquire,
6560b57cec5SDimitry Andric  memory_order_release = __mo_release,
6570b57cec5SDimitry Andric  memory_order_acq_rel = __mo_acq_rel,
6580b57cec5SDimitry Andric  memory_order_seq_cst = __mo_seq_cst,
6590b57cec5SDimitry Andric} memory_order;
6600b57cec5SDimitry Andric
6610b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 17
6620b57cec5SDimitry Andric
6635ffd83dbSDimitry Andrictemplate <typename _Tp> _LIBCPP_INLINE_VISIBILITY
6645ffd83dbSDimitry Andricbool __cxx_nonatomic_compare_equal(_Tp const& __lhs, _Tp const& __rhs) {
665*e8d8bef9SDimitry Andric    return _VSTD::memcmp(&__lhs, &__rhs, sizeof(_Tp)) == 0;
6665ffd83dbSDimitry Andric}
6675ffd83dbSDimitry Andric
6680b57cec5SDimitry Andricstatic_assert((is_same<underlying_type<memory_order>::type, __memory_order_underlying_t>::value),
6690b57cec5SDimitry Andric  "unexpected underlying type for std::memory_order");
6700b57cec5SDimitry Andric
6710b57cec5SDimitry Andric#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) || \
6720b57cec5SDimitry Andric	defined(_LIBCPP_ATOMIC_ONLY_USE_BUILTINS)
6730b57cec5SDimitry Andric
6740b57cec5SDimitry Andric// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
6750b57cec5SDimitry Andric// the default operator= in an object is not volatile, a byte-by-byte copy
6760b57cec5SDimitry Andric// is required.
6770b57cec5SDimitry Andrictemplate <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY
6780b57cec5SDimitry Andrictypename enable_if<is_assignable<_Tp&, _Tv>::value>::type
6790b57cec5SDimitry Andric__cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) {
6800b57cec5SDimitry Andric  __a_value = __val;
6810b57cec5SDimitry Andric}
6820b57cec5SDimitry Andrictemplate <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY
6830b57cec5SDimitry Andrictypename enable_if<is_assignable<_Tp&, _Tv>::value>::type
6840b57cec5SDimitry Andric__cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) {
6850b57cec5SDimitry Andric  volatile char* __to = reinterpret_cast<volatile char*>(&__a_value);
6860b57cec5SDimitry Andric  volatile char* __end = __to + sizeof(_Tp);
6870b57cec5SDimitry Andric  volatile const char* __from = reinterpret_cast<volatile const char*>(&__val);
6880b57cec5SDimitry Andric  while (__to != __end)
6890b57cec5SDimitry Andric    *__to++ = *__from++;
6900b57cec5SDimitry Andric}
6910b57cec5SDimitry Andric
6920b57cec5SDimitry Andric#endif
6930b57cec5SDimitry Andric
6940b57cec5SDimitry Andric#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
6950b57cec5SDimitry Andric
6960b57cec5SDimitry Andrictemplate <typename _Tp>
6970b57cec5SDimitry Andricstruct __cxx_atomic_base_impl {
6980b57cec5SDimitry Andric
6990b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY
7000b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7010b57cec5SDimitry Andric    __cxx_atomic_base_impl() _NOEXCEPT = default;
7020b57cec5SDimitry Andric#else
7030b57cec5SDimitry Andric    __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {}
7040b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
7050b57cec5SDimitry Andric  _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT
7060b57cec5SDimitry Andric    : __a_value(value) {}
7070b57cec5SDimitry Andric  _Tp __a_value;
7080b57cec5SDimitry Andric};
7090b57cec5SDimitry Andric
7100b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
7110b57cec5SDimitry Andric  // Avoid switch statement to make this a constexpr.
7120b57cec5SDimitry Andric  return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
7130b57cec5SDimitry Andric         (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
7140b57cec5SDimitry Andric          (__order == memory_order_release ? __ATOMIC_RELEASE:
7150b57cec5SDimitry Andric           (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
7160b57cec5SDimitry Andric            (__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
7170b57cec5SDimitry Andric              __ATOMIC_CONSUME))));
7180b57cec5SDimitry Andric}
7190b57cec5SDimitry Andric
7200b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
7210b57cec5SDimitry Andric  // Avoid switch statement to make this a constexpr.
7220b57cec5SDimitry Andric  return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
7230b57cec5SDimitry Andric         (__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
7240b57cec5SDimitry Andric          (__order == memory_order_release ? __ATOMIC_RELAXED:
7250b57cec5SDimitry Andric           (__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
7260b57cec5SDimitry Andric            (__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE:
7270b57cec5SDimitry Andric              __ATOMIC_CONSUME))));
7280b57cec5SDimitry Andric}
7290b57cec5SDimitry Andric
7300b57cec5SDimitry Andrictemplate <typename _Tp>
7310b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
7320b57cec5SDimitry Andricvoid __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a,  _Tp __val) {
7330b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__a->__a_value, __val);
7340b57cec5SDimitry Andric}
7350b57cec5SDimitry Andric
7360b57cec5SDimitry Andrictemplate <typename _Tp>
7370b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
7380b57cec5SDimitry Andricvoid __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a,  _Tp __val) {
7390b57cec5SDimitry Andric  __a->__a_value = __val;
7400b57cec5SDimitry Andric}
7410b57cec5SDimitry Andric
7420b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY inline
7430b57cec5SDimitry Andricvoid __cxx_atomic_thread_fence(memory_order __order) {
7440b57cec5SDimitry Andric  __atomic_thread_fence(__to_gcc_order(__order));
7450b57cec5SDimitry Andric}
7460b57cec5SDimitry Andric
7470b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY inline
7480b57cec5SDimitry Andricvoid __cxx_atomic_signal_fence(memory_order __order) {
7490b57cec5SDimitry Andric  __atomic_signal_fence(__to_gcc_order(__order));
7500b57cec5SDimitry Andric}
7510b57cec5SDimitry Andric
7520b57cec5SDimitry Andrictemplate <typename _Tp>
7530b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
7540b57cec5SDimitry Andricvoid __cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a,  _Tp __val,
7550b57cec5SDimitry Andric                        memory_order __order) {
7560b57cec5SDimitry Andric  __atomic_store(&__a->__a_value, &__val,
7570b57cec5SDimitry Andric                 __to_gcc_order(__order));
7580b57cec5SDimitry Andric}
7590b57cec5SDimitry Andric
7600b57cec5SDimitry Andrictemplate <typename _Tp>
7610b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
7620b57cec5SDimitry Andricvoid __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a,  _Tp __val,
7630b57cec5SDimitry Andric                        memory_order __order) {
7640b57cec5SDimitry Andric  __atomic_store(&__a->__a_value, &__val,
7650b57cec5SDimitry Andric                 __to_gcc_order(__order));
7660b57cec5SDimitry Andric}
7670b57cec5SDimitry Andric
7680b57cec5SDimitry Andrictemplate <typename _Tp>
7690b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
7700b57cec5SDimitry Andric_Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a,
7710b57cec5SDimitry Andric                      memory_order __order) {
7720b57cec5SDimitry Andric  _Tp __ret;
7730b57cec5SDimitry Andric  __atomic_load(&__a->__a_value, &__ret,
7740b57cec5SDimitry Andric                __to_gcc_order(__order));
7750b57cec5SDimitry Andric  return __ret;
7760b57cec5SDimitry Andric}
7770b57cec5SDimitry Andric
7780b57cec5SDimitry Andrictemplate <typename _Tp>
7790b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
7800b57cec5SDimitry Andric_Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) {
7810b57cec5SDimitry Andric  _Tp __ret;
7820b57cec5SDimitry Andric  __atomic_load(&__a->__a_value, &__ret,
7830b57cec5SDimitry Andric                __to_gcc_order(__order));
7840b57cec5SDimitry Andric  return __ret;
7850b57cec5SDimitry Andric}
7860b57cec5SDimitry Andric
7870b57cec5SDimitry Andrictemplate <typename _Tp>
7880b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
7890b57cec5SDimitry Andric_Tp __cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a,
7900b57cec5SDimitry Andric                          _Tp __value, memory_order __order) {
7910b57cec5SDimitry Andric  _Tp __ret;
7920b57cec5SDimitry Andric  __atomic_exchange(&__a->__a_value, &__value, &__ret,
7930b57cec5SDimitry Andric                    __to_gcc_order(__order));
7940b57cec5SDimitry Andric  return __ret;
7950b57cec5SDimitry Andric}
7960b57cec5SDimitry Andric
7970b57cec5SDimitry Andrictemplate <typename _Tp>
7980b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
7990b57cec5SDimitry Andric_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value,
8000b57cec5SDimitry Andric                          memory_order __order) {
8010b57cec5SDimitry Andric  _Tp __ret;
8020b57cec5SDimitry Andric  __atomic_exchange(&__a->__a_value, &__value, &__ret,
8030b57cec5SDimitry Andric                    __to_gcc_order(__order));
8040b57cec5SDimitry Andric  return __ret;
8050b57cec5SDimitry Andric}
8060b57cec5SDimitry Andric
8070b57cec5SDimitry Andrictemplate <typename _Tp>
8080b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
8090b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_strong(
8100b57cec5SDimitry Andric    volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value,
8110b57cec5SDimitry Andric    memory_order __success, memory_order __failure) {
8120b57cec5SDimitry Andric  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
8130b57cec5SDimitry Andric                                   false,
8140b57cec5SDimitry Andric                                   __to_gcc_order(__success),
8150b57cec5SDimitry Andric                                   __to_gcc_failure_order(__failure));
8160b57cec5SDimitry Andric}
8170b57cec5SDimitry Andric
8180b57cec5SDimitry Andrictemplate <typename _Tp>
8190b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
8200b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_strong(
8210b57cec5SDimitry Andric    __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success,
8220b57cec5SDimitry Andric    memory_order __failure) {
8230b57cec5SDimitry Andric  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
8240b57cec5SDimitry Andric                                   false,
8250b57cec5SDimitry Andric                                   __to_gcc_order(__success),
8260b57cec5SDimitry Andric                                   __to_gcc_failure_order(__failure));
8270b57cec5SDimitry Andric}
8280b57cec5SDimitry Andric
8290b57cec5SDimitry Andrictemplate <typename _Tp>
8300b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
8310b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_weak(
8320b57cec5SDimitry Andric    volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value,
8330b57cec5SDimitry Andric    memory_order __success, memory_order __failure) {
8340b57cec5SDimitry Andric  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
8350b57cec5SDimitry Andric                                   true,
8360b57cec5SDimitry Andric                                   __to_gcc_order(__success),
8370b57cec5SDimitry Andric                                   __to_gcc_failure_order(__failure));
8380b57cec5SDimitry Andric}
8390b57cec5SDimitry Andric
8400b57cec5SDimitry Andrictemplate <typename _Tp>
8410b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
8420b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_weak(
8430b57cec5SDimitry Andric    __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success,
8440b57cec5SDimitry Andric    memory_order __failure) {
8450b57cec5SDimitry Andric  return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
8460b57cec5SDimitry Andric                                   true,
8470b57cec5SDimitry Andric                                   __to_gcc_order(__success),
8480b57cec5SDimitry Andric                                   __to_gcc_failure_order(__failure));
8490b57cec5SDimitry Andric}
8500b57cec5SDimitry Andric
8510b57cec5SDimitry Andrictemplate <typename _Tp>
8520b57cec5SDimitry Andricstruct __skip_amt { enum {value = 1}; };
8530b57cec5SDimitry Andric
8540b57cec5SDimitry Andrictemplate <typename _Tp>
8550b57cec5SDimitry Andricstruct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
8560b57cec5SDimitry Andric
8570b57cec5SDimitry Andric// FIXME: Haven't figured out what the spec says about using arrays with
8580b57cec5SDimitry Andric// atomic_fetch_add. Force a failure rather than creating bad behavior.
8590b57cec5SDimitry Andrictemplate <typename _Tp>
8600b57cec5SDimitry Andricstruct __skip_amt<_Tp[]> { };
8610b57cec5SDimitry Andrictemplate <typename _Tp, int n>
8620b57cec5SDimitry Andricstruct __skip_amt<_Tp[n]> { };
8630b57cec5SDimitry Andric
8640b57cec5SDimitry Andrictemplate <typename _Tp, typename _Td>
8650b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
8660b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a,
8670b57cec5SDimitry Andric                           _Td __delta, memory_order __order) {
8680b57cec5SDimitry Andric  return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
8690b57cec5SDimitry Andric                            __to_gcc_order(__order));
8700b57cec5SDimitry Andric}
8710b57cec5SDimitry Andric
8720b57cec5SDimitry Andrictemplate <typename _Tp, typename _Td>
8730b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
8740b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta,
8750b57cec5SDimitry Andric                           memory_order __order) {
8760b57cec5SDimitry Andric  return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
8770b57cec5SDimitry Andric                            __to_gcc_order(__order));
8780b57cec5SDimitry Andric}
8790b57cec5SDimitry Andric
8800b57cec5SDimitry Andrictemplate <typename _Tp, typename _Td>
8810b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
8820b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a,
8830b57cec5SDimitry Andric                           _Td __delta, memory_order __order) {
8840b57cec5SDimitry Andric  return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
8850b57cec5SDimitry Andric                            __to_gcc_order(__order));
8860b57cec5SDimitry Andric}
8870b57cec5SDimitry Andric
8880b57cec5SDimitry Andrictemplate <typename _Tp, typename _Td>
8890b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
8900b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta,
8910b57cec5SDimitry Andric                           memory_order __order) {
8920b57cec5SDimitry Andric  return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
8930b57cec5SDimitry Andric                            __to_gcc_order(__order));
8940b57cec5SDimitry Andric}
8950b57cec5SDimitry Andric
8960b57cec5SDimitry Andrictemplate <typename _Tp>
8970b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
8980b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a,
8990b57cec5SDimitry Andric                           _Tp __pattern, memory_order __order) {
9000b57cec5SDimitry Andric  return __atomic_fetch_and(&__a->__a_value, __pattern,
9010b57cec5SDimitry Andric                            __to_gcc_order(__order));
9020b57cec5SDimitry Andric}
9030b57cec5SDimitry Andric
9040b57cec5SDimitry Andrictemplate <typename _Tp>
9050b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
9060b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a,
9070b57cec5SDimitry Andric                           _Tp __pattern, memory_order __order) {
9080b57cec5SDimitry Andric  return __atomic_fetch_and(&__a->__a_value, __pattern,
9090b57cec5SDimitry Andric                            __to_gcc_order(__order));
9100b57cec5SDimitry Andric}
9110b57cec5SDimitry Andric
9120b57cec5SDimitry Andrictemplate <typename _Tp>
9130b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
9140b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a,
9150b57cec5SDimitry Andric                          _Tp __pattern, memory_order __order) {
9160b57cec5SDimitry Andric  return __atomic_fetch_or(&__a->__a_value, __pattern,
9170b57cec5SDimitry Andric                           __to_gcc_order(__order));
9180b57cec5SDimitry Andric}
9190b57cec5SDimitry Andric
9200b57cec5SDimitry Andrictemplate <typename _Tp>
9210b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
9220b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern,
9230b57cec5SDimitry Andric                          memory_order __order) {
9240b57cec5SDimitry Andric  return __atomic_fetch_or(&__a->__a_value, __pattern,
9250b57cec5SDimitry Andric                           __to_gcc_order(__order));
9260b57cec5SDimitry Andric}
9270b57cec5SDimitry Andric
9280b57cec5SDimitry Andrictemplate <typename _Tp>
9290b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
9300b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a,
9310b57cec5SDimitry Andric                           _Tp __pattern, memory_order __order) {
9320b57cec5SDimitry Andric  return __atomic_fetch_xor(&__a->__a_value, __pattern,
9330b57cec5SDimitry Andric                            __to_gcc_order(__order));
9340b57cec5SDimitry Andric}
9350b57cec5SDimitry Andric
9360b57cec5SDimitry Andrictemplate <typename _Tp>
9370b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
9380b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern,
9390b57cec5SDimitry Andric                           memory_order __order) {
9400b57cec5SDimitry Andric  return __atomic_fetch_xor(&__a->__a_value, __pattern,
9410b57cec5SDimitry Andric                            __to_gcc_order(__order));
9420b57cec5SDimitry Andric}
9430b57cec5SDimitry Andric
9440b57cec5SDimitry Andric#define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0)
9450b57cec5SDimitry Andric
9460b57cec5SDimitry Andric#elif defined(_LIBCPP_HAS_C_ATOMIC_IMP)
9470b57cec5SDimitry Andric
9480b57cec5SDimitry Andrictemplate <typename _Tp>
9490b57cec5SDimitry Andricstruct __cxx_atomic_base_impl {
9500b57cec5SDimitry Andric
9510b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY
9520b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
9530b57cec5SDimitry Andric    __cxx_atomic_base_impl() _NOEXCEPT = default;
9540b57cec5SDimitry Andric#else
9550b57cec5SDimitry Andric    __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {}
9560b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
9570b57cec5SDimitry Andric  _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT
9580b57cec5SDimitry Andric    : __a_value(value) {}
959e40139ffSDimitry Andric  _LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value;
9600b57cec5SDimitry Andric};
9610b57cec5SDimitry Andric
9620b57cec5SDimitry Andric#define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s)
9630b57cec5SDimitry Andric
9640b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY inline
9650b57cec5SDimitry Andricvoid __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT {
9660b57cec5SDimitry Andric    __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order));
9670b57cec5SDimitry Andric}
9680b57cec5SDimitry Andric
9690b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY inline
9700b57cec5SDimitry Andricvoid __cxx_atomic_signal_fence(memory_order __order) _NOEXCEPT {
9710b57cec5SDimitry Andric    __c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order));
9720b57cec5SDimitry Andric}
9730b57cec5SDimitry Andric
9740b57cec5SDimitry Andrictemplate<class _Tp>
9750b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
9760b57cec5SDimitry Andricvoid __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) _NOEXCEPT {
9770b57cec5SDimitry Andric    __c11_atomic_init(&__a->__a_value, __val);
9780b57cec5SDimitry Andric}
9790b57cec5SDimitry Andrictemplate<class _Tp>
9800b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
9810b57cec5SDimitry Andricvoid __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val) _NOEXCEPT {
9820b57cec5SDimitry Andric    __c11_atomic_init(&__a->__a_value, __val);
9830b57cec5SDimitry Andric}
9840b57cec5SDimitry Andric
9850b57cec5SDimitry Andrictemplate<class _Tp>
9860b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
9870b57cec5SDimitry Andricvoid __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) _NOEXCEPT {
9880b57cec5SDimitry Andric    __c11_atomic_store(&__a->__a_value, __val, static_cast<__memory_order_underlying_t>(__order));
9890b57cec5SDimitry Andric}
9900b57cec5SDimitry Andrictemplate<class _Tp>
9910b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
9920b57cec5SDimitry Andricvoid __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val, memory_order __order) _NOEXCEPT {
9930b57cec5SDimitry Andric    __c11_atomic_store(&__a->__a_value, __val, static_cast<__memory_order_underlying_t>(__order));
9940b57cec5SDimitry Andric}
9950b57cec5SDimitry Andric
9960b57cec5SDimitry Andrictemplate<class _Tp>
9970b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
9980b57cec5SDimitry Andric_Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) _NOEXCEPT {
9990b57cec5SDimitry Andric    using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*;
10000b57cec5SDimitry Andric    return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), static_cast<__memory_order_underlying_t>(__order));
10010b57cec5SDimitry Andric}
10020b57cec5SDimitry Andrictemplate<class _Tp>
10030b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10040b57cec5SDimitry Andric_Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) _NOEXCEPT {
10050b57cec5SDimitry Andric    using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*;
10060b57cec5SDimitry Andric    return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), static_cast<__memory_order_underlying_t>(__order));
10070b57cec5SDimitry Andric}
10080b57cec5SDimitry Andric
10090b57cec5SDimitry Andrictemplate<class _Tp>
10100b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10110b57cec5SDimitry Andric_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) _NOEXCEPT {
10120b57cec5SDimitry Andric    return __c11_atomic_exchange(&__a->__a_value, __value, static_cast<__memory_order_underlying_t>(__order));
10130b57cec5SDimitry Andric}
10140b57cec5SDimitry Andrictemplate<class _Tp>
10150b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10160b57cec5SDimitry Andric_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> * __a, _Tp __value, memory_order __order) _NOEXCEPT {
10170b57cec5SDimitry Andric    return __c11_atomic_exchange(&__a->__a_value, __value, static_cast<__memory_order_underlying_t>(__order));
10180b57cec5SDimitry Andric}
10190b57cec5SDimitry Andric
10200b57cec5SDimitry Andrictemplate<class _Tp>
10210b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10220b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
10230b57cec5SDimitry Andric    return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
10240b57cec5SDimitry Andric}
10250b57cec5SDimitry Andrictemplate<class _Tp>
10260b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10270b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
10280b57cec5SDimitry Andric    return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
10290b57cec5SDimitry Andric}
10300b57cec5SDimitry Andric
10310b57cec5SDimitry Andrictemplate<class _Tp>
10320b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10330b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
10340b57cec5SDimitry Andric    return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
10350b57cec5SDimitry Andric}
10360b57cec5SDimitry Andrictemplate<class _Tp>
10370b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10380b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
10390b57cec5SDimitry Andric    return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value,  static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
10400b57cec5SDimitry Andric}
10410b57cec5SDimitry Andric
10420b57cec5SDimitry Andrictemplate<class _Tp>
10430b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10440b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
10450b57cec5SDimitry Andric    return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
10460b57cec5SDimitry Andric}
10470b57cec5SDimitry Andrictemplate<class _Tp>
10480b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10490b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) _NOEXCEPT {
10500b57cec5SDimitry Andric    return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
10510b57cec5SDimitry Andric}
10520b57cec5SDimitry Andric
10530b57cec5SDimitry Andrictemplate<class _Tp>
10540b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10550b57cec5SDimitry Andric_Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
10560b57cec5SDimitry Andric    return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
10570b57cec5SDimitry Andric}
10580b57cec5SDimitry Andrictemplate<class _Tp>
10590b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10600b57cec5SDimitry Andric_Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
10610b57cec5SDimitry Andric    return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
10620b57cec5SDimitry Andric}
10630b57cec5SDimitry Andric
10640b57cec5SDimitry Andrictemplate<class _Tp>
10650b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10660b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
10670b57cec5SDimitry Andric    return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
10680b57cec5SDimitry Andric}
10690b57cec5SDimitry Andrictemplate<class _Tp>
10700b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10710b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) _NOEXCEPT {
10720b57cec5SDimitry Andric    return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
10730b57cec5SDimitry Andric}
10740b57cec5SDimitry Andrictemplate<class _Tp>
10750b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10760b57cec5SDimitry Andric_Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
10770b57cec5SDimitry Andric    return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
10780b57cec5SDimitry Andric}
10790b57cec5SDimitry Andrictemplate<class _Tp>
10800b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10810b57cec5SDimitry Andric_Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
10820b57cec5SDimitry Andric    return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
10830b57cec5SDimitry Andric}
10840b57cec5SDimitry Andric
10850b57cec5SDimitry Andrictemplate<class _Tp>
10860b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10870b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
10880b57cec5SDimitry Andric    return __c11_atomic_fetch_and(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
10890b57cec5SDimitry Andric}
10900b57cec5SDimitry Andrictemplate<class _Tp>
10910b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10920b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
10930b57cec5SDimitry Andric    return __c11_atomic_fetch_and(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
10940b57cec5SDimitry Andric}
10950b57cec5SDimitry Andric
10960b57cec5SDimitry Andrictemplate<class _Tp>
10970b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
10980b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
10990b57cec5SDimitry Andric    return __c11_atomic_fetch_or(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
11000b57cec5SDimitry Andric}
11010b57cec5SDimitry Andrictemplate<class _Tp>
11020b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
11030b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
11040b57cec5SDimitry Andric    return __c11_atomic_fetch_or(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
11050b57cec5SDimitry Andric}
11060b57cec5SDimitry Andric
11070b57cec5SDimitry Andrictemplate<class _Tp>
11080b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
11090b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
11100b57cec5SDimitry Andric    return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
11110b57cec5SDimitry Andric}
11120b57cec5SDimitry Andrictemplate<class _Tp>
11130b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
11140b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
11150b57cec5SDimitry Andric    return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
11160b57cec5SDimitry Andric}
11170b57cec5SDimitry Andric
11180b57cec5SDimitry Andric#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP, _LIBCPP_HAS_C_ATOMIC_IMP
11190b57cec5SDimitry Andric
11200b57cec5SDimitry Andrictemplate <class _Tp>
11210b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
11220b57cec5SDimitry Andric_Tp kill_dependency(_Tp __y) _NOEXCEPT
11230b57cec5SDimitry Andric{
11240b57cec5SDimitry Andric    return __y;
11250b57cec5SDimitry Andric}
11260b57cec5SDimitry Andric
11270b57cec5SDimitry Andric#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)
11280b57cec5SDimitry Andric# define ATOMIC_BOOL_LOCK_FREE      __CLANG_ATOMIC_BOOL_LOCK_FREE
11290b57cec5SDimitry Andric# define ATOMIC_CHAR_LOCK_FREE      __CLANG_ATOMIC_CHAR_LOCK_FREE
1130*e8d8bef9SDimitry Andric#ifndef _LIBCPP_NO_HAS_CHAR8_T
1131*e8d8bef9SDimitry Andric# define ATOMIC_CHAR8_T_LOCK_FREE   __CLANG_ATOMIC_CHAR8_T_LOCK_FREE
1132*e8d8bef9SDimitry Andric#endif
11330b57cec5SDimitry Andric# define ATOMIC_CHAR16_T_LOCK_FREE  __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
11340b57cec5SDimitry Andric# define ATOMIC_CHAR32_T_LOCK_FREE  __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
11350b57cec5SDimitry Andric# define ATOMIC_WCHAR_T_LOCK_FREE   __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
11360b57cec5SDimitry Andric# define ATOMIC_SHORT_LOCK_FREE     __CLANG_ATOMIC_SHORT_LOCK_FREE
11370b57cec5SDimitry Andric# define ATOMIC_INT_LOCK_FREE       __CLANG_ATOMIC_INT_LOCK_FREE
11380b57cec5SDimitry Andric# define ATOMIC_LONG_LOCK_FREE      __CLANG_ATOMIC_LONG_LOCK_FREE
11390b57cec5SDimitry Andric# define ATOMIC_LLONG_LOCK_FREE     __CLANG_ATOMIC_LLONG_LOCK_FREE
11400b57cec5SDimitry Andric# define ATOMIC_POINTER_LOCK_FREE   __CLANG_ATOMIC_POINTER_LOCK_FREE
11410b57cec5SDimitry Andric#elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE)
11420b57cec5SDimitry Andric# define ATOMIC_BOOL_LOCK_FREE      __GCC_ATOMIC_BOOL_LOCK_FREE
11430b57cec5SDimitry Andric# define ATOMIC_CHAR_LOCK_FREE      __GCC_ATOMIC_CHAR_LOCK_FREE
1144*e8d8bef9SDimitry Andric#ifndef _LIBCPP_NO_HAS_CHAR8_T
1145*e8d8bef9SDimitry Andric# define ATOMIC_CHAR8_T_LOCK_FREE   __GCC_ATOMIC_CHAR8_T_LOCK_FREE
1146*e8d8bef9SDimitry Andric#endif
11470b57cec5SDimitry Andric# define ATOMIC_CHAR16_T_LOCK_FREE  __GCC_ATOMIC_CHAR16_T_LOCK_FREE
11480b57cec5SDimitry Andric# define ATOMIC_CHAR32_T_LOCK_FREE  __GCC_ATOMIC_CHAR32_T_LOCK_FREE
11490b57cec5SDimitry Andric# define ATOMIC_WCHAR_T_LOCK_FREE   __GCC_ATOMIC_WCHAR_T_LOCK_FREE
11500b57cec5SDimitry Andric# define ATOMIC_SHORT_LOCK_FREE     __GCC_ATOMIC_SHORT_LOCK_FREE
11510b57cec5SDimitry Andric# define ATOMIC_INT_LOCK_FREE       __GCC_ATOMIC_INT_LOCK_FREE
11520b57cec5SDimitry Andric# define ATOMIC_LONG_LOCK_FREE      __GCC_ATOMIC_LONG_LOCK_FREE
11530b57cec5SDimitry Andric# define ATOMIC_LLONG_LOCK_FREE     __GCC_ATOMIC_LLONG_LOCK_FREE
11540b57cec5SDimitry Andric# define ATOMIC_POINTER_LOCK_FREE   __GCC_ATOMIC_POINTER_LOCK_FREE
11550b57cec5SDimitry Andric#endif
11560b57cec5SDimitry Andric
11570b57cec5SDimitry Andric#ifdef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
11580b57cec5SDimitry Andric
11590b57cec5SDimitry Andrictemplate<typename _Tp>
11600b57cec5SDimitry Andricstruct __cxx_atomic_lock_impl {
11610b57cec5SDimitry Andric
11620b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY
11630b57cec5SDimitry Andric  __cxx_atomic_lock_impl() _NOEXCEPT
11640b57cec5SDimitry Andric    : __a_value(), __a_lock(0) {}
11650b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit
11660b57cec5SDimitry Andric  __cxx_atomic_lock_impl(_Tp value) _NOEXCEPT
11670b57cec5SDimitry Andric    : __a_value(value), __a_lock(0) {}
11680b57cec5SDimitry Andric
11690b57cec5SDimitry Andric  _Tp __a_value;
11700b57cec5SDimitry Andric  mutable __cxx_atomic_base_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_lock;
11710b57cec5SDimitry Andric
11720b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY void __lock() const volatile {
11730b57cec5SDimitry Andric    while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire))
11740b57cec5SDimitry Andric        /*spin*/;
11750b57cec5SDimitry Andric  }
11760b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY void __lock() const {
11770b57cec5SDimitry Andric    while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire))
11780b57cec5SDimitry Andric        /*spin*/;
11790b57cec5SDimitry Andric  }
11800b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY void __unlock() const volatile {
11810b57cec5SDimitry Andric    __cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release);
11820b57cec5SDimitry Andric  }
11830b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY void __unlock() const {
11840b57cec5SDimitry Andric    __cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release);
11850b57cec5SDimitry Andric  }
11860b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY _Tp __read() const volatile {
11870b57cec5SDimitry Andric    __lock();
11880b57cec5SDimitry Andric    _Tp __old;
11890b57cec5SDimitry Andric    __cxx_atomic_assign_volatile(__old, __a_value);
11900b57cec5SDimitry Andric    __unlock();
11910b57cec5SDimitry Andric    return __old;
11920b57cec5SDimitry Andric  }
11930b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY _Tp __read() const {
11940b57cec5SDimitry Andric    __lock();
11950b57cec5SDimitry Andric    _Tp __old = __a_value;
11960b57cec5SDimitry Andric    __unlock();
11970b57cec5SDimitry Andric    return __old;
11980b57cec5SDimitry Andric  }
11990b57cec5SDimitry Andric};
12000b57cec5SDimitry Andric
12010b57cec5SDimitry Andrictemplate <typename _Tp>
12020b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12030b57cec5SDimitry Andricvoid __cxx_atomic_init(volatile __cxx_atomic_lock_impl<_Tp>* __a,  _Tp __val) {
12040b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__a->__a_value, __val);
12050b57cec5SDimitry Andric}
12060b57cec5SDimitry Andrictemplate <typename _Tp>
12070b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12080b57cec5SDimitry Andricvoid __cxx_atomic_init(__cxx_atomic_lock_impl<_Tp>* __a,  _Tp __val) {
12090b57cec5SDimitry Andric  __a->__a_value = __val;
12100b57cec5SDimitry Andric}
12110b57cec5SDimitry Andric
12120b57cec5SDimitry Andrictemplate <typename _Tp>
12130b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12140b57cec5SDimitry Andricvoid __cxx_atomic_store(volatile __cxx_atomic_lock_impl<_Tp>* __a,  _Tp __val, memory_order) {
12150b57cec5SDimitry Andric  __a->__lock();
12160b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__a->__a_value, __val);
12170b57cec5SDimitry Andric  __a->__unlock();
12180b57cec5SDimitry Andric}
12190b57cec5SDimitry Andrictemplate <typename _Tp>
12200b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12210b57cec5SDimitry Andricvoid __cxx_atomic_store(__cxx_atomic_lock_impl<_Tp>* __a,  _Tp __val, memory_order) {
12220b57cec5SDimitry Andric  __a->__lock();
12230b57cec5SDimitry Andric  __a->__a_value = __val;
12240b57cec5SDimitry Andric  __a->__unlock();
12250b57cec5SDimitry Andric}
12260b57cec5SDimitry Andric
12270b57cec5SDimitry Andrictemplate <typename _Tp>
12280b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12290b57cec5SDimitry Andric_Tp __cxx_atomic_load(const volatile __cxx_atomic_lock_impl<_Tp>* __a, memory_order) {
12300b57cec5SDimitry Andric  return __a->__read();
12310b57cec5SDimitry Andric}
12320b57cec5SDimitry Andrictemplate <typename _Tp>
12330b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12340b57cec5SDimitry Andric_Tp __cxx_atomic_load(const __cxx_atomic_lock_impl<_Tp>* __a, memory_order) {
12350b57cec5SDimitry Andric  return __a->__read();
12360b57cec5SDimitry Andric}
12370b57cec5SDimitry Andric
12380b57cec5SDimitry Andrictemplate <typename _Tp>
12390b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12400b57cec5SDimitry Andric_Tp __cxx_atomic_exchange(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) {
12410b57cec5SDimitry Andric  __a->__lock();
12420b57cec5SDimitry Andric  _Tp __old;
12430b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__old, __a->__a_value);
12440b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__a->__a_value, __value);
12450b57cec5SDimitry Andric  __a->__unlock();
12460b57cec5SDimitry Andric  return __old;
12470b57cec5SDimitry Andric}
12480b57cec5SDimitry Andrictemplate <typename _Tp>
12490b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12500b57cec5SDimitry Andric_Tp __cxx_atomic_exchange(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) {
12510b57cec5SDimitry Andric  __a->__lock();
12520b57cec5SDimitry Andric  _Tp __old = __a->__a_value;
12530b57cec5SDimitry Andric  __a->__a_value = __value;
12540b57cec5SDimitry Andric  __a->__unlock();
12550b57cec5SDimitry Andric  return __old;
12560b57cec5SDimitry Andric}
12570b57cec5SDimitry Andric
12580b57cec5SDimitry Andrictemplate <typename _Tp>
12590b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12600b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_strong(volatile __cxx_atomic_lock_impl<_Tp>* __a,
12610b57cec5SDimitry Andric                                          _Tp* __expected, _Tp __value, memory_order, memory_order) {
12625ffd83dbSDimitry Andric  _Tp __temp;
1263*e8d8bef9SDimitry Andric  __a->__lock();
12645ffd83dbSDimitry Andric  __cxx_atomic_assign_volatile(__temp, __a->__a_value);
1265*e8d8bef9SDimitry Andric  bool __ret = (_VSTD::memcmp(&__temp, __expected, sizeof(_Tp)) == 0);
12660b57cec5SDimitry Andric  if(__ret)
12670b57cec5SDimitry Andric    __cxx_atomic_assign_volatile(__a->__a_value, __value);
12680b57cec5SDimitry Andric  else
12690b57cec5SDimitry Andric    __cxx_atomic_assign_volatile(*__expected, __a->__a_value);
12700b57cec5SDimitry Andric  __a->__unlock();
12710b57cec5SDimitry Andric  return __ret;
12720b57cec5SDimitry Andric}
12730b57cec5SDimitry Andrictemplate <typename _Tp>
12740b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12750b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_strong(__cxx_atomic_lock_impl<_Tp>* __a,
12760b57cec5SDimitry Andric                                          _Tp* __expected, _Tp __value, memory_order, memory_order) {
12770b57cec5SDimitry Andric  __a->__lock();
1278*e8d8bef9SDimitry Andric  bool __ret = (_VSTD::memcmp(&__a->__a_value, __expected, sizeof(_Tp)) == 0);
12790b57cec5SDimitry Andric  if(__ret)
1280*e8d8bef9SDimitry Andric    _VSTD::memcpy(&__a->__a_value, &__value, sizeof(_Tp));
12810b57cec5SDimitry Andric  else
1282*e8d8bef9SDimitry Andric    _VSTD::memcpy(__expected, &__a->__a_value, sizeof(_Tp));
12830b57cec5SDimitry Andric  __a->__unlock();
12840b57cec5SDimitry Andric  return __ret;
12850b57cec5SDimitry Andric}
12860b57cec5SDimitry Andric
12870b57cec5SDimitry Andrictemplate <typename _Tp>
12880b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
12890b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_weak(volatile __cxx_atomic_lock_impl<_Tp>* __a,
12900b57cec5SDimitry Andric                                        _Tp* __expected, _Tp __value, memory_order, memory_order) {
12915ffd83dbSDimitry Andric  _Tp __temp;
1292*e8d8bef9SDimitry Andric  __a->__lock();
12935ffd83dbSDimitry Andric  __cxx_atomic_assign_volatile(__temp, __a->__a_value);
1294*e8d8bef9SDimitry Andric  bool __ret = (_VSTD::memcmp(&__temp, __expected, sizeof(_Tp)) == 0);
12950b57cec5SDimitry Andric  if(__ret)
12960b57cec5SDimitry Andric    __cxx_atomic_assign_volatile(__a->__a_value, __value);
12970b57cec5SDimitry Andric  else
12980b57cec5SDimitry Andric    __cxx_atomic_assign_volatile(*__expected, __a->__a_value);
12990b57cec5SDimitry Andric  __a->__unlock();
13000b57cec5SDimitry Andric  return __ret;
13010b57cec5SDimitry Andric}
13020b57cec5SDimitry Andrictemplate <typename _Tp>
13030b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
13040b57cec5SDimitry Andricbool __cxx_atomic_compare_exchange_weak(__cxx_atomic_lock_impl<_Tp>* __a,
13050b57cec5SDimitry Andric                                        _Tp* __expected, _Tp __value, memory_order, memory_order) {
13060b57cec5SDimitry Andric  __a->__lock();
1307*e8d8bef9SDimitry Andric  bool __ret = (_VSTD::memcmp(&__a->__a_value, __expected, sizeof(_Tp)) == 0);
13080b57cec5SDimitry Andric  if(__ret)
1309*e8d8bef9SDimitry Andric    _VSTD::memcpy(&__a->__a_value, &__value, sizeof(_Tp));
13100b57cec5SDimitry Andric  else
1311*e8d8bef9SDimitry Andric    _VSTD::memcpy(__expected, &__a->__a_value, sizeof(_Tp));
13120b57cec5SDimitry Andric  __a->__unlock();
13130b57cec5SDimitry Andric  return __ret;
13140b57cec5SDimitry Andric}
13150b57cec5SDimitry Andric
13160b57cec5SDimitry Andrictemplate <typename _Tp, typename _Td>
13170b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
13180b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp>* __a,
13190b57cec5SDimitry Andric                           _Td __delta, memory_order) {
13200b57cec5SDimitry Andric  __a->__lock();
13210b57cec5SDimitry Andric  _Tp __old;
13220b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__old, __a->__a_value);
13230b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old + __delta));
13240b57cec5SDimitry Andric  __a->__unlock();
13250b57cec5SDimitry Andric  return __old;
13260b57cec5SDimitry Andric}
13270b57cec5SDimitry Andrictemplate <typename _Tp, typename _Td>
13280b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
13290b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp>* __a,
13300b57cec5SDimitry Andric                           _Td __delta, memory_order) {
13310b57cec5SDimitry Andric  __a->__lock();
13320b57cec5SDimitry Andric  _Tp __old = __a->__a_value;
13330b57cec5SDimitry Andric  __a->__a_value += __delta;
13340b57cec5SDimitry Andric  __a->__unlock();
13350b57cec5SDimitry Andric  return __old;
13360b57cec5SDimitry Andric}
13370b57cec5SDimitry Andric
13380b57cec5SDimitry Andrictemplate <typename _Tp, typename _Td>
13390b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
13400b57cec5SDimitry Andric_Tp* __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp*>* __a,
13410b57cec5SDimitry Andric                           ptrdiff_t __delta, memory_order) {
13420b57cec5SDimitry Andric  __a->__lock();
13430b57cec5SDimitry Andric  _Tp* __old;
13440b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__old, __a->__a_value);
13450b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__a->__a_value, __old + __delta);
13460b57cec5SDimitry Andric  __a->__unlock();
13470b57cec5SDimitry Andric  return __old;
13480b57cec5SDimitry Andric}
13490b57cec5SDimitry Andrictemplate <typename _Tp, typename _Td>
13500b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
13510b57cec5SDimitry Andric_Tp* __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp*>* __a,
13520b57cec5SDimitry Andric                           ptrdiff_t __delta, memory_order) {
13530b57cec5SDimitry Andric  __a->__lock();
13540b57cec5SDimitry Andric  _Tp* __old = __a->__a_value;
13550b57cec5SDimitry Andric  __a->__a_value += __delta;
13560b57cec5SDimitry Andric  __a->__unlock();
13570b57cec5SDimitry Andric  return __old;
13580b57cec5SDimitry Andric}
13590b57cec5SDimitry Andric
13600b57cec5SDimitry Andrictemplate <typename _Tp, typename _Td>
13610b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
13620b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_lock_impl<_Tp>* __a,
13630b57cec5SDimitry Andric                           _Td __delta, memory_order) {
13640b57cec5SDimitry Andric  __a->__lock();
13650b57cec5SDimitry Andric  _Tp __old;
13660b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__old, __a->__a_value);
13670b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old - __delta));
13680b57cec5SDimitry Andric  __a->__unlock();
13690b57cec5SDimitry Andric  return __old;
13700b57cec5SDimitry Andric}
13710b57cec5SDimitry Andrictemplate <typename _Tp, typename _Td>
13720b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
13730b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_sub(__cxx_atomic_lock_impl<_Tp>* __a,
13740b57cec5SDimitry Andric                           _Td __delta, memory_order) {
13750b57cec5SDimitry Andric  __a->__lock();
13760b57cec5SDimitry Andric  _Tp __old = __a->__a_value;
13770b57cec5SDimitry Andric  __a->__a_value -= __delta;
13780b57cec5SDimitry Andric  __a->__unlock();
13790b57cec5SDimitry Andric  return __old;
13800b57cec5SDimitry Andric}
13810b57cec5SDimitry Andric
13820b57cec5SDimitry Andrictemplate <typename _Tp>
13830b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
13840b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_lock_impl<_Tp>* __a,
13850b57cec5SDimitry Andric                           _Tp __pattern, memory_order) {
13860b57cec5SDimitry Andric  __a->__lock();
13870b57cec5SDimitry Andric  _Tp __old;
13880b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__old, __a->__a_value);
13890b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old & __pattern));
13900b57cec5SDimitry Andric  __a->__unlock();
13910b57cec5SDimitry Andric  return __old;
13920b57cec5SDimitry Andric}
13930b57cec5SDimitry Andrictemplate <typename _Tp>
13940b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
13950b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_and(__cxx_atomic_lock_impl<_Tp>* __a,
13960b57cec5SDimitry Andric                           _Tp __pattern, memory_order) {
13970b57cec5SDimitry Andric  __a->__lock();
13980b57cec5SDimitry Andric  _Tp __old = __a->__a_value;
13990b57cec5SDimitry Andric  __a->__a_value &= __pattern;
14000b57cec5SDimitry Andric  __a->__unlock();
14010b57cec5SDimitry Andric  return __old;
14020b57cec5SDimitry Andric}
14030b57cec5SDimitry Andric
14040b57cec5SDimitry Andrictemplate <typename _Tp>
14050b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
14060b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_lock_impl<_Tp>* __a,
14070b57cec5SDimitry Andric                          _Tp __pattern, memory_order) {
14080b57cec5SDimitry Andric  __a->__lock();
14090b57cec5SDimitry Andric  _Tp __old;
14100b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__old, __a->__a_value);
14110b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old | __pattern));
14120b57cec5SDimitry Andric  __a->__unlock();
14130b57cec5SDimitry Andric  return __old;
14140b57cec5SDimitry Andric}
14150b57cec5SDimitry Andrictemplate <typename _Tp>
14160b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
14170b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_or(__cxx_atomic_lock_impl<_Tp>* __a,
14180b57cec5SDimitry Andric                          _Tp __pattern, memory_order) {
14190b57cec5SDimitry Andric  __a->__lock();
14200b57cec5SDimitry Andric  _Tp __old = __a->__a_value;
14210b57cec5SDimitry Andric  __a->__a_value |= __pattern;
14220b57cec5SDimitry Andric  __a->__unlock();
14230b57cec5SDimitry Andric  return __old;
14240b57cec5SDimitry Andric}
14250b57cec5SDimitry Andric
14260b57cec5SDimitry Andrictemplate <typename _Tp>
14270b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
14280b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_lock_impl<_Tp>* __a,
14290b57cec5SDimitry Andric                           _Tp __pattern, memory_order) {
14300b57cec5SDimitry Andric  __a->__lock();
14310b57cec5SDimitry Andric  _Tp __old;
14320b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__old, __a->__a_value);
14330b57cec5SDimitry Andric  __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old ^ __pattern));
14340b57cec5SDimitry Andric  __a->__unlock();
14350b57cec5SDimitry Andric  return __old;
14360b57cec5SDimitry Andric}
14370b57cec5SDimitry Andrictemplate <typename _Tp>
14380b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
14390b57cec5SDimitry Andric_Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a,
14400b57cec5SDimitry Andric                           _Tp __pattern, memory_order) {
14410b57cec5SDimitry Andric  __a->__lock();
14420b57cec5SDimitry Andric  _Tp __old = __a->__a_value;
14430b57cec5SDimitry Andric  __a->__a_value ^= __pattern;
14440b57cec5SDimitry Andric  __a->__unlock();
14450b57cec5SDimitry Andric  return __old;
14460b57cec5SDimitry Andric}
14470b57cec5SDimitry Andric
14480b57cec5SDimitry Andric#ifdef __cpp_lib_atomic_is_always_lock_free
14490b57cec5SDimitry Andric
14500b57cec5SDimitry Andrictemplate<typename _Tp> struct __cxx_is_always_lock_free {
14510b57cec5SDimitry Andric    enum { __value = __atomic_always_lock_free(sizeof(_Tp), 0) }; };
14520b57cec5SDimitry Andric
14530b57cec5SDimitry Andric#else
14540b57cec5SDimitry Andric
14550b57cec5SDimitry Andrictemplate<typename _Tp> struct __cxx_is_always_lock_free { enum { __value = false }; };
14560b57cec5SDimitry Andric// Implementations must match the C ATOMIC_*_LOCK_FREE macro values.
14570b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<bool> { enum { __value = 2 == ATOMIC_BOOL_LOCK_FREE }; };
14580b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
14590b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<signed char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
14600b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<unsigned char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
1461*e8d8bef9SDimitry Andric#ifndef _LIBCPP_NO_HAS_CHAR8_T
1462*e8d8bef9SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<char8_t> { enum { __value = 2 == ATOMIC_CHAR8_T_LOCK_FREE }; };
1463*e8d8bef9SDimitry Andric#endif
14640b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<char16_t> { enum { __value = 2 == ATOMIC_CHAR16_T_LOCK_FREE }; };
14650b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<char32_t> { enum { __value = 2 == ATOMIC_CHAR32_T_LOCK_FREE }; };
14660b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<wchar_t> { enum { __value = 2 == ATOMIC_WCHAR_T_LOCK_FREE }; };
14670b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
14680b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<unsigned short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
14690b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; };
14700b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<unsigned int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; };
14710b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; };
14720b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<unsigned long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; };
14730b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; };
14740b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<unsigned long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; };
14750b57cec5SDimitry Andrictemplate<typename _Tp> struct __cxx_is_always_lock_free<_Tp*> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
14760b57cec5SDimitry Andrictemplate<> struct __cxx_is_always_lock_free<std::nullptr_t> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
14770b57cec5SDimitry Andric
14780b57cec5SDimitry Andric#endif //__cpp_lib_atomic_is_always_lock_free
14790b57cec5SDimitry Andric
14800b57cec5SDimitry Andrictemplate <typename _Tp,
14810b57cec5SDimitry Andric          typename _Base = typename conditional<__cxx_is_always_lock_free<_Tp>::__value,
14820b57cec5SDimitry Andric                                                __cxx_atomic_base_impl<_Tp>,
14830b57cec5SDimitry Andric                                                __cxx_atomic_lock_impl<_Tp> >::type>
14840b57cec5SDimitry Andric#else
14850b57cec5SDimitry Andrictemplate <typename _Tp,
14860b57cec5SDimitry Andric          typename _Base = __cxx_atomic_base_impl<_Tp> >
14870b57cec5SDimitry Andric#endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS
14880b57cec5SDimitry Andricstruct __cxx_atomic_impl : public _Base {
14890b57cec5SDimitry Andric
14900b57cec5SDimitry Andric#if _GNUC_VER >= 501
14910b57cec5SDimitry Andric    static_assert(is_trivially_copyable<_Tp>::value,
14920b57cec5SDimitry Andric      "std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
14930b57cec5SDimitry Andric#endif
14940b57cec5SDimitry Andric
14950b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT _LIBCPP_DEFAULT
14960b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp value) _NOEXCEPT
14970b57cec5SDimitry Andric    : _Base(value) {}
14980b57cec5SDimitry Andric};
14990b57cec5SDimitry Andric
1500d061adc4SAdrian Chadd#if defined(__linux__) || (defined(__FreeBSD__) && defined(__mips__))
15015ffd83dbSDimitry Andric    using __cxx_contention_t = int32_t;
15025ffd83dbSDimitry Andric#else
15035ffd83dbSDimitry Andric    using __cxx_contention_t = int64_t;
1504d061adc4SAdrian Chadd#endif
15055ffd83dbSDimitry Andric
15065ffd83dbSDimitry Andricusing __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>;
15075ffd83dbSDimitry Andric
15085ffd83dbSDimitry Andric#ifndef _LIBCPP_HAS_NO_PLATFORM_WAIT
15095ffd83dbSDimitry Andric
15105ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile*);
15115ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(void const volatile*);
15125ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __libcpp_atomic_monitor(void const volatile*);
15135ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __libcpp_atomic_wait(void const volatile*, __cxx_contention_t);
15145ffd83dbSDimitry Andric
15155ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(__cxx_atomic_contention_t const volatile*);
15165ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(__cxx_atomic_contention_t const volatile*);
15175ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI __cxx_contention_t __libcpp_atomic_monitor(__cxx_atomic_contention_t const volatile*);
15185ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __libcpp_atomic_wait(__cxx_atomic_contention_t const volatile*, __cxx_contention_t);
15195ffd83dbSDimitry Andric
15205ffd83dbSDimitry Andrictemplate <class _Atp, class _Fn>
15215ffd83dbSDimitry Andricstruct __libcpp_atomic_wait_backoff_impl {
15225ffd83dbSDimitry Andric    _Atp* __a;
15235ffd83dbSDimitry Andric    _Fn __test_fn;
15245ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC
15255ffd83dbSDimitry Andric    _LIBCPP_INLINE_VISIBILITY bool operator()(chrono::nanoseconds __elapsed) const
15265ffd83dbSDimitry Andric    {
15275ffd83dbSDimitry Andric        if(__elapsed > chrono::microseconds(64))
15285ffd83dbSDimitry Andric        {
15295ffd83dbSDimitry Andric            auto const __monitor = __libcpp_atomic_monitor(__a);
15305ffd83dbSDimitry Andric            if(__test_fn())
15315ffd83dbSDimitry Andric                return true;
15325ffd83dbSDimitry Andric            __libcpp_atomic_wait(__a, __monitor);
15335ffd83dbSDimitry Andric        }
15345ffd83dbSDimitry Andric        else if(__elapsed > chrono::microseconds(4))
15355ffd83dbSDimitry Andric            __libcpp_thread_yield();
15365ffd83dbSDimitry Andric        else
1537*e8d8bef9SDimitry Andric            {} // poll
15385ffd83dbSDimitry Andric        return false;
15395ffd83dbSDimitry Andric    }
15405ffd83dbSDimitry Andric};
15415ffd83dbSDimitry Andric
15425ffd83dbSDimitry Andrictemplate <class _Atp, class _Fn>
15435ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC
15445ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait(_Atp* __a, _Fn && __test_fn)
15455ffd83dbSDimitry Andric{
15465ffd83dbSDimitry Andric    __libcpp_atomic_wait_backoff_impl<_Atp, typename decay<_Fn>::type> __backoff_fn = {__a, __test_fn};
15475ffd83dbSDimitry Andric    return __libcpp_thread_poll_with_backoff(__test_fn, __backoff_fn);
15485ffd83dbSDimitry Andric}
15495ffd83dbSDimitry Andric
15505ffd83dbSDimitry Andric#else // _LIBCPP_HAS_NO_PLATFORM_WAIT
15515ffd83dbSDimitry Andric
15525ffd83dbSDimitry Andrictemplate <class _Tp>
15535ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY void __cxx_atomic_notify_all(__cxx_atomic_impl<_Tp> const volatile*) { }
15545ffd83dbSDimitry Andrictemplate <class _Tp>
15555ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY void __cxx_atomic_notify_one(__cxx_atomic_impl<_Tp> const volatile*) { }
15565ffd83dbSDimitry Andrictemplate <class _Atp, class _Fn>
15575ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait(_Atp*, _Fn && __test_fn)
15585ffd83dbSDimitry Andric{
15595ffd83dbSDimitry Andric    return __libcpp_thread_poll_with_backoff(__test_fn, __libcpp_timed_backoff_policy());
15605ffd83dbSDimitry Andric}
15615ffd83dbSDimitry Andric
15625ffd83dbSDimitry Andric#endif // _LIBCPP_HAS_NO_PLATFORM_WAIT
15635ffd83dbSDimitry Andric
15645ffd83dbSDimitry Andrictemplate <class _Atp, class _Tp>
15655ffd83dbSDimitry Andricstruct __cxx_atomic_wait_test_fn_impl {
15665ffd83dbSDimitry Andric    _Atp* __a;
15675ffd83dbSDimitry Andric    _Tp __val;
15685ffd83dbSDimitry Andric    memory_order __order;
15695ffd83dbSDimitry Andric    _LIBCPP_INLINE_VISIBILITY bool operator()() const
15705ffd83dbSDimitry Andric    {
15715ffd83dbSDimitry Andric        return !__cxx_nonatomic_compare_equal(__cxx_atomic_load(__a, __order), __val);
15725ffd83dbSDimitry Andric    }
15735ffd83dbSDimitry Andric};
15745ffd83dbSDimitry Andric
15755ffd83dbSDimitry Andrictemplate <class _Atp, class _Tp>
15765ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC
15775ffd83dbSDimitry Andric_LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait(_Atp* __a, _Tp const __val, memory_order __order)
15785ffd83dbSDimitry Andric{
15795ffd83dbSDimitry Andric    __cxx_atomic_wait_test_fn_impl<_Atp, _Tp> __test_fn = {__a, __val, __order};
15805ffd83dbSDimitry Andric    return __cxx_atomic_wait(__a, __test_fn);
15815ffd83dbSDimitry Andric}
15825ffd83dbSDimitry Andric
15830b57cec5SDimitry Andric// general atomic<T>
15840b57cec5SDimitry Andric
15850b57cec5SDimitry Andrictemplate <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
15860b57cec5SDimitry Andricstruct __atomic_base  // false
15870b57cec5SDimitry Andric{
15880b57cec5SDimitry Andric    mutable __cxx_atomic_impl<_Tp> __a_;
15890b57cec5SDimitry Andric
15900b57cec5SDimitry Andric#if defined(__cpp_lib_atomic_is_always_lock_free)
15910b57cec5SDimitry Andric  static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0);
15920b57cec5SDimitry Andric#endif
15930b57cec5SDimitry Andric
15940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15950b57cec5SDimitry Andric    bool is_lock_free() const volatile _NOEXCEPT
15960b57cec5SDimitry Andric        {return __cxx_atomic_is_lock_free(sizeof(_Tp));}
15970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15980b57cec5SDimitry Andric    bool is_lock_free() const _NOEXCEPT
15990b57cec5SDimitry Andric        {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();}
16000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16010b57cec5SDimitry Andric    void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
16020b57cec5SDimitry Andric      _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
16030b57cec5SDimitry Andric        {__cxx_atomic_store(&__a_, __d, __m);}
16040b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16050b57cec5SDimitry Andric    void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
16060b57cec5SDimitry Andric      _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
16070b57cec5SDimitry Andric        {__cxx_atomic_store(&__a_, __d, __m);}
16080b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16090b57cec5SDimitry Andric    _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
16100b57cec5SDimitry Andric      _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
16110b57cec5SDimitry Andric        {return __cxx_atomic_load(&__a_, __m);}
16120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16130b57cec5SDimitry Andric    _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
16140b57cec5SDimitry Andric      _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
16150b57cec5SDimitry Andric        {return __cxx_atomic_load(&__a_, __m);}
16160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16170b57cec5SDimitry Andric    operator _Tp() const volatile _NOEXCEPT {return load();}
16180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16190b57cec5SDimitry Andric    operator _Tp() const _NOEXCEPT          {return load();}
16200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16210b57cec5SDimitry Andric    _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
16220b57cec5SDimitry Andric        {return __cxx_atomic_exchange(&__a_, __d, __m);}
16230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16240b57cec5SDimitry Andric    _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
16250b57cec5SDimitry Andric        {return __cxx_atomic_exchange(&__a_, __d, __m);}
16260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16270b57cec5SDimitry Andric    bool compare_exchange_weak(_Tp& __e, _Tp __d,
16280b57cec5SDimitry Andric                               memory_order __s, memory_order __f) volatile _NOEXCEPT
16290b57cec5SDimitry Andric      _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
16300b57cec5SDimitry Andric        {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
16310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16320b57cec5SDimitry Andric    bool compare_exchange_weak(_Tp& __e, _Tp __d,
16330b57cec5SDimitry Andric                               memory_order __s, memory_order __f) _NOEXCEPT
16340b57cec5SDimitry Andric      _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
16350b57cec5SDimitry Andric        {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
16360b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16370b57cec5SDimitry Andric    bool compare_exchange_strong(_Tp& __e, _Tp __d,
16380b57cec5SDimitry Andric                                 memory_order __s, memory_order __f) volatile _NOEXCEPT
16390b57cec5SDimitry Andric      _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
16400b57cec5SDimitry Andric        {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
16410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16420b57cec5SDimitry Andric    bool compare_exchange_strong(_Tp& __e, _Tp __d,
16430b57cec5SDimitry Andric                                 memory_order __s, memory_order __f) _NOEXCEPT
16440b57cec5SDimitry Andric      _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
16450b57cec5SDimitry Andric        {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
16460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16470b57cec5SDimitry Andric    bool compare_exchange_weak(_Tp& __e, _Tp __d,
16480b57cec5SDimitry Andric                              memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
16490b57cec5SDimitry Andric        {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
16500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16510b57cec5SDimitry Andric    bool compare_exchange_weak(_Tp& __e, _Tp __d,
16520b57cec5SDimitry Andric                               memory_order __m = memory_order_seq_cst) _NOEXCEPT
16530b57cec5SDimitry Andric        {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
16540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16550b57cec5SDimitry Andric    bool compare_exchange_strong(_Tp& __e, _Tp __d,
16560b57cec5SDimitry Andric                              memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
16570b57cec5SDimitry Andric        {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
16580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16590b57cec5SDimitry Andric    bool compare_exchange_strong(_Tp& __e, _Tp __d,
16600b57cec5SDimitry Andric                                 memory_order __m = memory_order_seq_cst) _NOEXCEPT
16610b57cec5SDimitry Andric        {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
16620b57cec5SDimitry Andric
16635ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
16645ffd83dbSDimitry Andric        {__cxx_atomic_wait(&__a_, __v, __m);}
16655ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT
16665ffd83dbSDimitry Andric        {__cxx_atomic_wait(&__a_, __v, __m);}
16675ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void notify_one() volatile _NOEXCEPT
16685ffd83dbSDimitry Andric        {__cxx_atomic_notify_one(&__a_);}
16695ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void notify_one() _NOEXCEPT
16705ffd83dbSDimitry Andric        {__cxx_atomic_notify_one(&__a_);}
16715ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void notify_all() volatile _NOEXCEPT
16725ffd83dbSDimitry Andric        {__cxx_atomic_notify_all(&__a_);}
16735ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY void notify_all() _NOEXCEPT
16745ffd83dbSDimitry Andric        {__cxx_atomic_notify_all(&__a_);}
16755ffd83dbSDimitry Andric
16760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16770b57cec5SDimitry Andric    __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
16780b57cec5SDimitry Andric
16790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
16800b57cec5SDimitry Andric    __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
16810b57cec5SDimitry Andric
16820b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
16830b57cec5SDimitry Andric    __atomic_base(const __atomic_base&) = delete;
16840b57cec5SDimitry Andric    __atomic_base& operator=(const __atomic_base&) = delete;
16850b57cec5SDimitry Andric    __atomic_base& operator=(const __atomic_base&) volatile = delete;
16860b57cec5SDimitry Andric#else
16870b57cec5SDimitry Andricprivate:
16885ffd83dbSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16890b57cec5SDimitry Andric    __atomic_base(const __atomic_base&);
16905ffd83dbSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16910b57cec5SDimitry Andric    __atomic_base& operator=(const __atomic_base&);
16925ffd83dbSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16930b57cec5SDimitry Andric    __atomic_base& operator=(const __atomic_base&) volatile;
16940b57cec5SDimitry Andric#endif
16950b57cec5SDimitry Andric};
16960b57cec5SDimitry Andric
16970b57cec5SDimitry Andric#if defined(__cpp_lib_atomic_is_always_lock_free)
16980b57cec5SDimitry Andrictemplate <class _Tp, bool __b>
16990b57cec5SDimitry Andric_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
17000b57cec5SDimitry Andric#endif
17010b57cec5SDimitry Andric
17020b57cec5SDimitry Andric// atomic<Integral>
17030b57cec5SDimitry Andric
17040b57cec5SDimitry Andrictemplate <class _Tp>
17050b57cec5SDimitry Andricstruct __atomic_base<_Tp, true>
17060b57cec5SDimitry Andric    : public __atomic_base<_Tp, false>
17070b57cec5SDimitry Andric{
17080b57cec5SDimitry Andric    typedef __atomic_base<_Tp, false> __base;
17090b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17100b57cec5SDimitry Andric    __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
17110b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17120b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
17130b57cec5SDimitry Andric
17140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17150b57cec5SDimitry Andric    _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
17160b57cec5SDimitry Andric        {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
17170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17180b57cec5SDimitry Andric    _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
17190b57cec5SDimitry Andric        {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
17200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17210b57cec5SDimitry Andric    _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
17220b57cec5SDimitry Andric        {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
17230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17240b57cec5SDimitry Andric    _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
17250b57cec5SDimitry Andric        {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
17260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17270b57cec5SDimitry Andric    _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
17280b57cec5SDimitry Andric        {return __cxx_atomic_fetch_and(&this->__a_, __op, __m);}
17290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17300b57cec5SDimitry Andric    _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
17310b57cec5SDimitry Andric        {return __cxx_atomic_fetch_and(&this->__a_, __op, __m);}
17320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17330b57cec5SDimitry Andric    _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
17340b57cec5SDimitry Andric        {return __cxx_atomic_fetch_or(&this->__a_, __op, __m);}
17350b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17360b57cec5SDimitry Andric    _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
17370b57cec5SDimitry Andric        {return __cxx_atomic_fetch_or(&this->__a_, __op, __m);}
17380b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17390b57cec5SDimitry Andric    _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
17400b57cec5SDimitry Andric        {return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);}
17410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17420b57cec5SDimitry Andric    _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
17430b57cec5SDimitry Andric        {return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);}
17440b57cec5SDimitry Andric
17450b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17460b57cec5SDimitry Andric    _Tp operator++(int) volatile _NOEXCEPT      {return fetch_add(_Tp(1));}
17470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17480b57cec5SDimitry Andric    _Tp operator++(int) _NOEXCEPT               {return fetch_add(_Tp(1));}
17490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17500b57cec5SDimitry Andric    _Tp operator--(int) volatile _NOEXCEPT      {return fetch_sub(_Tp(1));}
17510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17520b57cec5SDimitry Andric    _Tp operator--(int) _NOEXCEPT               {return fetch_sub(_Tp(1));}
17530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17540b57cec5SDimitry Andric    _Tp operator++() volatile _NOEXCEPT         {return fetch_add(_Tp(1)) + _Tp(1);}
17550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17560b57cec5SDimitry Andric    _Tp operator++() _NOEXCEPT                  {return fetch_add(_Tp(1)) + _Tp(1);}
17570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17580b57cec5SDimitry Andric    _Tp operator--() volatile _NOEXCEPT         {return fetch_sub(_Tp(1)) - _Tp(1);}
17590b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17600b57cec5SDimitry Andric    _Tp operator--() _NOEXCEPT                  {return fetch_sub(_Tp(1)) - _Tp(1);}
17610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17620b57cec5SDimitry Andric    _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
17630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17640b57cec5SDimitry Andric    _Tp operator+=(_Tp __op) _NOEXCEPT          {return fetch_add(__op) + __op;}
17650b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17660b57cec5SDimitry Andric    _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
17670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17680b57cec5SDimitry Andric    _Tp operator-=(_Tp __op) _NOEXCEPT          {return fetch_sub(__op) - __op;}
17690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17700b57cec5SDimitry Andric    _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
17710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17720b57cec5SDimitry Andric    _Tp operator&=(_Tp __op) _NOEXCEPT          {return fetch_and(__op) & __op;}
17730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17740b57cec5SDimitry Andric    _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
17750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17760b57cec5SDimitry Andric    _Tp operator|=(_Tp __op) _NOEXCEPT          {return fetch_or(__op) | __op;}
17770b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17780b57cec5SDimitry Andric    _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
17790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17800b57cec5SDimitry Andric    _Tp operator^=(_Tp __op) _NOEXCEPT          {return fetch_xor(__op) ^ __op;}
17810b57cec5SDimitry Andric};
17820b57cec5SDimitry Andric
17830b57cec5SDimitry Andric// atomic<T>
17840b57cec5SDimitry Andric
17850b57cec5SDimitry Andrictemplate <class _Tp>
17860b57cec5SDimitry Andricstruct atomic
17870b57cec5SDimitry Andric    : public __atomic_base<_Tp>
17880b57cec5SDimitry Andric{
17890b57cec5SDimitry Andric    typedef __atomic_base<_Tp> __base;
17905ffd83dbSDimitry Andric    typedef _Tp value_type;
1791*e8d8bef9SDimitry Andric    typedef value_type difference_type;
17920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17930b57cec5SDimitry Andric    atomic() _NOEXCEPT _LIBCPP_DEFAULT
17940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17950b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
17960b57cec5SDimitry Andric
17970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
17980b57cec5SDimitry Andric    _Tp operator=(_Tp __d) volatile _NOEXCEPT
17990b57cec5SDimitry Andric        {__base::store(__d); return __d;}
18000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18010b57cec5SDimitry Andric    _Tp operator=(_Tp __d) _NOEXCEPT
18020b57cec5SDimitry Andric        {__base::store(__d); return __d;}
18030b57cec5SDimitry Andric};
18040b57cec5SDimitry Andric
18050b57cec5SDimitry Andric// atomic<T*>
18060b57cec5SDimitry Andric
18070b57cec5SDimitry Andrictemplate <class _Tp>
18080b57cec5SDimitry Andricstruct atomic<_Tp*>
18090b57cec5SDimitry Andric    : public __atomic_base<_Tp*>
18100b57cec5SDimitry Andric{
18110b57cec5SDimitry Andric    typedef __atomic_base<_Tp*> __base;
18125ffd83dbSDimitry Andric    typedef _Tp* value_type;
1813*e8d8bef9SDimitry Andric    typedef ptrdiff_t difference_type;
18140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18150b57cec5SDimitry Andric    atomic() _NOEXCEPT _LIBCPP_DEFAULT
18160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18170b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
18180b57cec5SDimitry Andric
18190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18200b57cec5SDimitry Andric    _Tp* operator=(_Tp* __d) volatile _NOEXCEPT
18210b57cec5SDimitry Andric        {__base::store(__d); return __d;}
18220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18230b57cec5SDimitry Andric    _Tp* operator=(_Tp* __d) _NOEXCEPT
18240b57cec5SDimitry Andric        {__base::store(__d); return __d;}
18250b57cec5SDimitry Andric
18260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18270b57cec5SDimitry Andric    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
18280b57cec5SDimitry Andric                                                                        volatile _NOEXCEPT
18290b57cec5SDimitry Andric        {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
18300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18310b57cec5SDimitry Andric    _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
18320b57cec5SDimitry Andric        {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
18330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18340b57cec5SDimitry Andric    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
18350b57cec5SDimitry Andric                                                                        volatile _NOEXCEPT
18360b57cec5SDimitry Andric        {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
18370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18380b57cec5SDimitry Andric    _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
18390b57cec5SDimitry Andric        {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
18400b57cec5SDimitry Andric
18410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18420b57cec5SDimitry Andric    _Tp* operator++(int) volatile _NOEXCEPT            {return fetch_add(1);}
18430b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18440b57cec5SDimitry Andric    _Tp* operator++(int) _NOEXCEPT                     {return fetch_add(1);}
18450b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18460b57cec5SDimitry Andric    _Tp* operator--(int) volatile _NOEXCEPT            {return fetch_sub(1);}
18470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18480b57cec5SDimitry Andric    _Tp* operator--(int) _NOEXCEPT                     {return fetch_sub(1);}
18490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18500b57cec5SDimitry Andric    _Tp* operator++() volatile _NOEXCEPT               {return fetch_add(1) + 1;}
18510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18520b57cec5SDimitry Andric    _Tp* operator++() _NOEXCEPT                        {return fetch_add(1) + 1;}
18530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18540b57cec5SDimitry Andric    _Tp* operator--() volatile _NOEXCEPT               {return fetch_sub(1) - 1;}
18550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18560b57cec5SDimitry Andric    _Tp* operator--() _NOEXCEPT                        {return fetch_sub(1) - 1;}
18570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18580b57cec5SDimitry Andric    _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
18590b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18600b57cec5SDimitry Andric    _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT          {return fetch_add(__op) + __op;}
18610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18620b57cec5SDimitry Andric    _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
18630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
18640b57cec5SDimitry Andric    _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT          {return fetch_sub(__op) - __op;}
18650b57cec5SDimitry Andric};
18660b57cec5SDimitry Andric
18670b57cec5SDimitry Andric// atomic_is_lock_free
18680b57cec5SDimitry Andric
18690b57cec5SDimitry Andrictemplate <class _Tp>
18700b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
18710b57cec5SDimitry Andricbool
18720b57cec5SDimitry Andricatomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
18730b57cec5SDimitry Andric{
18740b57cec5SDimitry Andric    return __o->is_lock_free();
18750b57cec5SDimitry Andric}
18760b57cec5SDimitry Andric
18770b57cec5SDimitry Andrictemplate <class _Tp>
18780b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
18790b57cec5SDimitry Andricbool
18800b57cec5SDimitry Andricatomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
18810b57cec5SDimitry Andric{
18820b57cec5SDimitry Andric    return __o->is_lock_free();
18830b57cec5SDimitry Andric}
18840b57cec5SDimitry Andric
18850b57cec5SDimitry Andric// atomic_init
18860b57cec5SDimitry Andric
18870b57cec5SDimitry Andrictemplate <class _Tp>
18880b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
18890b57cec5SDimitry Andricvoid
1890*e8d8bef9SDimitry Andricatomic_init(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
18910b57cec5SDimitry Andric{
18920b57cec5SDimitry Andric    __cxx_atomic_init(&__o->__a_, __d);
18930b57cec5SDimitry Andric}
18940b57cec5SDimitry Andric
18950b57cec5SDimitry Andrictemplate <class _Tp>
18960b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
18970b57cec5SDimitry Andricvoid
1898*e8d8bef9SDimitry Andricatomic_init(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
18990b57cec5SDimitry Andric{
19000b57cec5SDimitry Andric    __cxx_atomic_init(&__o->__a_, __d);
19010b57cec5SDimitry Andric}
19020b57cec5SDimitry Andric
19030b57cec5SDimitry Andric// atomic_store
19040b57cec5SDimitry Andric
19050b57cec5SDimitry Andrictemplate <class _Tp>
19060b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
19070b57cec5SDimitry Andricvoid
1908*e8d8bef9SDimitry Andricatomic_store(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
19090b57cec5SDimitry Andric{
19100b57cec5SDimitry Andric    __o->store(__d);
19110b57cec5SDimitry Andric}
19120b57cec5SDimitry Andric
19130b57cec5SDimitry Andrictemplate <class _Tp>
19140b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
19150b57cec5SDimitry Andricvoid
1916*e8d8bef9SDimitry Andricatomic_store(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
19170b57cec5SDimitry Andric{
19180b57cec5SDimitry Andric    __o->store(__d);
19190b57cec5SDimitry Andric}
19200b57cec5SDimitry Andric
19210b57cec5SDimitry Andric// atomic_store_explicit
19220b57cec5SDimitry Andric
19230b57cec5SDimitry Andrictemplate <class _Tp>
19240b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
19250b57cec5SDimitry Andricvoid
1926*e8d8bef9SDimitry Andricatomic_store_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
19270b57cec5SDimitry Andric  _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
19280b57cec5SDimitry Andric{
19290b57cec5SDimitry Andric    __o->store(__d, __m);
19300b57cec5SDimitry Andric}
19310b57cec5SDimitry Andric
19320b57cec5SDimitry Andrictemplate <class _Tp>
19330b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
19340b57cec5SDimitry Andricvoid
1935*e8d8bef9SDimitry Andricatomic_store_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
19360b57cec5SDimitry Andric  _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
19370b57cec5SDimitry Andric{
19380b57cec5SDimitry Andric    __o->store(__d, __m);
19390b57cec5SDimitry Andric}
19400b57cec5SDimitry Andric
19410b57cec5SDimitry Andric// atomic_load
19420b57cec5SDimitry Andric
19430b57cec5SDimitry Andrictemplate <class _Tp>
19440b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
19450b57cec5SDimitry Andric_Tp
19460b57cec5SDimitry Andricatomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
19470b57cec5SDimitry Andric{
19480b57cec5SDimitry Andric    return __o->load();
19490b57cec5SDimitry Andric}
19500b57cec5SDimitry Andric
19510b57cec5SDimitry Andrictemplate <class _Tp>
19520b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
19530b57cec5SDimitry Andric_Tp
19540b57cec5SDimitry Andricatomic_load(const atomic<_Tp>* __o) _NOEXCEPT
19550b57cec5SDimitry Andric{
19560b57cec5SDimitry Andric    return __o->load();
19570b57cec5SDimitry Andric}
19580b57cec5SDimitry Andric
19590b57cec5SDimitry Andric// atomic_load_explicit
19600b57cec5SDimitry Andric
19610b57cec5SDimitry Andrictemplate <class _Tp>
19620b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
19630b57cec5SDimitry Andric_Tp
19640b57cec5SDimitry Andricatomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
19650b57cec5SDimitry Andric  _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
19660b57cec5SDimitry Andric{
19670b57cec5SDimitry Andric    return __o->load(__m);
19680b57cec5SDimitry Andric}
19690b57cec5SDimitry Andric
19700b57cec5SDimitry Andrictemplate <class _Tp>
19710b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
19720b57cec5SDimitry Andric_Tp
19730b57cec5SDimitry Andricatomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
19740b57cec5SDimitry Andric  _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
19750b57cec5SDimitry Andric{
19760b57cec5SDimitry Andric    return __o->load(__m);
19770b57cec5SDimitry Andric}
19780b57cec5SDimitry Andric
19790b57cec5SDimitry Andric// atomic_exchange
19800b57cec5SDimitry Andric
19810b57cec5SDimitry Andrictemplate <class _Tp>
19820b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
19830b57cec5SDimitry Andric_Tp
1984*e8d8bef9SDimitry Andricatomic_exchange(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
19850b57cec5SDimitry Andric{
19860b57cec5SDimitry Andric    return __o->exchange(__d);
19870b57cec5SDimitry Andric}
19880b57cec5SDimitry Andric
19890b57cec5SDimitry Andrictemplate <class _Tp>
19900b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
19910b57cec5SDimitry Andric_Tp
1992*e8d8bef9SDimitry Andricatomic_exchange(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT
19930b57cec5SDimitry Andric{
19940b57cec5SDimitry Andric    return __o->exchange(__d);
19950b57cec5SDimitry Andric}
19960b57cec5SDimitry Andric
19970b57cec5SDimitry Andric// atomic_exchange_explicit
19980b57cec5SDimitry Andric
19990b57cec5SDimitry Andrictemplate <class _Tp>
20000b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
20010b57cec5SDimitry Andric_Tp
2002*e8d8bef9SDimitry Andricatomic_exchange_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
20030b57cec5SDimitry Andric{
20040b57cec5SDimitry Andric    return __o->exchange(__d, __m);
20050b57cec5SDimitry Andric}
20060b57cec5SDimitry Andric
20070b57cec5SDimitry Andrictemplate <class _Tp>
20080b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
20090b57cec5SDimitry Andric_Tp
2010*e8d8bef9SDimitry Andricatomic_exchange_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d, memory_order __m) _NOEXCEPT
20110b57cec5SDimitry Andric{
20120b57cec5SDimitry Andric    return __o->exchange(__d, __m);
20130b57cec5SDimitry Andric}
20140b57cec5SDimitry Andric
20150b57cec5SDimitry Andric// atomic_compare_exchange_weak
20160b57cec5SDimitry Andric
20170b57cec5SDimitry Andrictemplate <class _Tp>
20180b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
20190b57cec5SDimitry Andricbool
2020*e8d8bef9SDimitry Andricatomic_compare_exchange_weak(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
20210b57cec5SDimitry Andric{
20220b57cec5SDimitry Andric    return __o->compare_exchange_weak(*__e, __d);
20230b57cec5SDimitry Andric}
20240b57cec5SDimitry Andric
20250b57cec5SDimitry Andrictemplate <class _Tp>
20260b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
20270b57cec5SDimitry Andricbool
2028*e8d8bef9SDimitry Andricatomic_compare_exchange_weak(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
20290b57cec5SDimitry Andric{
20300b57cec5SDimitry Andric    return __o->compare_exchange_weak(*__e, __d);
20310b57cec5SDimitry Andric}
20320b57cec5SDimitry Andric
20330b57cec5SDimitry Andric// atomic_compare_exchange_strong
20340b57cec5SDimitry Andric
20350b57cec5SDimitry Andrictemplate <class _Tp>
20360b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
20370b57cec5SDimitry Andricbool
2038*e8d8bef9SDimitry Andricatomic_compare_exchange_strong(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
20390b57cec5SDimitry Andric{
20400b57cec5SDimitry Andric    return __o->compare_exchange_strong(*__e, __d);
20410b57cec5SDimitry Andric}
20420b57cec5SDimitry Andric
20430b57cec5SDimitry Andrictemplate <class _Tp>
20440b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
20450b57cec5SDimitry Andricbool
2046*e8d8bef9SDimitry Andricatomic_compare_exchange_strong(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d) _NOEXCEPT
20470b57cec5SDimitry Andric{
20480b57cec5SDimitry Andric    return __o->compare_exchange_strong(*__e, __d);
20490b57cec5SDimitry Andric}
20500b57cec5SDimitry Andric
20510b57cec5SDimitry Andric// atomic_compare_exchange_weak_explicit
20520b57cec5SDimitry Andric
20530b57cec5SDimitry Andrictemplate <class _Tp>
20540b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
20550b57cec5SDimitry Andricbool
2056*e8d8bef9SDimitry Andricatomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e,
2057*e8d8bef9SDimitry Andric                                      typename atomic<_Tp>::value_type __d,
20580b57cec5SDimitry Andric                                      memory_order __s, memory_order __f) _NOEXCEPT
20590b57cec5SDimitry Andric  _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
20600b57cec5SDimitry Andric{
20610b57cec5SDimitry Andric    return __o->compare_exchange_weak(*__e, __d, __s, __f);
20620b57cec5SDimitry Andric}
20630b57cec5SDimitry Andric
20640b57cec5SDimitry Andrictemplate <class _Tp>
20650b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
20660b57cec5SDimitry Andricbool
2067*e8d8bef9SDimitry Andricatomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d,
20680b57cec5SDimitry Andric                                      memory_order __s, memory_order __f) _NOEXCEPT
20690b57cec5SDimitry Andric  _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
20700b57cec5SDimitry Andric{
20710b57cec5SDimitry Andric    return __o->compare_exchange_weak(*__e, __d, __s, __f);
20720b57cec5SDimitry Andric}
20730b57cec5SDimitry Andric
20740b57cec5SDimitry Andric// atomic_compare_exchange_strong_explicit
20750b57cec5SDimitry Andric
20760b57cec5SDimitry Andrictemplate <class _Tp>
20770b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
20780b57cec5SDimitry Andricbool
20790b57cec5SDimitry Andricatomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
2080*e8d8bef9SDimitry Andric                                        typename atomic<_Tp>::value_type* __e, typename atomic<_Tp>::value_type __d,
20810b57cec5SDimitry Andric                                        memory_order __s, memory_order __f) _NOEXCEPT
20820b57cec5SDimitry Andric  _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
20830b57cec5SDimitry Andric{
20840b57cec5SDimitry Andric    return __o->compare_exchange_strong(*__e, __d, __s, __f);
20850b57cec5SDimitry Andric}
20860b57cec5SDimitry Andric
20870b57cec5SDimitry Andrictemplate <class _Tp>
20880b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
20890b57cec5SDimitry Andricbool
2090*e8d8bef9SDimitry Andricatomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type* __e,
2091*e8d8bef9SDimitry Andric                                        typename atomic<_Tp>::value_type __d,
20920b57cec5SDimitry Andric                                        memory_order __s, memory_order __f) _NOEXCEPT
20930b57cec5SDimitry Andric  _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
20940b57cec5SDimitry Andric{
20950b57cec5SDimitry Andric    return __o->compare_exchange_strong(*__e, __d, __s, __f);
20960b57cec5SDimitry Andric}
20970b57cec5SDimitry Andric
20985ffd83dbSDimitry Andric// atomic_wait
20995ffd83dbSDimitry Andric
21005ffd83dbSDimitry Andrictemplate <class _Tp>
21015ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
21025ffd83dbSDimitry Andricvoid atomic_wait(const volatile atomic<_Tp>* __o,
21035ffd83dbSDimitry Andric                 typename atomic<_Tp>::value_type __v) _NOEXCEPT
21045ffd83dbSDimitry Andric{
21055ffd83dbSDimitry Andric    return __o->wait(__v);
21065ffd83dbSDimitry Andric}
21075ffd83dbSDimitry Andric
21085ffd83dbSDimitry Andrictemplate <class _Tp>
21095ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
21105ffd83dbSDimitry Andricvoid atomic_wait(const atomic<_Tp>* __o,
21115ffd83dbSDimitry Andric                 typename atomic<_Tp>::value_type __v) _NOEXCEPT
21125ffd83dbSDimitry Andric{
21135ffd83dbSDimitry Andric    return __o->wait(__v);
21145ffd83dbSDimitry Andric}
21155ffd83dbSDimitry Andric
21165ffd83dbSDimitry Andric// atomic_wait_explicit
21175ffd83dbSDimitry Andric
21185ffd83dbSDimitry Andrictemplate <class _Tp>
21195ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
21205ffd83dbSDimitry Andricvoid atomic_wait_explicit(const volatile atomic<_Tp>* __o,
21215ffd83dbSDimitry Andric                          typename atomic<_Tp>::value_type __v,
21225ffd83dbSDimitry Andric                          memory_order __m) _NOEXCEPT
21235ffd83dbSDimitry Andric  _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
21245ffd83dbSDimitry Andric{
21255ffd83dbSDimitry Andric    return __o->wait(__v, __m);
21265ffd83dbSDimitry Andric}
21275ffd83dbSDimitry Andric
21285ffd83dbSDimitry Andrictemplate <class _Tp>
21295ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
21305ffd83dbSDimitry Andricvoid atomic_wait_explicit(const atomic<_Tp>* __o,
21315ffd83dbSDimitry Andric                          typename atomic<_Tp>::value_type __v,
21325ffd83dbSDimitry Andric                          memory_order __m) _NOEXCEPT
21335ffd83dbSDimitry Andric  _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
21345ffd83dbSDimitry Andric{
21355ffd83dbSDimitry Andric    return __o->wait(__v, __m);
21365ffd83dbSDimitry Andric}
21375ffd83dbSDimitry Andric
21385ffd83dbSDimitry Andric// atomic_notify_one
21395ffd83dbSDimitry Andric
21405ffd83dbSDimitry Andrictemplate <class _Tp>
21415ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
21425ffd83dbSDimitry Andricvoid atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT
21435ffd83dbSDimitry Andric{
21445ffd83dbSDimitry Andric    __o->notify_one();
21455ffd83dbSDimitry Andric}
21465ffd83dbSDimitry Andrictemplate <class _Tp>
21475ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
21485ffd83dbSDimitry Andricvoid atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT
21495ffd83dbSDimitry Andric{
21505ffd83dbSDimitry Andric    __o->notify_one();
21515ffd83dbSDimitry Andric}
21525ffd83dbSDimitry Andric
21535ffd83dbSDimitry Andric// atomic_notify_one
21545ffd83dbSDimitry Andric
21555ffd83dbSDimitry Andrictemplate <class _Tp>
21565ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
21575ffd83dbSDimitry Andricvoid atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT
21585ffd83dbSDimitry Andric{
21595ffd83dbSDimitry Andric    __o->notify_all();
21605ffd83dbSDimitry Andric}
21615ffd83dbSDimitry Andrictemplate <class _Tp>
21625ffd83dbSDimitry Andric_LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
21635ffd83dbSDimitry Andricvoid atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT
21645ffd83dbSDimitry Andric{
21655ffd83dbSDimitry Andric    __o->notify_all();
21665ffd83dbSDimitry Andric}
21675ffd83dbSDimitry Andric
21680b57cec5SDimitry Andric// atomic_fetch_add
21690b57cec5SDimitry Andric
21700b57cec5SDimitry Andrictemplate <class _Tp>
21710b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
21720b57cec5SDimitry Andrictypename enable_if
21730b57cec5SDimitry Andric<
2174*e8d8bef9SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
21750b57cec5SDimitry Andric    _Tp
21760b57cec5SDimitry Andric>::type
2177*e8d8bef9SDimitry Andricatomic_fetch_add(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
21780b57cec5SDimitry Andric{
21790b57cec5SDimitry Andric    return __o->fetch_add(__op);
21800b57cec5SDimitry Andric}
21810b57cec5SDimitry Andric
21820b57cec5SDimitry Andrictemplate <class _Tp>
21830b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
21840b57cec5SDimitry Andrictypename enable_if
21850b57cec5SDimitry Andric<
2186*e8d8bef9SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
21870b57cec5SDimitry Andric    _Tp
21880b57cec5SDimitry Andric>::type
2189*e8d8bef9SDimitry Andricatomic_fetch_add(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
21900b57cec5SDimitry Andric{
21910b57cec5SDimitry Andric    return __o->fetch_add(__op);
21920b57cec5SDimitry Andric}
21930b57cec5SDimitry Andric
21940b57cec5SDimitry Andrictemplate <class _Tp>
21950b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
21960b57cec5SDimitry Andric_Tp*
2197*e8d8bef9SDimitry Andricatomic_fetch_add(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
21980b57cec5SDimitry Andric{
21990b57cec5SDimitry Andric    return __o->fetch_add(__op);
22000b57cec5SDimitry Andric}
22010b57cec5SDimitry Andric
22020b57cec5SDimitry Andrictemplate <class _Tp>
22030b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
22040b57cec5SDimitry Andric_Tp*
2205*e8d8bef9SDimitry Andricatomic_fetch_add(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
22060b57cec5SDimitry Andric{
22070b57cec5SDimitry Andric    return __o->fetch_add(__op);
22080b57cec5SDimitry Andric}
22090b57cec5SDimitry Andric
22100b57cec5SDimitry Andric// atomic_fetch_add_explicit
22110b57cec5SDimitry Andric
22120b57cec5SDimitry Andrictemplate <class _Tp>
22130b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
22140b57cec5SDimitry Andrictypename enable_if
22150b57cec5SDimitry Andric<
2216*e8d8bef9SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
22170b57cec5SDimitry Andric    _Tp
22180b57cec5SDimitry Andric>::type
2219*e8d8bef9SDimitry Andricatomic_fetch_add_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
22200b57cec5SDimitry Andric{
22210b57cec5SDimitry Andric    return __o->fetch_add(__op, __m);
22220b57cec5SDimitry Andric}
22230b57cec5SDimitry Andric
22240b57cec5SDimitry Andrictemplate <class _Tp>
22250b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
22260b57cec5SDimitry Andrictypename enable_if
22270b57cec5SDimitry Andric<
2228*e8d8bef9SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
22290b57cec5SDimitry Andric    _Tp
22300b57cec5SDimitry Andric>::type
2231*e8d8bef9SDimitry Andricatomic_fetch_add_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
22320b57cec5SDimitry Andric{
22330b57cec5SDimitry Andric    return __o->fetch_add(__op, __m);
22340b57cec5SDimitry Andric}
22350b57cec5SDimitry Andric
22360b57cec5SDimitry Andrictemplate <class _Tp>
22370b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
22380b57cec5SDimitry Andric_Tp*
2239*e8d8bef9SDimitry Andricatomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
22400b57cec5SDimitry Andric{
22410b57cec5SDimitry Andric    return __o->fetch_add(__op, __m);
22420b57cec5SDimitry Andric}
22430b57cec5SDimitry Andric
22440b57cec5SDimitry Andrictemplate <class _Tp>
22450b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
22460b57cec5SDimitry Andric_Tp*
2247*e8d8bef9SDimitry Andricatomic_fetch_add_explicit(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
22480b57cec5SDimitry Andric{
22490b57cec5SDimitry Andric    return __o->fetch_add(__op, __m);
22500b57cec5SDimitry Andric}
22510b57cec5SDimitry Andric
22520b57cec5SDimitry Andric// atomic_fetch_sub
22530b57cec5SDimitry Andric
22540b57cec5SDimitry Andrictemplate <class _Tp>
22550b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
22560b57cec5SDimitry Andrictypename enable_if
22570b57cec5SDimitry Andric<
2258*e8d8bef9SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
22590b57cec5SDimitry Andric    _Tp
22600b57cec5SDimitry Andric>::type
2261*e8d8bef9SDimitry Andricatomic_fetch_sub(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
22620b57cec5SDimitry Andric{
22630b57cec5SDimitry Andric    return __o->fetch_sub(__op);
22640b57cec5SDimitry Andric}
22650b57cec5SDimitry Andric
22660b57cec5SDimitry Andrictemplate <class _Tp>
22670b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
22680b57cec5SDimitry Andrictypename enable_if
22690b57cec5SDimitry Andric<
2270*e8d8bef9SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
22710b57cec5SDimitry Andric    _Tp
22720b57cec5SDimitry Andric>::type
2273*e8d8bef9SDimitry Andricatomic_fetch_sub(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op) _NOEXCEPT
22740b57cec5SDimitry Andric{
22750b57cec5SDimitry Andric    return __o->fetch_sub(__op);
22760b57cec5SDimitry Andric}
22770b57cec5SDimitry Andric
22780b57cec5SDimitry Andrictemplate <class _Tp>
22790b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
22800b57cec5SDimitry Andric_Tp*
2281*e8d8bef9SDimitry Andricatomic_fetch_sub(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
22820b57cec5SDimitry Andric{
22830b57cec5SDimitry Andric    return __o->fetch_sub(__op);
22840b57cec5SDimitry Andric}
22850b57cec5SDimitry Andric
22860b57cec5SDimitry Andrictemplate <class _Tp>
22870b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
22880b57cec5SDimitry Andric_Tp*
2289*e8d8bef9SDimitry Andricatomic_fetch_sub(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op) _NOEXCEPT
22900b57cec5SDimitry Andric{
22910b57cec5SDimitry Andric    return __o->fetch_sub(__op);
22920b57cec5SDimitry Andric}
22930b57cec5SDimitry Andric
22940b57cec5SDimitry Andric// atomic_fetch_sub_explicit
22950b57cec5SDimitry Andric
22960b57cec5SDimitry Andrictemplate <class _Tp>
22970b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
22980b57cec5SDimitry Andrictypename enable_if
22990b57cec5SDimitry Andric<
2300*e8d8bef9SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
23010b57cec5SDimitry Andric    _Tp
23020b57cec5SDimitry Andric>::type
2303*e8d8bef9SDimitry Andricatomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
23040b57cec5SDimitry Andric{
23050b57cec5SDimitry Andric    return __o->fetch_sub(__op, __m);
23060b57cec5SDimitry Andric}
23070b57cec5SDimitry Andric
23080b57cec5SDimitry Andrictemplate <class _Tp>
23090b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
23100b57cec5SDimitry Andrictypename enable_if
23110b57cec5SDimitry Andric<
2312*e8d8bef9SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value && !is_const<_Tp>::value,
23130b57cec5SDimitry Andric    _Tp
23140b57cec5SDimitry Andric>::type
2315*e8d8bef9SDimitry Andricatomic_fetch_sub_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::difference_type __op, memory_order __m) _NOEXCEPT
23160b57cec5SDimitry Andric{
23170b57cec5SDimitry Andric    return __o->fetch_sub(__op, __m);
23180b57cec5SDimitry Andric}
23190b57cec5SDimitry Andric
23200b57cec5SDimitry Andrictemplate <class _Tp>
23210b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
23220b57cec5SDimitry Andric_Tp*
2323*e8d8bef9SDimitry Andricatomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
23240b57cec5SDimitry Andric{
23250b57cec5SDimitry Andric    return __o->fetch_sub(__op, __m);
23260b57cec5SDimitry Andric}
23270b57cec5SDimitry Andric
23280b57cec5SDimitry Andrictemplate <class _Tp>
23290b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
23300b57cec5SDimitry Andric_Tp*
2331*e8d8bef9SDimitry Andricatomic_fetch_sub_explicit(atomic<_Tp*>* __o, typename atomic<_Tp*>::difference_type __op, memory_order __m) _NOEXCEPT
23320b57cec5SDimitry Andric{
23330b57cec5SDimitry Andric    return __o->fetch_sub(__op, __m);
23340b57cec5SDimitry Andric}
23350b57cec5SDimitry Andric
23360b57cec5SDimitry Andric// atomic_fetch_and
23370b57cec5SDimitry Andric
23380b57cec5SDimitry Andrictemplate <class _Tp>
23390b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
23400b57cec5SDimitry Andrictypename enable_if
23410b57cec5SDimitry Andric<
23420b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
23430b57cec5SDimitry Andric    _Tp
23440b57cec5SDimitry Andric>::type
2345*e8d8bef9SDimitry Andricatomic_fetch_and(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
23460b57cec5SDimitry Andric{
23470b57cec5SDimitry Andric    return __o->fetch_and(__op);
23480b57cec5SDimitry Andric}
23490b57cec5SDimitry Andric
23500b57cec5SDimitry Andrictemplate <class _Tp>
23510b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
23520b57cec5SDimitry Andrictypename enable_if
23530b57cec5SDimitry Andric<
23540b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
23550b57cec5SDimitry Andric    _Tp
23560b57cec5SDimitry Andric>::type
2357*e8d8bef9SDimitry Andricatomic_fetch_and(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
23580b57cec5SDimitry Andric{
23590b57cec5SDimitry Andric    return __o->fetch_and(__op);
23600b57cec5SDimitry Andric}
23610b57cec5SDimitry Andric
23620b57cec5SDimitry Andric// atomic_fetch_and_explicit
23630b57cec5SDimitry Andric
23640b57cec5SDimitry Andrictemplate <class _Tp>
23650b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
23660b57cec5SDimitry Andrictypename enable_if
23670b57cec5SDimitry Andric<
23680b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
23690b57cec5SDimitry Andric    _Tp
23700b57cec5SDimitry Andric>::type
2371*e8d8bef9SDimitry Andricatomic_fetch_and_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
23720b57cec5SDimitry Andric{
23730b57cec5SDimitry Andric    return __o->fetch_and(__op, __m);
23740b57cec5SDimitry Andric}
23750b57cec5SDimitry Andric
23760b57cec5SDimitry Andrictemplate <class _Tp>
23770b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
23780b57cec5SDimitry Andrictypename enable_if
23790b57cec5SDimitry Andric<
23800b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
23810b57cec5SDimitry Andric    _Tp
23820b57cec5SDimitry Andric>::type
2383*e8d8bef9SDimitry Andricatomic_fetch_and_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
23840b57cec5SDimitry Andric{
23850b57cec5SDimitry Andric    return __o->fetch_and(__op, __m);
23860b57cec5SDimitry Andric}
23870b57cec5SDimitry Andric
23880b57cec5SDimitry Andric// atomic_fetch_or
23890b57cec5SDimitry Andric
23900b57cec5SDimitry Andrictemplate <class _Tp>
23910b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
23920b57cec5SDimitry Andrictypename enable_if
23930b57cec5SDimitry Andric<
23940b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
23950b57cec5SDimitry Andric    _Tp
23960b57cec5SDimitry Andric>::type
2397*e8d8bef9SDimitry Andricatomic_fetch_or(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
23980b57cec5SDimitry Andric{
23990b57cec5SDimitry Andric    return __o->fetch_or(__op);
24000b57cec5SDimitry Andric}
24010b57cec5SDimitry Andric
24020b57cec5SDimitry Andrictemplate <class _Tp>
24030b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
24040b57cec5SDimitry Andrictypename enable_if
24050b57cec5SDimitry Andric<
24060b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
24070b57cec5SDimitry Andric    _Tp
24080b57cec5SDimitry Andric>::type
2409*e8d8bef9SDimitry Andricatomic_fetch_or(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
24100b57cec5SDimitry Andric{
24110b57cec5SDimitry Andric    return __o->fetch_or(__op);
24120b57cec5SDimitry Andric}
24130b57cec5SDimitry Andric
24140b57cec5SDimitry Andric// atomic_fetch_or_explicit
24150b57cec5SDimitry Andric
24160b57cec5SDimitry Andrictemplate <class _Tp>
24170b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
24180b57cec5SDimitry Andrictypename enable_if
24190b57cec5SDimitry Andric<
24200b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
24210b57cec5SDimitry Andric    _Tp
24220b57cec5SDimitry Andric>::type
2423*e8d8bef9SDimitry Andricatomic_fetch_or_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
24240b57cec5SDimitry Andric{
24250b57cec5SDimitry Andric    return __o->fetch_or(__op, __m);
24260b57cec5SDimitry Andric}
24270b57cec5SDimitry Andric
24280b57cec5SDimitry Andrictemplate <class _Tp>
24290b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
24300b57cec5SDimitry Andrictypename enable_if
24310b57cec5SDimitry Andric<
24320b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
24330b57cec5SDimitry Andric    _Tp
24340b57cec5SDimitry Andric>::type
2435*e8d8bef9SDimitry Andricatomic_fetch_or_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
24360b57cec5SDimitry Andric{
24370b57cec5SDimitry Andric    return __o->fetch_or(__op, __m);
24380b57cec5SDimitry Andric}
24390b57cec5SDimitry Andric
24400b57cec5SDimitry Andric// atomic_fetch_xor
24410b57cec5SDimitry Andric
24420b57cec5SDimitry Andrictemplate <class _Tp>
24430b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
24440b57cec5SDimitry Andrictypename enable_if
24450b57cec5SDimitry Andric<
24460b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
24470b57cec5SDimitry Andric    _Tp
24480b57cec5SDimitry Andric>::type
2449*e8d8bef9SDimitry Andricatomic_fetch_xor(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
24500b57cec5SDimitry Andric{
24510b57cec5SDimitry Andric    return __o->fetch_xor(__op);
24520b57cec5SDimitry Andric}
24530b57cec5SDimitry Andric
24540b57cec5SDimitry Andrictemplate <class _Tp>
24550b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
24560b57cec5SDimitry Andrictypename enable_if
24570b57cec5SDimitry Andric<
24580b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
24590b57cec5SDimitry Andric    _Tp
24600b57cec5SDimitry Andric>::type
2461*e8d8bef9SDimitry Andricatomic_fetch_xor(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op) _NOEXCEPT
24620b57cec5SDimitry Andric{
24630b57cec5SDimitry Andric    return __o->fetch_xor(__op);
24640b57cec5SDimitry Andric}
24650b57cec5SDimitry Andric
24660b57cec5SDimitry Andric// atomic_fetch_xor_explicit
24670b57cec5SDimitry Andric
24680b57cec5SDimitry Andrictemplate <class _Tp>
24690b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
24700b57cec5SDimitry Andrictypename enable_if
24710b57cec5SDimitry Andric<
24720b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
24730b57cec5SDimitry Andric    _Tp
24740b57cec5SDimitry Andric>::type
2475*e8d8bef9SDimitry Andricatomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
24760b57cec5SDimitry Andric{
24770b57cec5SDimitry Andric    return __o->fetch_xor(__op, __m);
24780b57cec5SDimitry Andric}
24790b57cec5SDimitry Andric
24800b57cec5SDimitry Andrictemplate <class _Tp>
24810b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
24820b57cec5SDimitry Andrictypename enable_if
24830b57cec5SDimitry Andric<
24840b57cec5SDimitry Andric    is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
24850b57cec5SDimitry Andric    _Tp
24860b57cec5SDimitry Andric>::type
2487*e8d8bef9SDimitry Andricatomic_fetch_xor_explicit(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __op, memory_order __m) _NOEXCEPT
24880b57cec5SDimitry Andric{
24890b57cec5SDimitry Andric    return __o->fetch_xor(__op, __m);
24900b57cec5SDimitry Andric}
24910b57cec5SDimitry Andric
24920b57cec5SDimitry Andric// flag type and operations
24930b57cec5SDimitry Andric
24940b57cec5SDimitry Andrictypedef struct atomic_flag
24950b57cec5SDimitry Andric{
24960b57cec5SDimitry Andric    __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_;
24970b57cec5SDimitry Andric
24980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24995ffd83dbSDimitry Andric    bool test(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
25005ffd83dbSDimitry Andric        {return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m);}
25015ffd83dbSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
25025ffd83dbSDimitry Andric    bool test(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
25035ffd83dbSDimitry Andric        {return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m);}
25045ffd83dbSDimitry Andric
25055ffd83dbSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
25060b57cec5SDimitry Andric    bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
25070b57cec5SDimitry Andric        {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);}
25080b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
25090b57cec5SDimitry Andric    bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
25100b57cec5SDimitry Andric        {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);}
25110b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
25120b57cec5SDimitry Andric    void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
25130b57cec5SDimitry Andric        {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);}
25140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
25150b57cec5SDimitry Andric    void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
25160b57cec5SDimitry Andric        {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);}
25170b57cec5SDimitry Andric
25185ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
25195ffd83dbSDimitry Andric    void wait(bool __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
25205ffd83dbSDimitry Andric        {__cxx_atomic_wait(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);}
25215ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
25225ffd83dbSDimitry Andric    void wait(bool __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT
25235ffd83dbSDimitry Andric        {__cxx_atomic_wait(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);}
25245ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
25255ffd83dbSDimitry Andric    void notify_one() volatile _NOEXCEPT
25265ffd83dbSDimitry Andric        {__cxx_atomic_notify_one(&__a_);}
25275ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
25285ffd83dbSDimitry Andric    void notify_one() _NOEXCEPT
25295ffd83dbSDimitry Andric        {__cxx_atomic_notify_one(&__a_);}
25305ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
25315ffd83dbSDimitry Andric    void notify_all() volatile _NOEXCEPT
25325ffd83dbSDimitry Andric        {__cxx_atomic_notify_all(&__a_);}
25335ffd83dbSDimitry Andric    _LIBCPP_AVAILABILITY_SYNC _LIBCPP_INLINE_VISIBILITY
25345ffd83dbSDimitry Andric    void notify_all() _NOEXCEPT
25355ffd83dbSDimitry Andric        {__cxx_atomic_notify_all(&__a_);}
25365ffd83dbSDimitry Andric
25370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
25380b57cec5SDimitry Andric    atomic_flag() _NOEXCEPT _LIBCPP_DEFAULT
25390b57cec5SDimitry Andric
25400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
25410b57cec5SDimitry Andric    atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
25420b57cec5SDimitry Andric
25430b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
25440b57cec5SDimitry Andric    atomic_flag(const atomic_flag&) = delete;
25450b57cec5SDimitry Andric    atomic_flag& operator=(const atomic_flag&) = delete;
25460b57cec5SDimitry Andric    atomic_flag& operator=(const atomic_flag&) volatile = delete;
25470b57cec5SDimitry Andric#else
25480b57cec5SDimitry Andricprivate:
25495ffd83dbSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
25500b57cec5SDimitry Andric    atomic_flag(const atomic_flag&);
25515ffd83dbSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
25520b57cec5SDimitry Andric    atomic_flag& operator=(const atomic_flag&);
25535ffd83dbSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
25540b57cec5SDimitry Andric    atomic_flag& operator=(const atomic_flag&) volatile;
25550b57cec5SDimitry Andric#endif
25560b57cec5SDimitry Andric} atomic_flag;
25570b57cec5SDimitry Andric
25585ffd83dbSDimitry Andric
25595ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
25605ffd83dbSDimitry Andricbool
25615ffd83dbSDimitry Andricatomic_flag_test(const volatile atomic_flag* __o) _NOEXCEPT
25625ffd83dbSDimitry Andric{
25635ffd83dbSDimitry Andric    return __o->test();
25645ffd83dbSDimitry Andric}
25655ffd83dbSDimitry Andric
25665ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
25675ffd83dbSDimitry Andricbool
25685ffd83dbSDimitry Andricatomic_flag_test(const atomic_flag* __o) _NOEXCEPT
25695ffd83dbSDimitry Andric{
25705ffd83dbSDimitry Andric    return __o->test();
25715ffd83dbSDimitry Andric}
25725ffd83dbSDimitry Andric
25735ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
25745ffd83dbSDimitry Andricbool
25755ffd83dbSDimitry Andricatomic_flag_test_explicit(const volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
25765ffd83dbSDimitry Andric{
25775ffd83dbSDimitry Andric    return __o->test(__m);
25785ffd83dbSDimitry Andric}
25795ffd83dbSDimitry Andric
25805ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
25815ffd83dbSDimitry Andricbool
25825ffd83dbSDimitry Andricatomic_flag_test_explicit(const atomic_flag* __o, memory_order __m) _NOEXCEPT
25835ffd83dbSDimitry Andric{
25845ffd83dbSDimitry Andric    return __o->test(__m);
25855ffd83dbSDimitry Andric}
25865ffd83dbSDimitry Andric
25870b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
25880b57cec5SDimitry Andricbool
25890b57cec5SDimitry Andricatomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
25900b57cec5SDimitry Andric{
25910b57cec5SDimitry Andric    return __o->test_and_set();
25920b57cec5SDimitry Andric}
25930b57cec5SDimitry Andric
25940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
25950b57cec5SDimitry Andricbool
25960b57cec5SDimitry Andricatomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
25970b57cec5SDimitry Andric{
25980b57cec5SDimitry Andric    return __o->test_and_set();
25990b57cec5SDimitry Andric}
26000b57cec5SDimitry Andric
26010b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
26020b57cec5SDimitry Andricbool
26030b57cec5SDimitry Andricatomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
26040b57cec5SDimitry Andric{
26050b57cec5SDimitry Andric    return __o->test_and_set(__m);
26060b57cec5SDimitry Andric}
26070b57cec5SDimitry Andric
26080b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
26090b57cec5SDimitry Andricbool
26100b57cec5SDimitry Andricatomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
26110b57cec5SDimitry Andric{
26120b57cec5SDimitry Andric    return __o->test_and_set(__m);
26130b57cec5SDimitry Andric}
26140b57cec5SDimitry Andric
26150b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
26160b57cec5SDimitry Andricvoid
26170b57cec5SDimitry Andricatomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
26180b57cec5SDimitry Andric{
26190b57cec5SDimitry Andric    __o->clear();
26200b57cec5SDimitry Andric}
26210b57cec5SDimitry Andric
26220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
26230b57cec5SDimitry Andricvoid
26240b57cec5SDimitry Andricatomic_flag_clear(atomic_flag* __o) _NOEXCEPT
26250b57cec5SDimitry Andric{
26260b57cec5SDimitry Andric    __o->clear();
26270b57cec5SDimitry Andric}
26280b57cec5SDimitry Andric
26290b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
26300b57cec5SDimitry Andricvoid
26310b57cec5SDimitry Andricatomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
26320b57cec5SDimitry Andric{
26330b57cec5SDimitry Andric    __o->clear(__m);
26340b57cec5SDimitry Andric}
26350b57cec5SDimitry Andric
26360b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
26370b57cec5SDimitry Andricvoid
26380b57cec5SDimitry Andricatomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
26390b57cec5SDimitry Andric{
26400b57cec5SDimitry Andric    __o->clear(__m);
26410b57cec5SDimitry Andric}
26420b57cec5SDimitry Andric
26435ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
26445ffd83dbSDimitry Andricvoid
26455ffd83dbSDimitry Andricatomic_flag_wait(const volatile atomic_flag* __o, bool __v) _NOEXCEPT
26465ffd83dbSDimitry Andric{
26475ffd83dbSDimitry Andric    __o->wait(__v);
26485ffd83dbSDimitry Andric}
26495ffd83dbSDimitry Andric
26505ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
26515ffd83dbSDimitry Andricvoid
26525ffd83dbSDimitry Andricatomic_flag_wait(const atomic_flag* __o, bool __v) _NOEXCEPT
26535ffd83dbSDimitry Andric{
26545ffd83dbSDimitry Andric    __o->wait(__v);
26555ffd83dbSDimitry Andric}
26565ffd83dbSDimitry Andric
26575ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
26585ffd83dbSDimitry Andricvoid
26595ffd83dbSDimitry Andricatomic_flag_wait_explicit(const volatile atomic_flag* __o,
26605ffd83dbSDimitry Andric                          bool __v, memory_order __m) _NOEXCEPT
26615ffd83dbSDimitry Andric{
26625ffd83dbSDimitry Andric    __o->wait(__v, __m);
26635ffd83dbSDimitry Andric}
26645ffd83dbSDimitry Andric
26655ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
26665ffd83dbSDimitry Andricvoid
26675ffd83dbSDimitry Andricatomic_flag_wait_explicit(const atomic_flag* __o,
26685ffd83dbSDimitry Andric                          bool __v, memory_order __m) _NOEXCEPT
26695ffd83dbSDimitry Andric{
26705ffd83dbSDimitry Andric    __o->wait(__v, __m);
26715ffd83dbSDimitry Andric}
26725ffd83dbSDimitry Andric
26735ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
26745ffd83dbSDimitry Andricvoid
26755ffd83dbSDimitry Andricatomic_flag_notify_one(volatile atomic_flag* __o) _NOEXCEPT
26765ffd83dbSDimitry Andric{
26775ffd83dbSDimitry Andric    __o->notify_one();
26785ffd83dbSDimitry Andric}
26795ffd83dbSDimitry Andric
26805ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
26815ffd83dbSDimitry Andricvoid
26825ffd83dbSDimitry Andricatomic_flag_notify_one(atomic_flag* __o) _NOEXCEPT
26835ffd83dbSDimitry Andric{
26845ffd83dbSDimitry Andric    __o->notify_one();
26855ffd83dbSDimitry Andric}
26865ffd83dbSDimitry Andric
26875ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
26885ffd83dbSDimitry Andricvoid
26895ffd83dbSDimitry Andricatomic_flag_notify_all(volatile atomic_flag* __o) _NOEXCEPT
26905ffd83dbSDimitry Andric{
26915ffd83dbSDimitry Andric    __o->notify_all();
26925ffd83dbSDimitry Andric}
26935ffd83dbSDimitry Andric
26945ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_SYNC
26955ffd83dbSDimitry Andricvoid
26965ffd83dbSDimitry Andricatomic_flag_notify_all(atomic_flag* __o) _NOEXCEPT
26975ffd83dbSDimitry Andric{
26985ffd83dbSDimitry Andric    __o->notify_all();
26995ffd83dbSDimitry Andric}
27005ffd83dbSDimitry Andric
27010b57cec5SDimitry Andric// fences
27020b57cec5SDimitry Andric
27030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
27040b57cec5SDimitry Andricvoid
27050b57cec5SDimitry Andricatomic_thread_fence(memory_order __m) _NOEXCEPT
27060b57cec5SDimitry Andric{
27070b57cec5SDimitry Andric    __cxx_atomic_thread_fence(__m);
27080b57cec5SDimitry Andric}
27090b57cec5SDimitry Andric
27100b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
27110b57cec5SDimitry Andricvoid
27120b57cec5SDimitry Andricatomic_signal_fence(memory_order __m) _NOEXCEPT
27130b57cec5SDimitry Andric{
27140b57cec5SDimitry Andric    __cxx_atomic_signal_fence(__m);
27150b57cec5SDimitry Andric}
27160b57cec5SDimitry Andric
27170b57cec5SDimitry Andric// Atomics for standard typedef types
27180b57cec5SDimitry Andric
27190b57cec5SDimitry Andrictypedef atomic<bool>               atomic_bool;
27200b57cec5SDimitry Andrictypedef atomic<char>               atomic_char;
27210b57cec5SDimitry Andrictypedef atomic<signed char>        atomic_schar;
27220b57cec5SDimitry Andrictypedef atomic<unsigned char>      atomic_uchar;
27230b57cec5SDimitry Andrictypedef atomic<short>              atomic_short;
27240b57cec5SDimitry Andrictypedef atomic<unsigned short>     atomic_ushort;
27250b57cec5SDimitry Andrictypedef atomic<int>                atomic_int;
27260b57cec5SDimitry Andrictypedef atomic<unsigned int>       atomic_uint;
27270b57cec5SDimitry Andrictypedef atomic<long>               atomic_long;
27280b57cec5SDimitry Andrictypedef atomic<unsigned long>      atomic_ulong;
27290b57cec5SDimitry Andrictypedef atomic<long long>          atomic_llong;
27300b57cec5SDimitry Andrictypedef atomic<unsigned long long> atomic_ullong;
2731*e8d8bef9SDimitry Andric#ifndef _LIBCPP_NO_HAS_CHAR8_T
2732*e8d8bef9SDimitry Andrictypedef atomic<char8_t>            atomic_char8_t;
2733*e8d8bef9SDimitry Andric#endif
27340b57cec5SDimitry Andrictypedef atomic<char16_t>           atomic_char16_t;
27350b57cec5SDimitry Andrictypedef atomic<char32_t>           atomic_char32_t;
27360b57cec5SDimitry Andrictypedef atomic<wchar_t>            atomic_wchar_t;
27370b57cec5SDimitry Andric
27380b57cec5SDimitry Andrictypedef atomic<int_least8_t>   atomic_int_least8_t;
27390b57cec5SDimitry Andrictypedef atomic<uint_least8_t>  atomic_uint_least8_t;
27400b57cec5SDimitry Andrictypedef atomic<int_least16_t>  atomic_int_least16_t;
27410b57cec5SDimitry Andrictypedef atomic<uint_least16_t> atomic_uint_least16_t;
27420b57cec5SDimitry Andrictypedef atomic<int_least32_t>  atomic_int_least32_t;
27430b57cec5SDimitry Andrictypedef atomic<uint_least32_t> atomic_uint_least32_t;
27440b57cec5SDimitry Andrictypedef atomic<int_least64_t>  atomic_int_least64_t;
27450b57cec5SDimitry Andrictypedef atomic<uint_least64_t> atomic_uint_least64_t;
27460b57cec5SDimitry Andric
27470b57cec5SDimitry Andrictypedef atomic<int_fast8_t>   atomic_int_fast8_t;
27480b57cec5SDimitry Andrictypedef atomic<uint_fast8_t>  atomic_uint_fast8_t;
27490b57cec5SDimitry Andrictypedef atomic<int_fast16_t>  atomic_int_fast16_t;
27500b57cec5SDimitry Andrictypedef atomic<uint_fast16_t> atomic_uint_fast16_t;
27510b57cec5SDimitry Andrictypedef atomic<int_fast32_t>  atomic_int_fast32_t;
27520b57cec5SDimitry Andrictypedef atomic<uint_fast32_t> atomic_uint_fast32_t;
27530b57cec5SDimitry Andrictypedef atomic<int_fast64_t>  atomic_int_fast64_t;
27540b57cec5SDimitry Andrictypedef atomic<uint_fast64_t> atomic_uint_fast64_t;
27550b57cec5SDimitry Andric
27560b57cec5SDimitry Andrictypedef atomic< int8_t>  atomic_int8_t;
27570b57cec5SDimitry Andrictypedef atomic<uint8_t>  atomic_uint8_t;
27580b57cec5SDimitry Andrictypedef atomic< int16_t> atomic_int16_t;
27590b57cec5SDimitry Andrictypedef atomic<uint16_t> atomic_uint16_t;
27600b57cec5SDimitry Andrictypedef atomic< int32_t> atomic_int32_t;
27610b57cec5SDimitry Andrictypedef atomic<uint32_t> atomic_uint32_t;
27620b57cec5SDimitry Andrictypedef atomic< int64_t> atomic_int64_t;
27630b57cec5SDimitry Andrictypedef atomic<uint64_t> atomic_uint64_t;
27640b57cec5SDimitry Andric
27650b57cec5SDimitry Andrictypedef atomic<intptr_t>  atomic_intptr_t;
27660b57cec5SDimitry Andrictypedef atomic<uintptr_t> atomic_uintptr_t;
27670b57cec5SDimitry Andrictypedef atomic<size_t>    atomic_size_t;
27680b57cec5SDimitry Andrictypedef atomic<ptrdiff_t> atomic_ptrdiff_t;
27690b57cec5SDimitry Andrictypedef atomic<intmax_t>  atomic_intmax_t;
27700b57cec5SDimitry Andrictypedef atomic<uintmax_t> atomic_uintmax_t;
27710b57cec5SDimitry Andric
27725ffd83dbSDimitry Andric// atomic_*_lock_free : prefer the contention type most highly, then the largest lock-free type
27735ffd83dbSDimitry Andric
27745ffd83dbSDimitry Andric#ifdef __cpp_lib_atomic_is_always_lock_free
27755ffd83dbSDimitry Andric# define _LIBCPP_CONTENTION_LOCK_FREE __atomic_always_lock_free(sizeof(__cxx_contention_t), 0)
27765ffd83dbSDimitry Andric#else
27775ffd83dbSDimitry Andric# define _LIBCPP_CONTENTION_LOCK_FREE false
27785ffd83dbSDimitry Andric#endif
27795ffd83dbSDimitry Andric
27805ffd83dbSDimitry Andric#if ATOMIC_LLONG_LOCK_FREE == 2
27815ffd83dbSDimitry Andrictypedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, long long>::type          __libcpp_signed_lock_free;
27825ffd83dbSDimitry Andrictypedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned long long>::type __libcpp_unsigned_lock_free;
27835ffd83dbSDimitry Andric#elif ATOMIC_INT_LOCK_FREE == 2
27845ffd83dbSDimitry Andrictypedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, int>::type                __libcpp_signed_lock_free;
27855ffd83dbSDimitry Andrictypedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned int>::type       __libcpp_unsigned_lock_free;
27865ffd83dbSDimitry Andric#elif ATOMIC_SHORT_LOCK_FREE == 2
27875ffd83dbSDimitry Andrictypedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, short>::type              __libcpp_signed_lock_free;
27885ffd83dbSDimitry Andrictypedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned short>::type     __libcpp_unsigned_lock_free;
27895ffd83dbSDimitry Andric#elif ATOMIC_CHAR_LOCK_FREE == 2
27905ffd83dbSDimitry Andrictypedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, char>::type               __libcpp_signed_lock_free;
27915ffd83dbSDimitry Andrictypedef conditional<_LIBCPP_CONTENTION_LOCK_FREE, __cxx_contention_t, unsigned char>::type      __libcpp_unsigned_lock_free;
27925ffd83dbSDimitry Andric#else
27935ffd83dbSDimitry Andric    // No signed/unsigned lock-free types
27945ffd83dbSDimitry Andric#endif
27955ffd83dbSDimitry Andric
27965ffd83dbSDimitry Andrictypedef atomic<__libcpp_signed_lock_free> atomic_signed_lock_free;
27975ffd83dbSDimitry Andrictypedef atomic<__libcpp_unsigned_lock_free> atomic_unsigned_lock_free;
27985ffd83dbSDimitry Andric
27990b57cec5SDimitry Andric#define ATOMIC_FLAG_INIT {false}
28000b57cec5SDimitry Andric#define ATOMIC_VAR_INIT(__v) {__v}
28010b57cec5SDimitry Andric
28020b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
28030b57cec5SDimitry Andric
28040b57cec5SDimitry Andric#endif  // _LIBCPP_ATOMIC
2805