master
  1//===----------------------------------------------------------------------===//
  2//
  3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4// See https://llvm.org/LICENSE.txt for license information.
  5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6//
  7//===----------------------------------------------------------------------===//
  8
  9#ifndef _LIBCPP___ATOMIC_ALIASES_H
 10#define _LIBCPP___ATOMIC_ALIASES_H
 11
 12#include <__atomic/atomic.h>
 13#include <__atomic/atomic_lock_free.h>
 14#include <__atomic/contention_t.h>
 15#include <__atomic/is_always_lock_free.h>
 16#include <__config>
 17#include <__cstddef/ptrdiff_t.h>
 18#include <__cstddef/size_t.h>
 19#include <__type_traits/conditional.h>
 20#include <__type_traits/make_unsigned.h>
 21#include <cstdint>
 22
 23#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 24#  pragma GCC system_header
 25#endif
 26
 27_LIBCPP_BEGIN_NAMESPACE_STD
 28
 29using atomic_bool   = atomic<bool>;
 30using atomic_char   = atomic<char>;
 31using atomic_schar  = atomic<signed char>;
 32using atomic_uchar  = atomic<unsigned char>;
 33using atomic_short  = atomic<short>;
 34using atomic_ushort = atomic<unsigned short>;
 35using atomic_int    = atomic<int>;
 36using atomic_uint   = atomic<unsigned int>;
 37using atomic_long   = atomic<long>;
 38using atomic_ulong  = atomic<unsigned long>;
 39using atomic_llong  = atomic<long long>;
 40using atomic_ullong = atomic<unsigned long long>;
 41#if _LIBCPP_HAS_CHAR8_T
 42using atomic_char8_t = atomic<char8_t>;
 43#endif
 44using atomic_char16_t = atomic<char16_t>;
 45using atomic_char32_t = atomic<char32_t>;
 46#if _LIBCPP_HAS_WIDE_CHARACTERS
 47using atomic_wchar_t = atomic<wchar_t>;
 48#endif
 49
 50using atomic_int_least8_t   = atomic<int_least8_t>;
 51using atomic_uint_least8_t  = atomic<uint_least8_t>;
 52using atomic_int_least16_t  = atomic<int_least16_t>;
 53using atomic_uint_least16_t = atomic<uint_least16_t>;
 54using atomic_int_least32_t  = atomic<int_least32_t>;
 55using atomic_uint_least32_t = atomic<uint_least32_t>;
 56using atomic_int_least64_t  = atomic<int_least64_t>;
 57using atomic_uint_least64_t = atomic<uint_least64_t>;
 58
 59using atomic_int_fast8_t   = atomic<int_fast8_t>;
 60using atomic_uint_fast8_t  = atomic<uint_fast8_t>;
 61using atomic_int_fast16_t  = atomic<int_fast16_t>;
 62using atomic_uint_fast16_t = atomic<uint_fast16_t>;
 63using atomic_int_fast32_t  = atomic<int_fast32_t>;
 64using atomic_uint_fast32_t = atomic<uint_fast32_t>;
 65using atomic_int_fast64_t  = atomic<int_fast64_t>;
 66using atomic_uint_fast64_t = atomic<uint_fast64_t>;
 67
 68using atomic_int8_t   = atomic< int8_t>;
 69using atomic_uint8_t  = atomic<uint8_t>;
 70using atomic_int16_t  = atomic< int16_t>;
 71using atomic_uint16_t = atomic<uint16_t>;
 72using atomic_int32_t  = atomic< int32_t>;
 73using atomic_uint32_t = atomic<uint32_t>;
 74using atomic_int64_t  = atomic< int64_t>;
 75using atomic_uint64_t = atomic<uint64_t>;
 76
 77using atomic_intptr_t  = atomic<intptr_t>;
 78using atomic_uintptr_t = atomic<uintptr_t>;
 79using atomic_size_t    = atomic<size_t>;
 80using atomic_ptrdiff_t = atomic<ptrdiff_t>;
 81using atomic_intmax_t  = atomic<intmax_t>;
 82using atomic_uintmax_t = atomic<uintmax_t>;
 83
 84// C++20 atomic_{signed,unsigned}_lock_free: prefer the contention type most highly, then the largest lock-free type
 85#if _LIBCPP_STD_VER >= 20
 86#  if ATOMIC_LLONG_LOCK_FREE == 2
 87using __largest_lock_free_type _LIBCPP_NODEBUG = long long;
 88#  elif ATOMIC_INT_LOCK_FREE == 2
 89using __largest_lock_free_type _LIBCPP_NODEBUG = int;
 90#  elif ATOMIC_SHORT_LOCK_FREE == 2
 91using __largest_lock_free_type _LIBCPP_NODEBUG = short;
 92#  elif ATOMIC_CHAR_LOCK_FREE == 2
 93using __largest_lock_free_type _LIBCPP_NODEBUG = char;
 94#  else
 95#    define _LIBCPP_NO_LOCK_FREE_TYPES // There are no lockfree types (this can happen on unusual platforms)
 96#  endif
 97
 98#  ifndef _LIBCPP_NO_LOCK_FREE_TYPES
 99using __contention_t_or_largest _LIBCPP_NODEBUG =
100    __conditional_t<__libcpp_is_always_lock_free<__cxx_contention_t>::__value,
101                    __cxx_contention_t,
102                    __largest_lock_free_type>;
103
104using atomic_signed_lock_free   = atomic<__contention_t_or_largest>;
105using atomic_unsigned_lock_free = atomic<make_unsigned_t<__contention_t_or_largest>>;
106#  endif // !_LIBCPP_NO_LOCK_FREE_TYPES
107#endif   // C++20
108
109_LIBCPP_END_NAMESPACE_STD
110
111#endif // _LIBCPP___ATOMIC_ALIASES_H