106c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
206c3fb27SDimitry Andric //
306c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
406c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
506c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
606c3fb27SDimitry Andric //
706c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
806c3fb27SDimitry Andric 
906c3fb27SDimitry Andric #ifndef _LIBCPP___ATOMIC_ALIASES_H
1006c3fb27SDimitry Andric #define _LIBCPP___ATOMIC_ALIASES_H
1106c3fb27SDimitry Andric 
1206c3fb27SDimitry Andric #include <__atomic/atomic.h>
1306c3fb27SDimitry Andric #include <__atomic/atomic_lock_free.h>
1406c3fb27SDimitry Andric #include <__atomic/contention_t.h>
1506c3fb27SDimitry Andric #include <__atomic/is_always_lock_free.h>
1606c3fb27SDimitry Andric #include <__config>
1706c3fb27SDimitry Andric #include <__type_traits/conditional.h>
18*5f757f3fSDimitry Andric #include <__type_traits/make_unsigned.h>
1906c3fb27SDimitry Andric #include <cstddef>
2006c3fb27SDimitry Andric #include <cstdint>
2106c3fb27SDimitry Andric #include <cstdlib>
2206c3fb27SDimitry Andric 
2306c3fb27SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2406c3fb27SDimitry Andric #  pragma GCC system_header
2506c3fb27SDimitry Andric #endif
2606c3fb27SDimitry Andric 
2706c3fb27SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
2806c3fb27SDimitry Andric 
2906c3fb27SDimitry Andric using atomic_bool   = atomic<bool>;
3006c3fb27SDimitry Andric using atomic_char   = atomic<char>;
3106c3fb27SDimitry Andric using atomic_schar  = atomic<signed char>;
3206c3fb27SDimitry Andric using atomic_uchar  = atomic<unsigned char>;
3306c3fb27SDimitry Andric using atomic_short  = atomic<short>;
3406c3fb27SDimitry Andric using atomic_ushort = atomic<unsigned short>;
3506c3fb27SDimitry Andric using atomic_int    = atomic<int>;
3606c3fb27SDimitry Andric using atomic_uint   = atomic<unsigned int>;
3706c3fb27SDimitry Andric using atomic_long   = atomic<long>;
3806c3fb27SDimitry Andric using atomic_ulong  = atomic<unsigned long>;
3906c3fb27SDimitry Andric using atomic_llong  = atomic<long long>;
4006c3fb27SDimitry Andric using atomic_ullong = atomic<unsigned long long>;
4106c3fb27SDimitry Andric #ifndef _LIBCPP_HAS_NO_CHAR8_T
4206c3fb27SDimitry Andric using atomic_char8_t = atomic<char8_t>;
4306c3fb27SDimitry Andric #endif
4406c3fb27SDimitry Andric using atomic_char16_t = atomic<char16_t>;
4506c3fb27SDimitry Andric using atomic_char32_t = atomic<char32_t>;
4606c3fb27SDimitry Andric #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4706c3fb27SDimitry Andric using atomic_wchar_t = atomic<wchar_t>;
4806c3fb27SDimitry Andric #endif
4906c3fb27SDimitry Andric 
5006c3fb27SDimitry Andric using atomic_int_least8_t   = atomic<int_least8_t>;
5106c3fb27SDimitry Andric using atomic_uint_least8_t  = atomic<uint_least8_t>;
5206c3fb27SDimitry Andric using atomic_int_least16_t  = atomic<int_least16_t>;
5306c3fb27SDimitry Andric using atomic_uint_least16_t = atomic<uint_least16_t>;
5406c3fb27SDimitry Andric using atomic_int_least32_t  = atomic<int_least32_t>;
5506c3fb27SDimitry Andric using atomic_uint_least32_t = atomic<uint_least32_t>;
5606c3fb27SDimitry Andric using atomic_int_least64_t  = atomic<int_least64_t>;
5706c3fb27SDimitry Andric using atomic_uint_least64_t = atomic<uint_least64_t>;
5806c3fb27SDimitry Andric 
5906c3fb27SDimitry Andric using atomic_int_fast8_t   = atomic<int_fast8_t>;
6006c3fb27SDimitry Andric using atomic_uint_fast8_t  = atomic<uint_fast8_t>;
6106c3fb27SDimitry Andric using atomic_int_fast16_t  = atomic<int_fast16_t>;
6206c3fb27SDimitry Andric using atomic_uint_fast16_t = atomic<uint_fast16_t>;
6306c3fb27SDimitry Andric using atomic_int_fast32_t  = atomic<int_fast32_t>;
6406c3fb27SDimitry Andric using atomic_uint_fast32_t = atomic<uint_fast32_t>;
6506c3fb27SDimitry Andric using atomic_int_fast64_t  = atomic<int_fast64_t>;
6606c3fb27SDimitry Andric using atomic_uint_fast64_t = atomic<uint_fast64_t>;
6706c3fb27SDimitry Andric 
6806c3fb27SDimitry Andric using atomic_int8_t   = atomic< int8_t>;
6906c3fb27SDimitry Andric using atomic_uint8_t  = atomic<uint8_t>;
7006c3fb27SDimitry Andric using atomic_int16_t  = atomic< int16_t>;
7106c3fb27SDimitry Andric using atomic_uint16_t = atomic<uint16_t>;
7206c3fb27SDimitry Andric using atomic_int32_t  = atomic< int32_t>;
7306c3fb27SDimitry Andric using atomic_uint32_t = atomic<uint32_t>;
7406c3fb27SDimitry Andric using atomic_int64_t  = atomic< int64_t>;
7506c3fb27SDimitry Andric using atomic_uint64_t = atomic<uint64_t>;
7606c3fb27SDimitry Andric 
7706c3fb27SDimitry Andric using atomic_intptr_t  = atomic<intptr_t>;
7806c3fb27SDimitry Andric using atomic_uintptr_t = atomic<uintptr_t>;
7906c3fb27SDimitry Andric using atomic_size_t    = atomic<size_t>;
8006c3fb27SDimitry Andric using atomic_ptrdiff_t = atomic<ptrdiff_t>;
8106c3fb27SDimitry Andric using atomic_intmax_t  = atomic<intmax_t>;
8206c3fb27SDimitry Andric using atomic_uintmax_t = atomic<uintmax_t>;
8306c3fb27SDimitry Andric 
84*5f757f3fSDimitry Andric // C++20 atomic_{signed,unsigned}_lock_free: prefer the contention type most highly, then the largest lock-free type
85*5f757f3fSDimitry Andric #if _LIBCPP_STD_VER >= 20
8606c3fb27SDimitry Andric #  if ATOMIC_LLONG_LOCK_FREE == 2
87*5f757f3fSDimitry Andric using __largest_lock_free_type = long long;
8806c3fb27SDimitry Andric #  elif ATOMIC_INT_LOCK_FREE == 2
89*5f757f3fSDimitry Andric using __largest_lock_free_type = int;
9006c3fb27SDimitry Andric #  elif ATOMIC_SHORT_LOCK_FREE == 2
91*5f757f3fSDimitry Andric using __largest_lock_free_type = short;
9206c3fb27SDimitry Andric #  elif ATOMIC_CHAR_LOCK_FREE == 2
93*5f757f3fSDimitry Andric using __largest_lock_free_type = char;
9406c3fb27SDimitry Andric #  else
95*5f757f3fSDimitry Andric #    define _LIBCPP_NO_LOCK_FREE_TYPES // There are no lockfree types (this can happen in freestanding)
9606c3fb27SDimitry Andric #  endif
9706c3fb27SDimitry Andric 
98*5f757f3fSDimitry Andric #  ifndef _LIBCPP_NO_LOCK_FREE_TYPES
99*5f757f3fSDimitry Andric using __contention_t_or_largest =
100*5f757f3fSDimitry Andric     __conditional_t<__libcpp_is_always_lock_free<__cxx_contention_t>::__value,
101*5f757f3fSDimitry Andric                     __cxx_contention_t,
102*5f757f3fSDimitry Andric                     __largest_lock_free_type>;
103*5f757f3fSDimitry Andric 
104*5f757f3fSDimitry Andric using atomic_signed_lock_free   = atomic<__contention_t_or_largest>;
105*5f757f3fSDimitry Andric using atomic_unsigned_lock_free = atomic<make_unsigned_t<__contention_t_or_largest>>;
106*5f757f3fSDimitry Andric #  endif // !_LIBCPP_NO_LOCK_FREE_TYPES
107*5f757f3fSDimitry Andric #endif   // C++20
10806c3fb27SDimitry Andric 
10906c3fb27SDimitry Andric _LIBCPP_END_NAMESPACE_STD
11006c3fb27SDimitry Andric 
11106c3fb27SDimitry Andric #endif // _LIBCPP___ATOMIC_ALIASES_H
112