[gcc r11-7248] libstdc++: Fix __thread_yield for non-gthreads targets

Jonathan Wakely redi@gcc.gnu.org
Mon Feb 15 15:52:36 GMT 2021


https://gcc.gnu.org/g:cc9a0a3d79d6abb08753a819c9ea21a25015e962

commit r11-7248-gcc9a0a3d79d6abb08753a819c9ea21a25015e962
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Feb 15 15:35:55 2021 +0000

    libstdc++: Fix __thread_yield for non-gthreads targets
    
    The __gthread_yield() function is only defined for gthreads targets, so
    check _GLIBCXX_HAS_GTHREADS before using it.
    
    Also reorder __thread_relax and __thread_yield so that the former can
    use the latter instead of repeating the same preprocessor checks.
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/atomic_wait.h (__thread_yield()): Check
            _GLIBCXX_HAS_GTHREADS before using __gthread_yield.
            (__thread_relax()): Use __thread_yield() instead of repeating
            the preprocessor checks for __gthread_yield.

Diff:
---
 libstdc++-v3/include/bits/atomic_wait.h | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index 1a0f0943ebd..37085ae8e50 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -214,23 +214,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     };
 
     inline void
-    __thread_relax() noexcept
+    __thread_yield() noexcept
     {
-#if defined __i386__ || defined __x86_64__
-      __builtin_ia32_pause();
-#elif defined _GLIBCXX_USE_SCHED_YIELD
-      __gthread_yield();
+#if defined _GLIBCXX_HAS_GTHREADS && defined _GLIBCXX_USE_SCHED_YIELD
+     __gthread_yield();
 #endif
     }
 
     inline void
-    __thread_yield() noexcept
+    __thread_relax() noexcept
     {
-#if defined _GLIBCXX_USE_SCHED_YIELD
-     __gthread_yield();
+#if defined __i386__ || defined __x86_64__
+      __builtin_ia32_pause();
+#else
+      __gthread_yield();
 #endif
     }
-
   } // namespace __detail
 
   template<typename _Pred>


More information about the Libstdc++-cvs mailing list