@@ -1482,14 +1482,28 @@ template <class _Atp, class _Fn>
14821482struct __libcpp_atomic_wait_backoff_impl {
14831483 _Atp* __a;
14841484 _Fn __test_fn;
1485+ memory_order __order;
1486+ _LIBCPP_AVAILABILITY_SYNC
1487+ _LIBCPP_INLINE_VISIBILITY bool __use_directly (void const volatile *) const { return false ; }
14851488 _LIBCPP_AVAILABILITY_SYNC
1486- _LIBCPP_INLINE_VISIBILITY bool operator ()(chrono::nanoseconds __elapsed) const
1489+ _LIBCPP_INLINE_VISIBILITY bool __use_directly (__cxx_atomic_contention_t const volatile *) const { return true ; }
1490+ template <class _Tp >
1491+ _LIBCPP_INLINE_VISIBILITY bool operator ()(chrono::nanoseconds __elapsed, _Tp __current_val) const
14871492 {
14881493 if (__elapsed > chrono::microseconds (64 ))
14891494 {
1490- auto const __monitor = __libcpp_atomic_monitor (__a);
1491- if (__test_fn ())
1492- return true ;
1495+ __cxx_contention_t __monitor;
1496+
1497+ if (!__use_directly (__a))
1498+ {
1499+ __monitor = __libcpp_atomic_monitor (__a);
1500+ __current_val = __cxx_atomic_load (__a, __order);
1501+ if (__test_fn (__current_val))
1502+ return true ;
1503+ }
1504+ else
1505+ __monitor = __current_val;
1506+
14931507 __libcpp_atomic_wait (__a, __monitor);
14941508 }
14951509 else if (__elapsed > chrono::microseconds (4 ))
@@ -1502,10 +1516,10 @@ struct __libcpp_atomic_wait_backoff_impl {
15021516
15031517template <class _Atp , class _Fn >
15041518_LIBCPP_AVAILABILITY_SYNC
1505- _LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait (_Atp* __a, _Fn && __test_fn)
1519+ _LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait_fn (_Atp* __a, _Fn && __test_fn, memory_order __order )
15061520{
1507- __libcpp_atomic_wait_backoff_impl<_Atp, typename decay<_Fn>::type> __backoff_fn = {__a, __test_fn};
1508- return __libcpp_thread_poll_with_backoff (__test_fn, __backoff_fn);
1521+ __libcpp_atomic_wait_backoff_impl<_Atp, typename decay<_Fn>::type> __backoff_fn = {__a, __test_fn, __order };
1522+ return __libcpp_thread_poll_with_backoff (__a, __test_fn, __order , __backoff_fn);
15091523}
15101524
15111525#else // _LIBCPP_HAS_NO_PLATFORM_WAIT
@@ -1515,14 +1529,14 @@ _LIBCPP_INLINE_VISIBILITY void __cxx_atomic_notify_all(__cxx_atomic_impl<_Tp> co
15151529template <class _Tp >
15161530_LIBCPP_INLINE_VISIBILITY void __cxx_atomic_notify_one (__cxx_atomic_impl<_Tp> const volatile *) { }
15171531template <class _Atp , class _Fn >
1518- _LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait (_Atp*, _Fn && __test_fn)
1532+ _LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait_fn (_Atp* __a , _Fn && __test_fn, memory_order __order )
15191533{
15201534#if defined(_LIBCPP_HAS_NO_THREADS)
15211535 using _Policy = __spinning_backoff_policy;
15221536#else
15231537 using _Policy = __libcpp_timed_backoff_policy;
15241538#endif
1525- return __libcpp_thread_poll_with_backoff (__test_fn, _Policy ());
1539+ return __libcpp_thread_poll_with_backoff (__a, __test_fn, __order , _Policy ());
15261540}
15271541
15281542#endif // _LIBCPP_HAS_NO_PLATFORM_WAIT
@@ -1531,19 +1545,18 @@ template <class _Atp, class _Tp>
15311545struct __cxx_atomic_wait_test_fn_impl {
15321546 _Atp* __a;
15331547 _Tp __val;
1534- memory_order __order;
1535- _LIBCPP_INLINE_VISIBILITY bool operator ()() const
1548+ _LIBCPP_INLINE_VISIBILITY bool operator ()(_Tp& __current_val) const
15361549 {
1537- return !__cxx_nonatomic_compare_equal (__cxx_atomic_load (__a, __order) , __val);
1550+ return !__cxx_nonatomic_compare_equal (__current_val , __val);
15381551 }
15391552};
15401553
15411554template <class _Atp , class _Tp >
15421555_LIBCPP_AVAILABILITY_SYNC
15431556_LIBCPP_INLINE_VISIBILITY bool __cxx_atomic_wait (_Atp* __a, _Tp const __val, memory_order __order)
15441557{
1545- __cxx_atomic_wait_test_fn_impl<_Atp, _Tp> __test_fn = {__a, __val, __order };
1546- return __cxx_atomic_wait (__a, __test_fn);
1558+ __cxx_atomic_wait_test_fn_impl<_Atp, _Tp> __test_fn = {__a, __val};
1559+ return __cxx_atomic_wait_fn (__a, __test_fn, __order );
15471560}
15481561
15491562// general atomic<T>
0 commit comments