libstdc++: Fix atomic waiting for non-linux targets

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.
This commit is contained in:
Jonathan Wakely 2020-11-21 16:52:22 +00:00
parent d4a20f9059
commit 62d19588b9
9 changed files with 28 additions and 13 deletions

View 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; });
}

View 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);
}

View 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);
}

View File

@ -39,8 +39,10 @@
#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
{

View 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.
//

View 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.
//

View 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.
//

View 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.
//

View 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.
//