1*81ad6265SDimitry Andric // -*- C++ -*- 2*81ad6265SDimitry Andric //===----------------------------------------------------------------------===// 3*81ad6265SDimitry Andric // 4*81ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*81ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 6*81ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*81ad6265SDimitry Andric // 8*81ad6265SDimitry Andric //===----------------------------------------------------------------------===// 9*81ad6265SDimitry Andric 10*81ad6265SDimitry Andric #ifndef _LIBCPP_STDATOMIC_H 11*81ad6265SDimitry Andric #define _LIBCPP_STDATOMIC_H 12*81ad6265SDimitry Andric 13*81ad6265SDimitry Andric /* 14*81ad6265SDimitry Andric stdatomic.h synopsis 15*81ad6265SDimitry Andric 16*81ad6265SDimitry Andric template<class T> 17*81ad6265SDimitry Andric using std-atomic = std::atomic<T>; // exposition only 18*81ad6265SDimitry Andric 19*81ad6265SDimitry Andric #define _Atomic(T) std-atomic<T> 20*81ad6265SDimitry Andric 21*81ad6265SDimitry Andric #define ATOMIC_BOOL_LOCK_FREE see below 22*81ad6265SDimitry Andric #define ATOMIC_CHAR_LOCK_FREE see below 23*81ad6265SDimitry Andric #define ATOMIC_CHAR16_T_LOCK_FREE see below 24*81ad6265SDimitry Andric #define ATOMIC_CHAR32_T_LOCK_FREE see below 25*81ad6265SDimitry Andric #define ATOMIC_WCHAR_T_LOCK_FREE see below 26*81ad6265SDimitry Andric #define ATOMIC_SHORT_LOCK_FREE see below 27*81ad6265SDimitry Andric #define ATOMIC_INT_LOCK_FREE see below 28*81ad6265SDimitry Andric #define ATOMIC_LONG_LOCK_FREE see below 29*81ad6265SDimitry Andric #define ATOMIC_LLONG_LOCK_FREE see below 30*81ad6265SDimitry Andric #define ATOMIC_POINTER_LOCK_FREE see below 31*81ad6265SDimitry Andric 32*81ad6265SDimitry Andric using std::memory_order // see below 33*81ad6265SDimitry Andric using std::memory_order_relaxed // see below 34*81ad6265SDimitry Andric using std::memory_order_consume // see below 35*81ad6265SDimitry Andric using std::memory_order_acquire // see below 36*81ad6265SDimitry Andric using std::memory_order_release // see below 37*81ad6265SDimitry Andric using std::memory_order_acq_rel // see below 38*81ad6265SDimitry Andric using std::memory_order_seq_cst // see below 39*81ad6265SDimitry Andric 40*81ad6265SDimitry Andric using std::atomic_flag // see below 41*81ad6265SDimitry Andric 42*81ad6265SDimitry Andric using std::atomic_bool // see below 43*81ad6265SDimitry Andric using std::atomic_char // see below 44*81ad6265SDimitry Andric using std::atomic_schar // see below 45*81ad6265SDimitry Andric using std::atomic_uchar // see below 46*81ad6265SDimitry Andric using std::atomic_short // see below 47*81ad6265SDimitry Andric using std::atomic_ushort // see below 48*81ad6265SDimitry Andric using std::atomic_int // see below 49*81ad6265SDimitry Andric using std::atomic_uint // see below 50*81ad6265SDimitry Andric using std::atomic_long // see below 51*81ad6265SDimitry Andric using std::atomic_ulong // see below 52*81ad6265SDimitry Andric using std::atomic_llong // see below 53*81ad6265SDimitry Andric using std::atomic_ullong // see below 54*81ad6265SDimitry Andric using std::atomic_char8_t // see below 55*81ad6265SDimitry Andric using std::atomic_char16_t // see below 56*81ad6265SDimitry Andric using std::atomic_char32_t // see below 57*81ad6265SDimitry Andric using std::atomic_wchar_t // see below 58*81ad6265SDimitry Andric using std::atomic_int8_t // see below 59*81ad6265SDimitry Andric using std::atomic_uint8_t // see below 60*81ad6265SDimitry Andric using std::atomic_int16_t // see below 61*81ad6265SDimitry Andric using std::atomic_uint16_t // see below 62*81ad6265SDimitry Andric using std::atomic_int32_t // see below 63*81ad6265SDimitry Andric using std::atomic_uint32_t // see below 64*81ad6265SDimitry Andric using std::atomic_int64_t // see below 65*81ad6265SDimitry Andric using std::atomic_uint64_t // see below 66*81ad6265SDimitry Andric using std::atomic_int_least8_t // see below 67*81ad6265SDimitry Andric using std::atomic_uint_least8_t // see below 68*81ad6265SDimitry Andric using std::atomic_int_least16_t // see below 69*81ad6265SDimitry Andric using std::atomic_uint_least16_t // see below 70*81ad6265SDimitry Andric using std::atomic_int_least32_t // see below 71*81ad6265SDimitry Andric using std::atomic_uint_least32_t // see below 72*81ad6265SDimitry Andric using std::atomic_int_least64_t // see below 73*81ad6265SDimitry Andric using std::atomic_uint_least64_t // see below 74*81ad6265SDimitry Andric using std::atomic_int_fast8_t // see below 75*81ad6265SDimitry Andric using std::atomic_uint_fast8_t // see below 76*81ad6265SDimitry Andric using std::atomic_int_fast16_t // see below 77*81ad6265SDimitry Andric using std::atomic_uint_fast16_t // see below 78*81ad6265SDimitry Andric using std::atomic_int_fast32_t // see below 79*81ad6265SDimitry Andric using std::atomic_uint_fast32_t // see below 80*81ad6265SDimitry Andric using std::atomic_int_fast64_t // see below 81*81ad6265SDimitry Andric using std::atomic_uint_fast64_t // see below 82*81ad6265SDimitry Andric using std::atomic_intptr_t // see below 83*81ad6265SDimitry Andric using std::atomic_uintptr_t // see below 84*81ad6265SDimitry Andric using std::atomic_size_t // see below 85*81ad6265SDimitry Andric using std::atomic_ptrdiff_t // see below 86*81ad6265SDimitry Andric using std::atomic_intmax_t // see below 87*81ad6265SDimitry Andric using std::atomic_uintmax_t // see below 88*81ad6265SDimitry Andric 89*81ad6265SDimitry Andric using std::atomic_is_lock_free // see below 90*81ad6265SDimitry Andric using std::atomic_load // see below 91*81ad6265SDimitry Andric using std::atomic_load_explicit // see below 92*81ad6265SDimitry Andric using std::atomic_store // see below 93*81ad6265SDimitry Andric using std::atomic_store_explicit // see below 94*81ad6265SDimitry Andric using std::atomic_exchange // see below 95*81ad6265SDimitry Andric using std::atomic_exchange_explicit // see below 96*81ad6265SDimitry Andric using std::atomic_compare_exchange_strong // see below 97*81ad6265SDimitry Andric using std::atomic_compare_exchange_strong_explicit // see below 98*81ad6265SDimitry Andric using std::atomic_compare_exchange_weak // see below 99*81ad6265SDimitry Andric using std::atomic_compare_exchange_weak_explicit // see below 100*81ad6265SDimitry Andric using std::atomic_fetch_add // see below 101*81ad6265SDimitry Andric using std::atomic_fetch_add_explicit // see below 102*81ad6265SDimitry Andric using std::atomic_fetch_sub // see below 103*81ad6265SDimitry Andric using std::atomic_fetch_sub_explicit // see below 104*81ad6265SDimitry Andric using std::atomic_fetch_or // see below 105*81ad6265SDimitry Andric using std::atomic_fetch_or_explicit // see below 106*81ad6265SDimitry Andric using std::atomic_fetch_and // see below 107*81ad6265SDimitry Andric using std::atomic_fetch_and_explicit // see below 108*81ad6265SDimitry Andric using std::atomic_flag_test_and_set // see below 109*81ad6265SDimitry Andric using std::atomic_flag_test_and_set_explicit // see below 110*81ad6265SDimitry Andric using std::atomic_flag_clear // see below 111*81ad6265SDimitry Andric using std::atomic_flag_clear_explicit // see below 112*81ad6265SDimitry Andric 113*81ad6265SDimitry Andric using std::atomic_thread_fence // see below 114*81ad6265SDimitry Andric using std::atomic_signal_fence // see below 115*81ad6265SDimitry Andric 116*81ad6265SDimitry Andric */ 117*81ad6265SDimitry Andric 118*81ad6265SDimitry Andric #include <__config> 119*81ad6265SDimitry Andric 120*81ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 121*81ad6265SDimitry Andric # pragma GCC system_header 122*81ad6265SDimitry Andric #endif 123*81ad6265SDimitry Andric 124*81ad6265SDimitry Andric #if _LIBCPP_STD_VER > 20 125*81ad6265SDimitry Andric 126*81ad6265SDimitry Andric #include <atomic> 127*81ad6265SDimitry Andric #include <version> 128*81ad6265SDimitry Andric 129*81ad6265SDimitry Andric #ifdef _Atomic 130*81ad6265SDimitry Andric # undef _Atomic 131*81ad6265SDimitry Andric #endif 132*81ad6265SDimitry Andric 133*81ad6265SDimitry Andric #define _Atomic(_Tp) ::std::atomic<_Tp> 134*81ad6265SDimitry Andric 135*81ad6265SDimitry Andric using std::memory_order _LIBCPP_USING_IF_EXISTS; 136*81ad6265SDimitry Andric using std::memory_order_relaxed _LIBCPP_USING_IF_EXISTS; 137*81ad6265SDimitry Andric using std::memory_order_consume _LIBCPP_USING_IF_EXISTS; 138*81ad6265SDimitry Andric using std::memory_order_acquire _LIBCPP_USING_IF_EXISTS; 139*81ad6265SDimitry Andric using std::memory_order_release _LIBCPP_USING_IF_EXISTS; 140*81ad6265SDimitry Andric using std::memory_order_acq_rel _LIBCPP_USING_IF_EXISTS; 141*81ad6265SDimitry Andric using std::memory_order_seq_cst _LIBCPP_USING_IF_EXISTS; 142*81ad6265SDimitry Andric 143*81ad6265SDimitry Andric using std::atomic_flag _LIBCPP_USING_IF_EXISTS; 144*81ad6265SDimitry Andric 145*81ad6265SDimitry Andric using std::atomic_bool _LIBCPP_USING_IF_EXISTS; 146*81ad6265SDimitry Andric using std::atomic_char _LIBCPP_USING_IF_EXISTS; 147*81ad6265SDimitry Andric using std::atomic_schar _LIBCPP_USING_IF_EXISTS; 148*81ad6265SDimitry Andric using std::atomic_uchar _LIBCPP_USING_IF_EXISTS; 149*81ad6265SDimitry Andric using std::atomic_short _LIBCPP_USING_IF_EXISTS; 150*81ad6265SDimitry Andric using std::atomic_ushort _LIBCPP_USING_IF_EXISTS; 151*81ad6265SDimitry Andric using std::atomic_int _LIBCPP_USING_IF_EXISTS; 152*81ad6265SDimitry Andric using std::atomic_uint _LIBCPP_USING_IF_EXISTS; 153*81ad6265SDimitry Andric using std::atomic_long _LIBCPP_USING_IF_EXISTS; 154*81ad6265SDimitry Andric using std::atomic_ulong _LIBCPP_USING_IF_EXISTS; 155*81ad6265SDimitry Andric using std::atomic_llong _LIBCPP_USING_IF_EXISTS; 156*81ad6265SDimitry Andric using std::atomic_ullong _LIBCPP_USING_IF_EXISTS; 157*81ad6265SDimitry Andric using std::atomic_char8_t _LIBCPP_USING_IF_EXISTS; 158*81ad6265SDimitry Andric using std::atomic_char16_t _LIBCPP_USING_IF_EXISTS; 159*81ad6265SDimitry Andric using std::atomic_char32_t _LIBCPP_USING_IF_EXISTS; 160*81ad6265SDimitry Andric using std::atomic_wchar_t _LIBCPP_USING_IF_EXISTS; 161*81ad6265SDimitry Andric 162*81ad6265SDimitry Andric using std::atomic_int8_t _LIBCPP_USING_IF_EXISTS; 163*81ad6265SDimitry Andric using std::atomic_uint8_t _LIBCPP_USING_IF_EXISTS; 164*81ad6265SDimitry Andric using std::atomic_int16_t _LIBCPP_USING_IF_EXISTS; 165*81ad6265SDimitry Andric using std::atomic_uint16_t _LIBCPP_USING_IF_EXISTS; 166*81ad6265SDimitry Andric using std::atomic_int32_t _LIBCPP_USING_IF_EXISTS; 167*81ad6265SDimitry Andric using std::atomic_uint32_t _LIBCPP_USING_IF_EXISTS; 168*81ad6265SDimitry Andric using std::atomic_int64_t _LIBCPP_USING_IF_EXISTS; 169*81ad6265SDimitry Andric using std::atomic_uint64_t _LIBCPP_USING_IF_EXISTS; 170*81ad6265SDimitry Andric 171*81ad6265SDimitry Andric using std::atomic_int_least8_t _LIBCPP_USING_IF_EXISTS; 172*81ad6265SDimitry Andric using std::atomic_uint_least8_t _LIBCPP_USING_IF_EXISTS; 173*81ad6265SDimitry Andric using std::atomic_int_least16_t _LIBCPP_USING_IF_EXISTS; 174*81ad6265SDimitry Andric using std::atomic_uint_least16_t _LIBCPP_USING_IF_EXISTS; 175*81ad6265SDimitry Andric using std::atomic_int_least32_t _LIBCPP_USING_IF_EXISTS; 176*81ad6265SDimitry Andric using std::atomic_uint_least32_t _LIBCPP_USING_IF_EXISTS; 177*81ad6265SDimitry Andric using std::atomic_int_least64_t _LIBCPP_USING_IF_EXISTS; 178*81ad6265SDimitry Andric using std::atomic_uint_least64_t _LIBCPP_USING_IF_EXISTS; 179*81ad6265SDimitry Andric 180*81ad6265SDimitry Andric using std::atomic_int_fast8_t _LIBCPP_USING_IF_EXISTS; 181*81ad6265SDimitry Andric using std::atomic_uint_fast8_t _LIBCPP_USING_IF_EXISTS; 182*81ad6265SDimitry Andric using std::atomic_int_fast16_t _LIBCPP_USING_IF_EXISTS; 183*81ad6265SDimitry Andric using std::atomic_uint_fast16_t _LIBCPP_USING_IF_EXISTS; 184*81ad6265SDimitry Andric using std::atomic_int_fast32_t _LIBCPP_USING_IF_EXISTS; 185*81ad6265SDimitry Andric using std::atomic_uint_fast32_t _LIBCPP_USING_IF_EXISTS; 186*81ad6265SDimitry Andric using std::atomic_int_fast64_t _LIBCPP_USING_IF_EXISTS; 187*81ad6265SDimitry Andric using std::atomic_uint_fast64_t _LIBCPP_USING_IF_EXISTS; 188*81ad6265SDimitry Andric 189*81ad6265SDimitry Andric using std::atomic_intptr_t _LIBCPP_USING_IF_EXISTS; 190*81ad6265SDimitry Andric using std::atomic_uintptr_t _LIBCPP_USING_IF_EXISTS; 191*81ad6265SDimitry Andric using std::atomic_size_t _LIBCPP_USING_IF_EXISTS; 192*81ad6265SDimitry Andric using std::atomic_ptrdiff_t _LIBCPP_USING_IF_EXISTS; 193*81ad6265SDimitry Andric using std::atomic_intmax_t _LIBCPP_USING_IF_EXISTS; 194*81ad6265SDimitry Andric using std::atomic_uintmax_t _LIBCPP_USING_IF_EXISTS; 195*81ad6265SDimitry Andric 196*81ad6265SDimitry Andric using std::atomic_compare_exchange_strong _LIBCPP_USING_IF_EXISTS; 197*81ad6265SDimitry Andric using std::atomic_compare_exchange_strong_explicit _LIBCPP_USING_IF_EXISTS; 198*81ad6265SDimitry Andric using std::atomic_compare_exchange_weak _LIBCPP_USING_IF_EXISTS; 199*81ad6265SDimitry Andric using std::atomic_compare_exchange_weak_explicit _LIBCPP_USING_IF_EXISTS; 200*81ad6265SDimitry Andric using std::atomic_exchange _LIBCPP_USING_IF_EXISTS; 201*81ad6265SDimitry Andric using std::atomic_exchange_explicit _LIBCPP_USING_IF_EXISTS; 202*81ad6265SDimitry Andric using std::atomic_fetch_add _LIBCPP_USING_IF_EXISTS; 203*81ad6265SDimitry Andric using std::atomic_fetch_add_explicit _LIBCPP_USING_IF_EXISTS; 204*81ad6265SDimitry Andric using std::atomic_fetch_and _LIBCPP_USING_IF_EXISTS; 205*81ad6265SDimitry Andric using std::atomic_fetch_and_explicit _LIBCPP_USING_IF_EXISTS; 206*81ad6265SDimitry Andric using std::atomic_fetch_or _LIBCPP_USING_IF_EXISTS; 207*81ad6265SDimitry Andric using std::atomic_fetch_or_explicit _LIBCPP_USING_IF_EXISTS; 208*81ad6265SDimitry Andric using std::atomic_fetch_sub _LIBCPP_USING_IF_EXISTS; 209*81ad6265SDimitry Andric using std::atomic_fetch_sub_explicit _LIBCPP_USING_IF_EXISTS; 210*81ad6265SDimitry Andric using std::atomic_flag_clear _LIBCPP_USING_IF_EXISTS; 211*81ad6265SDimitry Andric using std::atomic_flag_clear_explicit _LIBCPP_USING_IF_EXISTS; 212*81ad6265SDimitry Andric using std::atomic_flag_test_and_set _LIBCPP_USING_IF_EXISTS; 213*81ad6265SDimitry Andric using std::atomic_flag_test_and_set_explicit _LIBCPP_USING_IF_EXISTS; 214*81ad6265SDimitry Andric using std::atomic_is_lock_free _LIBCPP_USING_IF_EXISTS; 215*81ad6265SDimitry Andric using std::atomic_load _LIBCPP_USING_IF_EXISTS; 216*81ad6265SDimitry Andric using std::atomic_load_explicit _LIBCPP_USING_IF_EXISTS; 217*81ad6265SDimitry Andric using std::atomic_store _LIBCPP_USING_IF_EXISTS; 218*81ad6265SDimitry Andric using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS; 219*81ad6265SDimitry Andric 220*81ad6265SDimitry Andric using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS; 221*81ad6265SDimitry Andric using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS; 222*81ad6265SDimitry Andric 223*81ad6265SDimitry Andric #elif defined(_LIBCPP_COMPILER_CLANG_BASED) 224*81ad6265SDimitry Andric 225*81ad6265SDimitry Andric // Before C++23, we include the next <stdatomic.h> on the path to avoid hijacking 226*81ad6265SDimitry Andric // the header. We do this because Clang has historically shipped a <stdatomic.h> 227*81ad6265SDimitry Andric // header that would be available in all Standard modes, and we don't want to 228*81ad6265SDimitry Andric // break that use case. 229*81ad6265SDimitry Andric # if __has_include_next(<stdatomic.h>) 230*81ad6265SDimitry Andric # include_next <stdatomic.h> 231*81ad6265SDimitry Andric # endif 232*81ad6265SDimitry Andric 233*81ad6265SDimitry Andric #endif // _LIBCPP_STD_VER > 20 234*81ad6265SDimitry Andric 235*81ad6265SDimitry Andric #endif // _LIBCPP_STDATOMIC_H 236