181ad6265SDimitry Andric // -*- C++ -*-
281ad6265SDimitry Andric //===----------------------------------------------------------------------===//
381ad6265SDimitry Andric //
481ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
581ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
681ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
781ad6265SDimitry Andric //
881ad6265SDimitry Andric //===----------------------------------------------------------------------===//
981ad6265SDimitry Andric 
1081ad6265SDimitry Andric #ifndef _LIBCPP_STDATOMIC_H
1181ad6265SDimitry Andric #define _LIBCPP_STDATOMIC_H
1281ad6265SDimitry Andric 
1381ad6265SDimitry Andric /*
1481ad6265SDimitry Andric     stdatomic.h synopsis
1581ad6265SDimitry Andric 
1681ad6265SDimitry Andric template<class T>
1781ad6265SDimitry Andric   using std-atomic = std::atomic<T>;        // exposition only
1881ad6265SDimitry Andric 
1981ad6265SDimitry Andric #define _Atomic(T) std-atomic<T>
2081ad6265SDimitry Andric 
2181ad6265SDimitry Andric #define ATOMIC_BOOL_LOCK_FREE see below
2281ad6265SDimitry Andric #define ATOMIC_CHAR_LOCK_FREE see below
2381ad6265SDimitry Andric #define ATOMIC_CHAR16_T_LOCK_FREE see below
2481ad6265SDimitry Andric #define ATOMIC_CHAR32_T_LOCK_FREE see below
2581ad6265SDimitry Andric #define ATOMIC_WCHAR_T_LOCK_FREE see below
2681ad6265SDimitry Andric #define ATOMIC_SHORT_LOCK_FREE see below
2781ad6265SDimitry Andric #define ATOMIC_INT_LOCK_FREE see below
2881ad6265SDimitry Andric #define ATOMIC_LONG_LOCK_FREE see below
2981ad6265SDimitry Andric #define ATOMIC_LLONG_LOCK_FREE see below
3081ad6265SDimitry Andric #define ATOMIC_POINTER_LOCK_FREE see below
3181ad6265SDimitry Andric 
3281ad6265SDimitry Andric using std::memory_order                // see below
3381ad6265SDimitry Andric using std::memory_order_relaxed        // see below
3481ad6265SDimitry Andric using std::memory_order_consume        // see below
3581ad6265SDimitry Andric using std::memory_order_acquire        // see below
3681ad6265SDimitry Andric using std::memory_order_release        // see below
3781ad6265SDimitry Andric using std::memory_order_acq_rel        // see below
3881ad6265SDimitry Andric using std::memory_order_seq_cst        // see below
3981ad6265SDimitry Andric 
4081ad6265SDimitry Andric using std::atomic_flag                 // see below
4181ad6265SDimitry Andric 
4281ad6265SDimitry Andric using std::atomic_bool                 // see below
4381ad6265SDimitry Andric using std::atomic_char                 // see below
4481ad6265SDimitry Andric using std::atomic_schar                // see below
4581ad6265SDimitry Andric using std::atomic_uchar                // see below
4681ad6265SDimitry Andric using std::atomic_short                // see below
4781ad6265SDimitry Andric using std::atomic_ushort               // see below
4881ad6265SDimitry Andric using std::atomic_int                  // see below
4981ad6265SDimitry Andric using std::atomic_uint                 // see below
5081ad6265SDimitry Andric using std::atomic_long                 // see below
5181ad6265SDimitry Andric using std::atomic_ulong                // see below
5281ad6265SDimitry Andric using std::atomic_llong                // see below
5381ad6265SDimitry Andric using std::atomic_ullong               // see below
5481ad6265SDimitry Andric using std::atomic_char8_t              // see below
5581ad6265SDimitry Andric using std::atomic_char16_t             // see below
5681ad6265SDimitry Andric using std::atomic_char32_t             // see below
5781ad6265SDimitry Andric using std::atomic_wchar_t              // see below
5881ad6265SDimitry Andric using std::atomic_int8_t               // see below
5981ad6265SDimitry Andric using std::atomic_uint8_t              // see below
6081ad6265SDimitry Andric using std::atomic_int16_t              // see below
6181ad6265SDimitry Andric using std::atomic_uint16_t             // see below
6281ad6265SDimitry Andric using std::atomic_int32_t              // see below
6381ad6265SDimitry Andric using std::atomic_uint32_t             // see below
6481ad6265SDimitry Andric using std::atomic_int64_t              // see below
6581ad6265SDimitry Andric using std::atomic_uint64_t             // see below
6681ad6265SDimitry Andric using std::atomic_int_least8_t         // see below
6781ad6265SDimitry Andric using std::atomic_uint_least8_t        // see below
6881ad6265SDimitry Andric using std::atomic_int_least16_t        // see below
6981ad6265SDimitry Andric using std::atomic_uint_least16_t       // see below
7081ad6265SDimitry Andric using std::atomic_int_least32_t        // see below
7181ad6265SDimitry Andric using std::atomic_uint_least32_t       // see below
7281ad6265SDimitry Andric using std::atomic_int_least64_t        // see below
7381ad6265SDimitry Andric using std::atomic_uint_least64_t       // see below
7481ad6265SDimitry Andric using std::atomic_int_fast8_t          // see below
7581ad6265SDimitry Andric using std::atomic_uint_fast8_t         // see below
7681ad6265SDimitry Andric using std::atomic_int_fast16_t         // see below
7781ad6265SDimitry Andric using std::atomic_uint_fast16_t        // see below
7881ad6265SDimitry Andric using std::atomic_int_fast32_t         // see below
7981ad6265SDimitry Andric using std::atomic_uint_fast32_t        // see below
8081ad6265SDimitry Andric using std::atomic_int_fast64_t         // see below
8181ad6265SDimitry Andric using std::atomic_uint_fast64_t        // see below
8281ad6265SDimitry Andric using std::atomic_intptr_t             // see below
8381ad6265SDimitry Andric using std::atomic_uintptr_t            // see below
8481ad6265SDimitry Andric using std::atomic_size_t               // see below
8581ad6265SDimitry Andric using std::atomic_ptrdiff_t            // see below
8681ad6265SDimitry Andric using std::atomic_intmax_t             // see below
8781ad6265SDimitry Andric using std::atomic_uintmax_t            // see below
8881ad6265SDimitry Andric 
8981ad6265SDimitry Andric using std::atomic_is_lock_free                         // see below
9081ad6265SDimitry Andric using std::atomic_load                                 // see below
9181ad6265SDimitry Andric using std::atomic_load_explicit                        // see below
9281ad6265SDimitry Andric using std::atomic_store                                // see below
9381ad6265SDimitry Andric using std::atomic_store_explicit                       // see below
9481ad6265SDimitry Andric using std::atomic_exchange                             // see below
9581ad6265SDimitry Andric using std::atomic_exchange_explicit                    // see below
9681ad6265SDimitry Andric using std::atomic_compare_exchange_strong              // see below
9781ad6265SDimitry Andric using std::atomic_compare_exchange_strong_explicit     // see below
9881ad6265SDimitry Andric using std::atomic_compare_exchange_weak                // see below
9981ad6265SDimitry Andric using std::atomic_compare_exchange_weak_explicit       // see below
10081ad6265SDimitry Andric using std::atomic_fetch_add                            // see below
10181ad6265SDimitry Andric using std::atomic_fetch_add_explicit                   // see below
10281ad6265SDimitry Andric using std::atomic_fetch_sub                            // see below
10381ad6265SDimitry Andric using std::atomic_fetch_sub_explicit                   // see below
10481ad6265SDimitry Andric using std::atomic_fetch_or                             // see below
10581ad6265SDimitry Andric using std::atomic_fetch_or_explicit                    // see below
10681ad6265SDimitry Andric using std::atomic_fetch_and                            // see below
10781ad6265SDimitry Andric using std::atomic_fetch_and_explicit                   // see below
10881ad6265SDimitry Andric using std::atomic_flag_test_and_set                    // see below
10981ad6265SDimitry Andric using std::atomic_flag_test_and_set_explicit           // see below
11081ad6265SDimitry Andric using std::atomic_flag_clear                           // see below
11181ad6265SDimitry Andric using std::atomic_flag_clear_explicit                  // see below
11281ad6265SDimitry Andric 
11381ad6265SDimitry Andric using std::atomic_thread_fence                         // see below
11481ad6265SDimitry Andric using std::atomic_signal_fence                         // see below
11581ad6265SDimitry Andric 
11681ad6265SDimitry Andric */
11781ad6265SDimitry Andric 
11881ad6265SDimitry Andric #include <__config>
11981ad6265SDimitry Andric 
12081ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
12181ad6265SDimitry Andric #  pragma GCC system_header
12281ad6265SDimitry Andric #endif
12381ad6265SDimitry Andric 
124*06c3fb27SDimitry Andric #if defined(__cplusplus) && _LIBCPP_STD_VER >= 23
12581ad6265SDimitry Andric 
12681ad6265SDimitry Andric #  include <atomic>
12781ad6265SDimitry Andric #  include <version>
12881ad6265SDimitry Andric 
12981ad6265SDimitry Andric #  ifdef _Atomic
13081ad6265SDimitry Andric #    undef _Atomic
13181ad6265SDimitry Andric #  endif
13281ad6265SDimitry Andric 
13381ad6265SDimitry Andric #  define _Atomic(_Tp) ::std::atomic<_Tp>
13481ad6265SDimitry Andric 
13581ad6265SDimitry Andric using std::memory_order _LIBCPP_USING_IF_EXISTS;
13681ad6265SDimitry Andric using std::memory_order_relaxed _LIBCPP_USING_IF_EXISTS;
13781ad6265SDimitry Andric using std::memory_order_consume _LIBCPP_USING_IF_EXISTS;
13881ad6265SDimitry Andric using std::memory_order_acquire _LIBCPP_USING_IF_EXISTS;
13981ad6265SDimitry Andric using std::memory_order_release _LIBCPP_USING_IF_EXISTS;
14081ad6265SDimitry Andric using std::memory_order_acq_rel _LIBCPP_USING_IF_EXISTS;
14181ad6265SDimitry Andric using std::memory_order_seq_cst _LIBCPP_USING_IF_EXISTS;
14281ad6265SDimitry Andric 
14381ad6265SDimitry Andric using std::atomic_flag _LIBCPP_USING_IF_EXISTS;
14481ad6265SDimitry Andric 
14581ad6265SDimitry Andric using std::atomic_bool _LIBCPP_USING_IF_EXISTS;
14681ad6265SDimitry Andric using std::atomic_char _LIBCPP_USING_IF_EXISTS;
14781ad6265SDimitry Andric using std::atomic_schar _LIBCPP_USING_IF_EXISTS;
14881ad6265SDimitry Andric using std::atomic_uchar _LIBCPP_USING_IF_EXISTS;
14981ad6265SDimitry Andric using std::atomic_short _LIBCPP_USING_IF_EXISTS;
15081ad6265SDimitry Andric using std::atomic_ushort _LIBCPP_USING_IF_EXISTS;
15181ad6265SDimitry Andric using std::atomic_int _LIBCPP_USING_IF_EXISTS;
15281ad6265SDimitry Andric using std::atomic_uint _LIBCPP_USING_IF_EXISTS;
15381ad6265SDimitry Andric using std::atomic_long _LIBCPP_USING_IF_EXISTS;
15481ad6265SDimitry Andric using std::atomic_ulong _LIBCPP_USING_IF_EXISTS;
15581ad6265SDimitry Andric using std::atomic_llong _LIBCPP_USING_IF_EXISTS;
15681ad6265SDimitry Andric using std::atomic_ullong _LIBCPP_USING_IF_EXISTS;
15781ad6265SDimitry Andric using std::atomic_char8_t _LIBCPP_USING_IF_EXISTS;
15881ad6265SDimitry Andric using std::atomic_char16_t _LIBCPP_USING_IF_EXISTS;
15981ad6265SDimitry Andric using std::atomic_char32_t _LIBCPP_USING_IF_EXISTS;
16081ad6265SDimitry Andric using std::atomic_wchar_t _LIBCPP_USING_IF_EXISTS;
16181ad6265SDimitry Andric 
16281ad6265SDimitry Andric using std::atomic_int8_t _LIBCPP_USING_IF_EXISTS;
16381ad6265SDimitry Andric using std::atomic_uint8_t _LIBCPP_USING_IF_EXISTS;
16481ad6265SDimitry Andric using std::atomic_int16_t _LIBCPP_USING_IF_EXISTS;
16581ad6265SDimitry Andric using std::atomic_uint16_t _LIBCPP_USING_IF_EXISTS;
16681ad6265SDimitry Andric using std::atomic_int32_t _LIBCPP_USING_IF_EXISTS;
16781ad6265SDimitry Andric using std::atomic_uint32_t _LIBCPP_USING_IF_EXISTS;
16881ad6265SDimitry Andric using std::atomic_int64_t _LIBCPP_USING_IF_EXISTS;
16981ad6265SDimitry Andric using std::atomic_uint64_t _LIBCPP_USING_IF_EXISTS;
17081ad6265SDimitry Andric 
17181ad6265SDimitry Andric using std::atomic_int_least8_t _LIBCPP_USING_IF_EXISTS;
17281ad6265SDimitry Andric using std::atomic_uint_least8_t _LIBCPP_USING_IF_EXISTS;
17381ad6265SDimitry Andric using std::atomic_int_least16_t _LIBCPP_USING_IF_EXISTS;
17481ad6265SDimitry Andric using std::atomic_uint_least16_t _LIBCPP_USING_IF_EXISTS;
17581ad6265SDimitry Andric using std::atomic_int_least32_t _LIBCPP_USING_IF_EXISTS;
17681ad6265SDimitry Andric using std::atomic_uint_least32_t _LIBCPP_USING_IF_EXISTS;
17781ad6265SDimitry Andric using std::atomic_int_least64_t _LIBCPP_USING_IF_EXISTS;
17881ad6265SDimitry Andric using std::atomic_uint_least64_t _LIBCPP_USING_IF_EXISTS;
17981ad6265SDimitry Andric 
18081ad6265SDimitry Andric using std::atomic_int_fast8_t _LIBCPP_USING_IF_EXISTS;
18181ad6265SDimitry Andric using std::atomic_uint_fast8_t _LIBCPP_USING_IF_EXISTS;
18281ad6265SDimitry Andric using std::atomic_int_fast16_t _LIBCPP_USING_IF_EXISTS;
18381ad6265SDimitry Andric using std::atomic_uint_fast16_t _LIBCPP_USING_IF_EXISTS;
18481ad6265SDimitry Andric using std::atomic_int_fast32_t _LIBCPP_USING_IF_EXISTS;
18581ad6265SDimitry Andric using std::atomic_uint_fast32_t _LIBCPP_USING_IF_EXISTS;
18681ad6265SDimitry Andric using std::atomic_int_fast64_t _LIBCPP_USING_IF_EXISTS;
18781ad6265SDimitry Andric using std::atomic_uint_fast64_t _LIBCPP_USING_IF_EXISTS;
18881ad6265SDimitry Andric 
18981ad6265SDimitry Andric using std::atomic_intptr_t _LIBCPP_USING_IF_EXISTS;
19081ad6265SDimitry Andric using std::atomic_uintptr_t _LIBCPP_USING_IF_EXISTS;
19181ad6265SDimitry Andric using std::atomic_size_t _LIBCPP_USING_IF_EXISTS;
19281ad6265SDimitry Andric using std::atomic_ptrdiff_t _LIBCPP_USING_IF_EXISTS;
19381ad6265SDimitry Andric using std::atomic_intmax_t _LIBCPP_USING_IF_EXISTS;
19481ad6265SDimitry Andric using std::atomic_uintmax_t _LIBCPP_USING_IF_EXISTS;
19581ad6265SDimitry Andric 
19681ad6265SDimitry Andric using std::atomic_compare_exchange_strong _LIBCPP_USING_IF_EXISTS;
19781ad6265SDimitry Andric using std::atomic_compare_exchange_strong_explicit _LIBCPP_USING_IF_EXISTS;
19881ad6265SDimitry Andric using std::atomic_compare_exchange_weak _LIBCPP_USING_IF_EXISTS;
19981ad6265SDimitry Andric using std::atomic_compare_exchange_weak_explicit _LIBCPP_USING_IF_EXISTS;
20081ad6265SDimitry Andric using std::atomic_exchange _LIBCPP_USING_IF_EXISTS;
20181ad6265SDimitry Andric using std::atomic_exchange_explicit _LIBCPP_USING_IF_EXISTS;
20281ad6265SDimitry Andric using std::atomic_fetch_add _LIBCPP_USING_IF_EXISTS;
20381ad6265SDimitry Andric using std::atomic_fetch_add_explicit _LIBCPP_USING_IF_EXISTS;
20481ad6265SDimitry Andric using std::atomic_fetch_and _LIBCPP_USING_IF_EXISTS;
20581ad6265SDimitry Andric using std::atomic_fetch_and_explicit _LIBCPP_USING_IF_EXISTS;
20681ad6265SDimitry Andric using std::atomic_fetch_or _LIBCPP_USING_IF_EXISTS;
20781ad6265SDimitry Andric using std::atomic_fetch_or_explicit _LIBCPP_USING_IF_EXISTS;
20881ad6265SDimitry Andric using std::atomic_fetch_sub _LIBCPP_USING_IF_EXISTS;
20981ad6265SDimitry Andric using std::atomic_fetch_sub_explicit _LIBCPP_USING_IF_EXISTS;
21081ad6265SDimitry Andric using std::atomic_flag_clear _LIBCPP_USING_IF_EXISTS;
21181ad6265SDimitry Andric using std::atomic_flag_clear_explicit _LIBCPP_USING_IF_EXISTS;
21281ad6265SDimitry Andric using std::atomic_flag_test_and_set _LIBCPP_USING_IF_EXISTS;
21381ad6265SDimitry Andric using std::atomic_flag_test_and_set_explicit _LIBCPP_USING_IF_EXISTS;
21481ad6265SDimitry Andric using std::atomic_is_lock_free _LIBCPP_USING_IF_EXISTS;
21581ad6265SDimitry Andric using std::atomic_load _LIBCPP_USING_IF_EXISTS;
21681ad6265SDimitry Andric using std::atomic_load_explicit _LIBCPP_USING_IF_EXISTS;
21781ad6265SDimitry Andric using std::atomic_store _LIBCPP_USING_IF_EXISTS;
21881ad6265SDimitry Andric using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS;
21981ad6265SDimitry Andric 
22081ad6265SDimitry Andric using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
22181ad6265SDimitry Andric using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
22281ad6265SDimitry Andric 
22381ad6265SDimitry Andric #elif defined(_LIBCPP_COMPILER_CLANG_BASED)
22481ad6265SDimitry Andric 
22581ad6265SDimitry Andric // Before C++23, we include the next <stdatomic.h> on the path to avoid hijacking
22681ad6265SDimitry Andric // the header. We do this because Clang has historically shipped a <stdatomic.h>
22781ad6265SDimitry Andric // header that would be available in all Standard modes, and we don't want to
22881ad6265SDimitry Andric // break that use case.
22981ad6265SDimitry Andric #  if __has_include_next(<stdatomic.h>)
23081ad6265SDimitry Andric #    include_next <stdatomic.h>
23181ad6265SDimitry Andric #  endif
23281ad6265SDimitry Andric 
233*06c3fb27SDimitry Andric #endif // defined(__cplusplus) && _LIBCPP_STD_VER >= 23
23481ad6265SDimitry Andric 
23581ad6265SDimitry Andric #endif // _LIBCPP_STDATOMIC_H
236