aliases.h 4.0 KB

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