@@ -36,9 +36,7 @@
#ifdef _GLIBCXX_HAS_GTHREADS
# define __cpp_lib_jthread 201911L
# include <bits/gthr.h>
-# if __has_include(<semaphore>)
-# include <semaphore>
-# endif
+# include <semaphore>
#endif
namespace std _GLIBCXX_VISIBILITY(default)
@@ -100,40 +98,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Callback>
friend class stop_callback;
- static void
- _S_yield() noexcept
- {
-#if defined __i386__ || defined __x86_64__
- __builtin_ia32_pause();
-#elif defined _GLIBCXX_USE_SCHED_YIELD
- __gthread_yield();
-#endif
- }
-
-#ifndef __cpp_lib_semaphore
- // TODO: replace this with a real implementation of std::binary_semaphore
- struct binary_semaphore
- {
- explicit binary_semaphore(int __d) : _M_counter(__d > 0) { }
-
- void release() { _M_counter.fetch_add(1, memory_order::release); }
-
- void acquire()
- {
- int __old = 1;
- while (!_M_counter.compare_exchange_weak(__old, 0,
- memory_order::acquire,
- memory_order::relaxed))
- {
- __old = 1;
- _S_yield();
- }
- }
-
- atomic<int> _M_counter;
- };
-#endif
-
struct _Stop_cb
{
using __cb_type = void(_Stop_cb*) noexcept;
@@ -389,7 +353,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if (__curval & _S_locked_bit)
{
- _S_yield();
+ __detail::__thread_yield();
__curval = _M_value.load(__failure);
return false;
}