libstdc++: Fix atomic waiting for non-linux targets
authorJonathan Wakely <jwakely@redhat.com>
Sat, 21 Nov 2020 16:52:22 +0000 (16:52 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Sat, 21 Nov 2020 17:50:13 +0000 (17:50 +0000)
This fixes some UNRESOLVED tests on (at least) Solaris and Darwin, and
disables some tests that hang forever on Solaris. A proper fix is still
needed.

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h (atomic_flag::wait): Use correct
type for __atomic_wait call.
* include/bits/atomic_timed_wait.h (__atomic_wait_until): Check
_GLIBCXX_HAVE_LINUX_FUTEX.
* include/bits/atomic_wait.h (__atomic_notify): Likewise.
* include/bits/semaphore_base.h (_GLIBCXX_HAVE_POSIX_SEMAPHORE):
Only define if SEM_VALUE_MAX or _POSIX_SEM_VALUE_MAX is defined.
* testsuite/29_atomics/atomic/wait_notify/bool.cc: Disable on
non-linux targes.
* testsuite/29_atomics/atomic/wait_notify/generic.cc: Likewise.
* testsuite/29_atomics/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: Likewise.
* testsuite/29_atomics/atomic_float/wait_notify.cc: Likewise.

libstdc++-v3/include/bits/atomic_base.h
libstdc++-v3/include/bits/atomic_timed_wait.h
libstdc++-v3/include/bits/atomic_wait.h
libstdc++-v3/include/bits/semaphore_base.h
libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/bool.cc
libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/generic.cc
libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/pointers.cc
libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
libstdc++-v3/testsuite/29_atomics/atomic_float/wait_notify.cc

index dd4db92..7de02f1 100644 (file)
@@ -234,7 +234,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     wait(bool __old,
        memory_order __m = memory_order_seq_cst) const noexcept
     {
-      std::__atomic_wait(&_M_i, __old,
+      std::__atomic_wait(&_M_i, static_cast<__atomic_flag_data_type>(__old),
                         [__m, this, __old]()
                         { return this->test(__m) != __old; });
     }
index 7712a6c..405f7e9 100644 (file)
@@ -240,12 +240,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       do
        {
          __atomic_wait_status __res;
+#ifdef _GLIBCXX_HAVE_LINUX_FUTEX
          if constexpr (__platform_wait_uses_type<_Tp>)
            {
              __res = __detail::__platform_wait_until((__platform_wait_t*)(void*) __addr,
                                                      __old, __atime);
            }
          else
+#endif
            {
              __res = __w._M_do_wait_until(__version, __atime);
            }
index 2d08e53..7b2682a 100644 (file)
@@ -292,11 +292,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       if (!__w._M_waiting())
        return;
 
+#ifdef _GLIBCXX_HAVE_LINUX_FUTEX
       if constexpr (__platform_wait_uses_type<_Tp>)
        {
          __platform_notify((__platform_wait_t*)(void*) __addr, __all);
        }
       else
+#endif
        {
          __w._M_notify(__all);
        }
index da6dc4b..78a0b6b 100644 (file)
 #include <ext/numeric_traits.h>
 
 #if __has_include(<semaphore.h>)
-#define _GLIBCXX_HAVE_POSIX_SEMAPHORE 1
-#include <semaphore.h>
+# include <semaphore.h>
+# if defined SEM_VALUE_MAX || _POSIX_SEM_VALUE_MAX
+#  define _GLIBCXX_HAVE_POSIX_SEMAPHORE 1
+# endif
 #endif
 
 #include <chrono>
@@ -54,7 +56,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   struct __platform_semaphore
   {
     using __clock_t = chrono::system_clock;
+#ifdef SEM_VALUE_MAX
     static constexpr ptrdiff_t _S_max = SEM_VALUE_MAX;
+#else
+    static constexpr ptrdiff_t _S_max = _POSIX_SEM_VALUE_MAX;
+#endif
 
     explicit __platform_semaphore(ptrdiff_t __count) noexcept
     {
index 5f1e30a..29781c6 100644 (file)
@@ -1,7 +1,8 @@
-// { dg-options "-std=gnu++2a -pthread" }
+// { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target pthread }
 // { dg-require-gthreads "" }
+// { dg-additional-options "-pthread" { target pthread } }
+// { dg-skip-if "broken" { ! *-*-*linux } }
 
 // Copyright (C) 2020 Free Software Foundation, Inc.
 //
index 0249341..629556a 100644 (file)
@@ -1,7 +1,8 @@
-// { dg-options "-std=gnu++2a -pthread" }
+// { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target pthread }
 // { dg-require-gthreads "" }
+// { dg-additional-options "-pthread" { target pthread } }
+// { dg-skip-if "broken" { ! *-*-*linux } }
 
 // Copyright (C) 2020 Free Software Foundation, Inc.
 //
index 8531bb2..f54961f 100644 (file)
@@ -1,7 +1,8 @@
-// { dg-options "-std=gnu++2a -pthread" }
+// { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target pthread }
+// { dg-additional-options "-pthread" { target pthread } }
 // { dg-require-gthreads "" }
+// { dg-skip-if "broken" { ! *-*-*linux } }
 
 // Copyright (C) 2020 Free Software Foundation, Inc.
 //
index 4f026e1..763d3e7 100644 (file)
@@ -1,7 +1,8 @@
-// { dg-options "-std=gnu++2a -pthread" }
+// { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target pthread }
 // { dg-require-gthreads "" }
+// { dg-additional-options "-pthread" { target pthread } }
+// { dg-skip-if "broken" { ! *-*-*linux } }
 
 // Copyright (C) 2020 Free Software Foundation, Inc.
 //
index 640a84e..27d9b60 100644 (file)
@@ -1,7 +1,8 @@
-// { dg-options "-std=gnu++2a -pthread" }
+// { dg-options "-std=gnu++2a" }
 // { dg-do run { target c++2a } }
-// { dg-require-effective-target pthread }
 // { dg-require-gthreads "" }
+// { dg-additional-options "-pthread" { target pthread } }
+// { dg-skip-if "broken" { ! *-*-*linux } }
 
 // Copyright (C) 2020 Free Software Foundation, Inc.
 //