On 19/04/21 12:23 -0700, Thomas Rodgers wrote:
+#if __cpp_lib_atomic_wait + struct __atomic_semaphore + { + static constexpr ptrdiff_t _S_max = __gnu_cxx::__int_traits<int>::__max; + explicit __atomic_semaphore(__detail::__platform_wait_t __count) noexcept + : _M_counter(__count) { - static_assert(std::is_integral_v<_Tp>); - static_assert(__gnu_cxx::__int_traits<_Tp>::__max - <= __gnu_cxx::__int_traits<ptrdiff_t>::__max); - static constexpr ptrdiff_t _S_max = __gnu_cxx::__int_traits<_Tp>::__max; + __glibcxx_assert(__count >= 0 && __count <= _S_max); + }- explicit __atomic_semaphore(_Tp __count) noexcept - : _M_counter(__count) + __atomic_semaphore(const __atomic_semaphore&) = delete; + __atomic_semaphore& operator=(const __atomic_semaphore&) = delete; + + static _GLIBCXX_ALWAYS_INLINE bool + _S_do_try_acquire(__detail::__platform_wait_t* __counter, + __detail::__platform_wait_t& __old) noexcept + { + if (__old == 0) + return false; + + return __atomic_impl::compare_exchange_strong(__counter, + __old, __old - 1, + memory_order::acquire, + memory_order::release);
This violates the compare_exchange precondition: Preconditions: The failure argument is neither memory_order::release nor memory_order::acq_rel. Should this be relaxed? I don't think a failed try_acquire has to synchronize, does it?
