@@ -1113,6 +1113,12 @@ _Tp kill_dependency(_Tp __y) _NOEXCEPT
11131113# define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
11141114#endif
11151115
1116+ template <class _Tp >
1117+ struct __libcpp_is_always_lock_free {
1118+ // __atomic_always_lock_free is available in all Standard modes
1119+ static const bool __value = __atomic_always_lock_free(sizeof (_Tp), 0 );
1120+ };
1121+
11161122#ifdef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
11171123
11181124template <typename _Tp>
@@ -1404,42 +1410,8 @@ _Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a,
14041410 return __old;
14051411}
14061412
1407- #ifdef __cpp_lib_atomic_is_always_lock_free
1408-
1409- template <typename _Tp> struct __cxx_is_always_lock_free {
1410- enum { __value = __atomic_always_lock_free (sizeof (_Tp), 0 ) }; };
1411-
1412- #else
1413-
1414- template <typename _Tp> struct __cxx_is_always_lock_free { enum { __value = false }; };
1415- // Implementations must match the C ATOMIC_*_LOCK_FREE macro values.
1416- template <> struct __cxx_is_always_lock_free <bool > { enum { __value = 2 == ATOMIC_BOOL_LOCK_FREE }; };
1417- template <> struct __cxx_is_always_lock_free <char > { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
1418- template <> struct __cxx_is_always_lock_free <signed char > { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
1419- template <> struct __cxx_is_always_lock_free <unsigned char > { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
1420- #ifndef _LIBCPP_HAS_NO_CHAR8_T
1421- template <> struct __cxx_is_always_lock_free <char8_t > { enum { __value = 2 == ATOMIC_CHAR8_T_LOCK_FREE }; };
1422- #endif
1423- template <> struct __cxx_is_always_lock_free <char16_t > { enum { __value = 2 == ATOMIC_CHAR16_T_LOCK_FREE }; };
1424- template <> struct __cxx_is_always_lock_free <char32_t > { enum { __value = 2 == ATOMIC_CHAR32_T_LOCK_FREE }; };
1425- #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1426- template <> struct __cxx_is_always_lock_free <wchar_t > { enum { __value = 2 == ATOMIC_WCHAR_T_LOCK_FREE }; };
1427- #endif
1428- template <> struct __cxx_is_always_lock_free <short > { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
1429- template <> struct __cxx_is_always_lock_free <unsigned short > { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
1430- template <> struct __cxx_is_always_lock_free <int > { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; };
1431- template <> struct __cxx_is_always_lock_free <unsigned int > { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; };
1432- template <> struct __cxx_is_always_lock_free <long > { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; };
1433- template <> struct __cxx_is_always_lock_free <unsigned long > { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; };
1434- template <> struct __cxx_is_always_lock_free <long long > { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; };
1435- template <> struct __cxx_is_always_lock_free <unsigned long long > { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; };
1436- template <typename _Tp> struct __cxx_is_always_lock_free <_Tp*> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
1437- template <> struct __cxx_is_always_lock_free <std::nullptr_t > { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
1438-
1439- #endif // __cpp_lib_atomic_is_always_lock_free
1440-
14411413template <typename _Tp,
1442- typename _Base = typename conditional<__cxx_is_always_lock_free <_Tp>::__value,
1414+ typename _Base = typename conditional<__libcpp_is_always_lock_free <_Tp>::__value,
14431415 __cxx_atomic_base_impl<_Tp>,
14441416 __cxx_atomic_lock_impl<_Tp> >::type>
14451417#else
@@ -1561,7 +1533,7 @@ struct __atomic_base // false
15611533 mutable __cxx_atomic_impl<_Tp> __a_;
15621534
15631535#if defined(__cpp_lib_atomic_is_always_lock_free)
1564- static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free( sizeof (__a_), 0 ) ;
1536+ static _LIBCPP_CONSTEXPR bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value ;
15651537#endif
15661538
15671539 _LIBCPP_INLINE_VISIBILITY
@@ -2664,7 +2636,7 @@ typedef atomic<uintmax_t> atomic_uintmax_t;
26642636// atomic_*_lock_free : prefer the contention type most highly, then the largest lock-free type
26652637
26662638#ifdef __cpp_lib_atomic_is_always_lock_free
2667- # define _LIBCPP_CONTENTION_LOCK_FREE __atomic_always_lock_free ( sizeof ( __cxx_contention_t ), 0)
2639+ # define _LIBCPP_CONTENTION_LOCK_FREE ::std::__libcpp_is_always_lock_free< __cxx_contention_t >::__value
26682640#else
26692641# define _LIBCPP_CONTENTION_LOCK_FREE false
26702642#endif
0 commit comments