Re: [PATCH] libstdc++: Split up pstl/set.cc testcase

2023-07-05 Thread Thomas Rodgers via Gcc-patches
Comment added to each file.

Tested x86_64-linux. Pushed to trunk.

On Mon, Jul 3, 2023 at 4:16 PM Jonathan Wakely  wrote:

> On Mon, 3 Jul 2023 at 23:14, Thomas Rodgers via Libstdc++
>  wrote:
> >
> > This testcase is causing some timeout issues. This patch splits the
> > testcase up by individual set algorithm.
>
> I think the Apache license requires a notice saying the original file
> was modified. A comment in each new file noting it was derived from
> pstl/alg_sorting/set.cc (or whatever the file is called upstream)
> should be sufficient.
>
> OK with that change, thanks.
>
>


[PATCH] libstdc++: Split up pstl/set.cc testcase

2023-07-03 Thread Thomas Rodgers via Gcc-patches
This testcase is causing some timeout issues. This patch splits the
testcase up by individual set algorithm.
From 857359b72f8886b6e90db3b596d04f08559d2b51 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Mon, 3 Jul 2023 15:04:45 -0700
Subject: [PATCH] libstdc++: Split up pstl/set.cc testcase

This testcase is causing some timeout issues. This patch splits the
testcase up by individual set algorithm.

libstdc++-v3:/ChangeLog:
	* testsuite/25_algorithms/pstl/alg_sorting/set.cc: Delete
	file.
	* testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc:
	New file.
	* testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/set_union.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/set_util.h:
	Likewise.
---
 .../25_algorithms/pstl/alg_sorting/set.cc | 289 --
 .../pstl/alg_sorting/set_difference.cc|  90 ++
 .../pstl/alg_sorting/set_intersection.cc  |  91 ++
 .../alg_sorting/set_symmetric_difference.cc   |  92 ++
 .../pstl/alg_sorting/set_union.cc |  90 ++
 .../25_algorithms/pstl/alg_sorting/set_util.h |  72 +
 6 files changed, 435 insertions(+), 289 deletions(-)
 delete mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc
 create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc
 create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc
 create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc
 create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc
 create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h

diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc
deleted file mode 100644
index 0343739dfd1..000
--- a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc
+++ /dev/null
@@ -1,289 +0,0 @@
-// -*- C++ -*-
-// { dg-options "-ltbb" }
-// { dg-do run { target c++17 } }
-// { dg-timeout-factor 3 }
-// { dg-require-effective-target tbb_backend }
-
-//===-- set.pass.cpp --===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "pstl/pstl_test_config.h"
-
-#ifdef PSTL_STANDALONE_TESTS
-
-#include 
-#include 
-
-#include "pstl/execution"
-#include "pstl/algorithm"
-#else
-#include 
-#include 
-#endif // PSTL_STANDALONE_TESTS
-
-#include "pstl/test_utils.h"
-
-using namespace TestUtils;
-
-template 
-struct Num
-{
-T val;
-
-Num() : val{} {}
-Num(const T& v) : val(v) {}
-
-//for "includes" checks
-template 
-bool
-operator<(const Num& v1) const
-{
-return val < v1.val;
-}
-
-//The types Type1 and Type2 must be such that an object of type InputIt can be dereferenced and then implicitly converted to both of them
-template 
-operator Num() const
-{
-return Num((T1)val);
-}
-
-friend bool
-operator==(const Num& v1, const Num& v2)
-{
-return v1.val == v2.val;
-}
-};
-
-template 
-struct test_set_union
-{
-template 
-typename std::enable_if::value, void>::type
-operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
-   Compare comp)
-{
-using T1 = typename std::iterator_traits::value_type;
-
-auto n1 = std::distance(first1, last1);
-auto n2 = std::distance(first2, last2);
-auto n = n1 + n2;
-Sequence expect(n);
-Sequence out(n);
-
-auto expect_res = std::set_union(first1, last1, first2, last2, expect.begin(), comp);
-auto res = std::set_union(exec, first1, last1, first2, last2, out.begin(), comp);
-
-EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_union");
-EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_union effect");
-}
-
-template 
-typename std::enable_if::value, void>::type
-operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare)
-{
-}
-};
-
-template 
-struct test_set_intersection
-{
-template 
-typename std::enable_if::value, void>::type
-operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
-   Compare comp)
-{
-using T1 = typename std::iterator_traits::value_type;
-
-auto n1 = std::distance(first1, last1);

Re: [PATCH] libstdc++: Synchronize PSTL with upstream

2023-06-26 Thread Thomas Rodgers via Gcc-patches
On Wed, May 17, 2023 at 12:32 PM Jonathan Wakely  wrote:

> -template 
> -  _OutputIterator
> -__brick_generate_n(_OutputIterator __first, _Size __count, _Generator
> __g, /* is_vector = */ std::true_type) noexcept
> +template 
>
> Missing uglification on Size.
>
> +_RandomAccessIterator
> +__brick_generate_n(_RandomAccessIterator __first, Size __count,
> _Generator __g,
> +   /* is_vector = */ std::true_type) noexcept
>  {
>  return __unseq_backend::__simd_generate_n(__first, __count, __g);
>  }
>
> -template 
> -  _OutputIterator
> -__brick_generate_n(_OutputIterator __first, _Size __count, _Generator
> __g, /* is_vector = */ std::false_type) noexcept
> +template 
>
> Missing uglification on OutputIterator and Size.
>
> +OutputIterator
> +__brick_generate_n(OutputIterator __first, Size __count, _Generator __g,
> /* is_vector = */ std::false_type) noexcept
>
>
> -template  _BinaryOperation>
> -_ForwardIterator2
> -__brick_adjacent_difference(_ForwardIterator1 __first, _ForwardIterator1
> __last, _ForwardIterator2 __d_first,
> -_BinaryOperation __op, /*is_vector=*/std::true_type) noexcept
> +template  class BinaryOperation>
>
> Missing uglification on BinaryOperation.
>
> +_RandomAccessIterator2
> +__brick_adjacent_difference(_RandomAccessIterator1 __first,
> _RandomAccessIterator1 __last,
> +_RandomAccessIterator2 __d_first,
> BinaryOperation __op,
> +/*is_vector=*/std::true_type) noexcept
>
>
> The above problems exist on the declaration and the definitions.
>
>
> --- a/libstdc++-v3/include/pstl/glue_execution_defs.h
> +++ b/libstdc++-v3/include/pstl/glue_execution_defs.h
> @@ -18,8 +18,8 @@ namespace std
>  {
>  // Type trait
>  using __pstl::execution::is_execution_policy;
> -#if _PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT
> -#if __INTEL_COMPILER
> +#if defined(_PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT)
> +#if defined(__INTEL_COMPILER)
>  template 
>  constexpr bool is_execution_policy_v = is_execution_policy::value;
>  #else
>
> Pre-existing, but that T should be _Tp, but it only affects the Intel
> compiler branch, so meh.
>
> Please fix these and report them upstream too.
>

Ack.


>
> All the actual code changes look good.
>
> I think I'd prefer if __pattern_partial_sort_copy used
> std::uninitialized_copy instead of a loop and placement-new, but that
> doesn't need to hold this up. We could optimize some uses of
> std::conjunction and std::conditional to use our own __and_ and
> __conditional, but I'm not sure it's worth diverging from upstream to do
> that.
>
> Please fix the naming bugs noted above and push to trunk, thanks!
>

There were a handful of additional missed uglifications in -
* libstdc++-v3/include/pstl/glue_algorithm_impl.h
* libstdc++-v3/include/pstl/unseq_backend_simd.h
That are in this commit, but not in the patch as reviewed.

Tested x86_64-linux. Pushed to trunk.


>
> +Reviewed-by: Jonathan Wakely 
>
>
>
>
>
>


Re: [PATCH v2] libstdc++: Do not use pthread_mutex_clocklock with ThreadSanitizer

2023-05-15 Thread Thomas Rodgers via Gcc-patches
On Thu, May 11, 2023 at 1:52 PM Jonathan Wakely  wrote:

> On Thu, 11 May 2023 at 13:42, Jonathan Wakely  wrote:
>
>>
>>
>> On Thu, 11 May 2023 at 13:19, Mike Crowe  wrote:
>>
>>> However, ...
>>>
>>> > > diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
>>> > > index 89e7f5f5f45..e2700b05ec3 100644
>>> > > --- a/libstdc++-v3/acinclude.m4
>>> > > +++ b/libstdc++-v3/acinclude.m4
>>> > > @@ -4284,7 +4284,7 @@
>>> AC_DEFUN([GLIBCXX_CHECK_PTHREAD_COND_CLOCKWAIT], [
>>> > >[glibcxx_cv_PTHREAD_COND_CLOCKWAIT=no])
>>> > >])
>>> > >if test $glibcxx_cv_PTHREAD_COND_CLOCKWAIT = yes; then
>>> > > -AC_DEFINE(_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT, 1, [Define if
>>> > > pthread_cond_clockwait is available in .])
>>> > > +AC_DEFINE(_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT,
>>> (_GLIBCXX_TSAN==0),
>>> > > [Define if pthread_cond_clockwait is available in .])
>>> > >fi
>>>
>>> TSan does appear to have an interceptor for pthread_cond_clockwait, even
>>> if
>>> it lacks the others. Does this mean that this part is unnecessary?
>>>
>>
>> Ah good point, thanks. I grepped for clocklock but not clockwait.
>>
>
> In fact it seems like we don't need to change
> _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK either, because I don't get any tsan
> warnings for that. It doesn't have interceptors for
> pthread_rwlock_{rd,wr}lock, but it doesn't complain anyway (maybe it's
> simply not instrumenting the rwlock functions at all?!)
>
> So I'm now retesting with this version of the patch, which only touches
> the USE_PTHREAD_LOCKLOCK macro.
>
> Please take another look, thanks.
>
> LGTM.


Re: [RFC] libstdc++: Do not use pthread_mutex_clocklock with ThreadSanitizer

2023-05-11 Thread Thomas Rodgers via Gcc-patches
On Thu, May 11, 2023 at 5:21 AM Mike Crowe via Libstdc++ <
libstd...@gcc.gnu.org> wrote:

> On Wednesday 10 May 2023 at 12:31:12 +0100, Jonathan Wakely wrote:
> > On Wed, 10 May 2023 at 12:20, Jonathan Wakely via Libstdc++ <
> > libstd...@gcc.gnu.org> wrote:
> >
> > > This patch would avoid TSan false positives when using timed waiting
> > > functions on mutexes and condvars, but as noted below, it changes the
> > > semantics.
> > >
> > > I'm not sure whether we want this workaround in place until tsan gets
> > > fixed.
> > >
> > > On one hand, there's no guarantee that those functions use the right
> > > clock anyway (and they won't do unless a recent-ish glibc is used). But
> > > on the other hand, if they normally would use the right clock because
> > > you have glibc support, it's not ideal for tsan to cause a different
> > > clock to be used.
> > >
> >
> > But of course, it's not ideal to get false positives from tsan either
> > (especially when it looks like a libstdc++ bug, as initially reported to
> > me).
>
> I think that this is probably the least-worst option in the short term. As
> TSan is distributed with GCC this workaround can be removed as soon as its
> TSan implementation gains the necessary interceptors. I shall look into
> trying to do that.
>
>
I don't have a strong opinion either way on this, but I think documenting
the TSAN suppressions is the option most in keeping with the principle of
Least Astonishment.


> However, ...
>
> > > diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
> > > index 89e7f5f5f45..e2700b05ec3 100644
> > > --- a/libstdc++-v3/acinclude.m4
> > > +++ b/libstdc++-v3/acinclude.m4
> > > @@ -4284,7 +4284,7 @@ AC_DEFUN([GLIBCXX_CHECK_PTHREAD_COND_CLOCKWAIT],
> [
> > >[glibcxx_cv_PTHREAD_COND_CLOCKWAIT=no])
> > >])
> > >if test $glibcxx_cv_PTHREAD_COND_CLOCKWAIT = yes; then
> > > -AC_DEFINE(_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT, 1, [Define if
> > > pthread_cond_clockwait is available in .])
> > > +AC_DEFINE(_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT, (_GLIBCXX_TSAN==0),
> > > [Define if pthread_cond_clockwait is available in .])
> > >fi
>
> TSan does appear to have an interceptor for pthread_cond_clockwait, even if
> it lacks the others. Does this mean that this part is unnecessary?
>
> See: https://github.com/google/sanitizers/issues/1259
>
> Thanks.
>
> Mike.
>
>


[PATCH] libstdc++: Synchronize PSTL with upstream (2nd attempt)

2023-04-20 Thread Thomas Rodgers via Gcc-patches
The attached (gzipped) patch brings libstdc++'s PSTL implementation up to
the current upstream version.

Tested x86_64-pc-linux-gnu, specifically with TBB 2020.3 (fedora 37 +
tbb-devel).


0001-libstdc-Synchronize-PSTL-with-upstream.patch.gz
Description: application/gzip


Re: [PATCH] libstdc++: Add missing free functions for atomic_flag [PR103934]

2023-03-09 Thread Thomas Rodgers via Gcc-patches
The second patch has now been backported and pushed to releases/gcc-12 and
releases/gcc-11.

On Mon, Feb 13, 2023 at 6:06 PM Thomas Rodgers  wrote:

> Tested x86_64-pc-linux-gnu. Pushed to trunk.
>
> The first patch has also been backported and pushed to releases/gcc-12 and
> releases/gcc-11
>
> The second patch fails to cleanly cherry-pick. Will resolve and push
> shortly.
>
> On Fri, Feb 10, 2023 at 4:41 PM Jonathan Wakely 
> wrote:
>
>> On Fri, 10 Feb 2023 at 18:25, Thomas Rodgers  wrote:
>> >
>> > This patch did not get committed in a timely manner after it was OK'd.
>> In revisiting the patch some issues were found that have lead me to
>> resubmit for review -
>> >
>> > Specifically -
>> >
>> > The original commit to add C++20 atomic_flag::test did not include the
>> free functions for atomic_flag_test[_explicit]
>> > The original commit to add C++20 atomic_flag::wait/notify did not
>> include the free functions for atomic_flag_wait/notify[_explicit]
>> >
>> > These two commits landed in GCC10 and GCC11 respectively. My original
>> patch included both sets of free functions, but
>> > that complicates the backporting of these changes to GCC10, GCC11, and
>> GCC12.
>>
>> I don't think we need them in GCC 10.
>>
>> > Additionally commit 7c2155 removed const qualification from
>> atomic_flag::notify_one/notify_all but the original version of this
>> > patch accepts the atomic flag as const.
>> >
>> > The original version of this patch did not include test cases for the
>> atomic_flag_test[_explicit] free functions.
>> >
>> > I have split the original patch into two patches, on for the
>> atomic_flag_test free functions, and one for the atomic_flag_wait/notify
>> > free functions.
>>
>> Thanks.
>>
>> For [PATCH 1/2] please name the added functions in the changelog entry:
>>
>> * include/std/atomic (atomic_flag_test): Add.
>> (atomic_flag_test_explicit): Add.
>>
>> Similarly for the changelog in [PATCH 2/2], naming the four new
>> functions added to include/std/atomic.
>>
>> The indentation is off in [PATCH 2/2] for atomic_flag:
>>
>> +#if __cpp_lib_atomic_wait
>> +  inline void
>> +  atomic_flag_wait(atomic_flag* __a, bool __old) noexcept
>> +  { __a->wait(__old); }
>> +
>>
>> And similarly for the other three added functions.
>> The function names should start in the same column as the 'inline' and
>> opening brace of the function body.
>>
>>
>> Both patches are OK for trunk, gcc-12 and gcc-11 with those changes.
>>
>>
>>
>>
>> >
>> >
>> > On Wed, Feb 2, 2022 at 1:35 PM Jonathan Wakely 
>> wrote:
>> >>
>> >> >+  inline void
>> >> >+  atomic_flag_wait_explicit(const atomic_flag* __a, bool __old,
>> >> >+   std::memory_order __m) noexcept
>> >>
>> >> No need for the std:: qualification, and check the indentation.
>> >>
>> >>
>> >> > libstdc++-v3/ChangeLog:
>> >> >
>> >> >PR103934
>> >>
>> >> This needs to include the component: PR libstdc++/103934
>> >>
>> >> >* include/std/atomic: Add missing free functions.
>> >>
>> >> Please name the new functions in the changelog, in the usual format.
>> >> Just the names is fine, no need for the full signatures with
>> >> parameters.
>> >>
>> >> OK for trunk with those changes.
>> >>
>>
>>


Re: [PATCH] libstdc++: Add missing free functions for atomic_flag [PR103934]

2023-02-13 Thread Thomas Rodgers via Gcc-patches
Tested x86_64-pc-linux-gnu. Pushed to trunk.

The first patch has also been backported and pushed to releases/gcc-12 and
releases/gcc-11

The second patch fails to cleanly cherry-pick. Will resolve and push
shortly.

On Fri, Feb 10, 2023 at 4:41 PM Jonathan Wakely  wrote:

> On Fri, 10 Feb 2023 at 18:25, Thomas Rodgers  wrote:
> >
> > This patch did not get committed in a timely manner after it was OK'd.
> In revisiting the patch some issues were found that have lead me to
> resubmit for review -
> >
> > Specifically -
> >
> > The original commit to add C++20 atomic_flag::test did not include the
> free functions for atomic_flag_test[_explicit]
> > The original commit to add C++20 atomic_flag::wait/notify did not
> include the free functions for atomic_flag_wait/notify[_explicit]
> >
> > These two commits landed in GCC10 and GCC11 respectively. My original
> patch included both sets of free functions, but
> > that complicates the backporting of these changes to GCC10, GCC11, and
> GCC12.
>
> I don't think we need them in GCC 10.
>
> > Additionally commit 7c2155 removed const qualification from
> atomic_flag::notify_one/notify_all but the original version of this
> > patch accepts the atomic flag as const.
> >
> > The original version of this patch did not include test cases for the
> atomic_flag_test[_explicit] free functions.
> >
> > I have split the original patch into two patches, on for the
> atomic_flag_test free functions, and one for the atomic_flag_wait/notify
> > free functions.
>
> Thanks.
>
> For [PATCH 1/2] please name the added functions in the changelog entry:
>
> * include/std/atomic (atomic_flag_test): Add.
> (atomic_flag_test_explicit): Add.
>
> Similarly for the changelog in [PATCH 2/2], naming the four new
> functions added to include/std/atomic.
>
> The indentation is off in [PATCH 2/2] for atomic_flag:
>
> +#if __cpp_lib_atomic_wait
> +  inline void
> +  atomic_flag_wait(atomic_flag* __a, bool __old) noexcept
> +  { __a->wait(__old); }
> +
>
> And similarly for the other three added functions.
> The function names should start in the same column as the 'inline' and
> opening brace of the function body.
>
>
> Both patches are OK for trunk, gcc-12 and gcc-11 with those changes.
>
>
>
>
> >
> >
> > On Wed, Feb 2, 2022 at 1:35 PM Jonathan Wakely 
> wrote:
> >>
> >> >+  inline void
> >> >+  atomic_flag_wait_explicit(const atomic_flag* __a, bool __old,
> >> >+   std::memory_order __m) noexcept
> >>
> >> No need for the std:: qualification, and check the indentation.
> >>
> >>
> >> > libstdc++-v3/ChangeLog:
> >> >
> >> >PR103934
> >>
> >> This needs to include the component: PR libstdc++/103934
> >>
> >> >* include/std/atomic: Add missing free functions.
> >>
> >> Please name the new functions in the changelog, in the usual format.
> >> Just the names is fine, no need for the full signatures with
> >> parameters.
> >>
> >> OK for trunk with those changes.
> >>
>
>


Re: [PATCH] libstdc++: Add missing free functions for atomic_flag [PR103934]

2023-02-10 Thread Thomas Rodgers via Gcc-patches
This patch did not get committed in a timely manner after it was OK'd. In
revisiting the patch some issues were found that have lead me to resubmit
for review -

Specifically -

The original commit to add C++20 atomic_flag::test did not include the free
functions for atomic_flag_test[_explicit]
The original commit to add C++20 atomic_flag::wait/notify did not include
the free functions for atomic_flag_wait/notify[_explicit]

These two commits landed in GCC10 and GCC11 respectively. My original patch
included both sets of free functions, but
that complicates the backporting of these changes to GCC10, GCC11, and
GCC12.

Additionally commit 7c2155 removed const qualification from
atomic_flag::notify_one/notify_all but the original version of this
patch accepts the atomic flag as const.

The original version of this patch did not include test cases for the
atomic_flag_test[_explicit] free functions.

I have split the original patch into two patches, on for the
atomic_flag_test free functions, and one for the atomic_flag_wait/notify
free functions.


On Wed, Feb 2, 2022 at 1:35 PM Jonathan Wakely  wrote:

> >+  inline void
> >+  atomic_flag_wait_explicit(const atomic_flag* __a, bool __old,
> >+   std::memory_order __m) noexcept
>
> No need for the std:: qualification, and check the indentation.
>
>
> > libstdc++-v3/ChangeLog:
> >
> >PR103934
>
> This needs to include the component: PR libstdc++/103934
>
> >* include/std/atomic: Add missing free functions.
>
> Please name the new functions in the changelog, in the usual format.
> Just the names is fine, no need for the full signatures with
> parameters.
>
> OK for trunk with those changes.
>
>
From 1338538c1667b7fbe201d22d81254e33a0e7b24c Mon Sep 17 00:00:00 2001
From: Thomas W Rodgers 
Date: Fri, 10 Feb 2023 10:09:06 -0800
Subject: [PATCH 2/2] libstdc++: Add missing free functions for atomic_flag
 [PR103934]

This patch adds -
  atomic_flag_wait
  atomic_flag_wait_explicit
  atomic_flag_notify
  atomic_flag_notify_explicit

Which were missed when commit 83a1be introduced C++20 atomic wait.

libstdc++-v3/ChangeLog:

	PR libstdc++/103934
	* include/std/atomic: Add missing free functions.
	* testsuite/29_atomics/atomic_flag/wait_notify/1.cc:
	Add test case to cover missing atomic_flag free functions.
---
 libstdc++-v3/include/std/atomic   | 19 ++
 .../29_atomics/atomic_flag/wait_notify/1.cc   | 26 +--
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 1edd3ae16fa..e82a6427378 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -1259,6 +1259,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   atomic_flag_clear(volatile atomic_flag* __a) noexcept
   { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
 
+#if __cpp_lib_atomic_wait
+  inline void
+  atomic_flag_wait(atomic_flag* __a, bool __old) noexcept
+  { __a->wait(__old); }
+
+  inline void
+  atomic_flag_wait_explicit(atomic_flag* __a, bool __old,
+memory_order __m) noexcept
+  { __a->wait(__old, __m); }
+
+  inline void
+  atomic_flag_notify_one(atomic_flag* __a) noexcept
+  { __a->notify_one(); }
+
+  inline void
+  atomic_flag_notify_all(atomic_flag* __a) noexcept
+  { __a->notify_all(); }
+#endif // __cpp_lib_atomic_wait
+
   /// @cond undocumented
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 3220. P0558 broke conforming C++14 uses of atomic shared_ptr
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
index 240fb4259f7..777fa915ea1 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
@@ -26,8 +26,8 @@
 
 #include 
 
-int
-main()
+void
+test01()
 {
   std::atomic_flag a;
   VERIFY( !a.test() );
@@ -39,5 +39,27 @@ main()
 });
   a.wait(false);
   t.join();
+}
+
+void
+test02()
+{
+  std::atomic_flag a;
+  VERIFY( !std::atomic_flag_test() );
+  std::atomic_flag_wait(, true);
+  std::thread t([&]
+{
+  std::atomic_flag_test_and_set();
+  std::atomic_flag_notify_one();
+});
+std::atomic_flag_wait(, false);
+t.join();
+}
+
+int
+main()
+{
+  test01();
+  test02();
   return 0;
 }
-- 
2.39.1

From 7f21e98bbefde5437a116ccda35a85922f5882bf Mon Sep 17 00:00:00 2001
From: Thomas W Rodgers 
Date: Fri, 10 Feb 2023 09:35:11 -0800
Subject: [PATCH 1/2] libstdc++: Add missing free functions for atomic_flag
 [PR103934]

This patch adds -
  atomic_flag_test
  atomic_flag_test_explicit

Which were missed when commit 491ba6 introduced C++20 atomic flag
test.

libstdc++-v3/ChangeLog:

	PR libstdc++/103934
	* include/std/atomic: Add missing free functions.
	* testsuite/29_atomics/atomic_flag/test/explicit.cc
Add test case to cover missing atomic_flag free functions.
* 

Re: [RFA] choosing __platform_wait_t on targets without lock-free 64 atomics

2023-01-11 Thread Thomas Rodgers via Gcc-patches
I agree with this change.

On Thu, Jan 5, 2023 at 4:22 PM Jonathan Wakely  wrote:

> How about this?
>
> I don't think we should worry about targets without atomic int, so don't
> bother using types smaller than int.
>
>
> -- >8 --
>
> For non-futex targets the __platform_wait_t type is currently uint64_t,
> but that requires a lock in libatomic for some 32-bit targets. We don't
> really need a 64-bit type, so use unsigned long if that is lock-free,
> and int otherwise. This should mean it's lock-free on a wider set of
> targets.
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/atomic_wait.h (__detail::__platform_wait_t):
> Define as unsigned long if always lock-free, and unsigned int
> otherwise.
> ---
>  libstdc++-v3/include/bits/atomic_wait.h | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/include/bits/atomic_wait.h
> b/libstdc++-v3/include/bits/atomic_wait.h
> index bd1ed56d157..46f39f10cbc 100644
> --- a/libstdc++-v3/include/bits/atomic_wait.h
> +++ b/libstdc++-v3/include/bits/atomic_wait.h
> @@ -64,7 +64,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>  // and __platform_notify() if there is a more efficient primitive
> supported
>  // by the platform (e.g. __ulock_wait()/__ulock_wake()) which is better
> than
>  // a mutex/condvar based wait.
> -using __platform_wait_t = uint64_t;
> +# if  ATOMIC_LONG_LOCK_FREE == 2
> +using __platform_wait_t = unsigned long;
> +# else
> +using __platform_wait_t = unsigned int;
> +# endif
>  inline constexpr size_t __platform_wait_alignment
>= __alignof__(__platform_wait_t);
>  #endif
> --
> 2.39.0
>
>


Re: Patch ping (was Re: [PATCH] libstdc++: Clear padding bits in atomic compare_exchange)

2022-09-09 Thread Thomas Rodgers via Gcc-patches
s/__weak/__is_weak/g  perhaps?

On Fri, Sep 9, 2022 at 11:46 AM Iain Sandoe via Libstdc++ <
libstd...@gcc.gnu.org> wrote:

>
>
> > On 9 Sep 2022, at 19:36, Rainer Orth 
> wrote:
> >
>
> >> Here's a complete patch that combines the various incremental patches
> >> that have been going around. I'm testing this now.
> >>
> >> Please take a look.
> >
> > unfortunately, this patch broke macOS bootstrap (seen on
> > x86_64-apple-darwin11.4.2):
> >
> > In file included from
> /var/gcc/regression/master/10.7-gcc/build/x86_64-apple-darwin11.4.2/libstdc++-v3/include/bits/shared_ptr_atomic.h:33,
> > from
> /var/gcc/regression/master/10.7-gcc/build/x86_64-apple-darwin11.4.2/libstdc++-v3/include/memory:78,
> > from
> /vol/gcc/src/hg/master/darwin/libstdc++-v3/include/precompiled/stdc++.h:82:
> >
> /var/gcc/regression/master/10.7-gcc/build/x86_64-apple-darwin11.4.2/libstdc++-v3/include/bits/atomic_base.h:
> In function 'bool std::__atomic_impl::__compare_exchange(_Tp&, _Val<_Tp>&,
> _Val<_Tp>&, bool, std::memory_order, std::memory_order)':
> >
> /var/gcc/regression/master/10.7-gcc/build/x86_64-apple-darwin11.4.2/libstdc++-v3/include/bits/atomic_base.h:1008:49:
> error: expected primary-expression before ',' token
> > 1008 |   __weak, int(__s),
> int(__f)))
> >  | ^
> >
> /var/gcc/regression/master/10.7-gcc/build/x86_64-apple-darwin11.4.2/libstdc++-v3/include/bits/atomic_base.h:1017:50:
> error: expected primary-expression before ',' token
> > 1017 |__weak, int(__s),
> int(__f));
> >  |  ^
> >
> > Darwin gcc predefines __weak= in gcc/config/darwin-c.cc
> (darwin_cpp_builtins).
>
> yes, __weak and __strong are Objective C things (in principle, applicable
> to non-Darwin targets
> using NeXT runtime - there is at least one such target).
>
> Iain
>
>


Re: Patch ping (was Re: [PATCH] libstdc++: Clear padding bits in atomic compare_exchange)

2022-09-07 Thread Thomas Rodgers via Gcc-patches
Looks good to me.

Tom.

On Wed, Sep 7, 2022 at 4:56 AM Jonathan Wakely  wrote:

> Here's a complete patch that combines the various incremental patches
> that have been going around. I'm testing this now.
>
> Please take a look.
>


Re: [committed] libstdc++: Add missing runtime exception to licence notice

2022-09-07 Thread Thomas Rodgers via Gcc-patches
Looks good to me.

Tom.

On Wed, Sep 7, 2022 at 12:27 PM Jonathan Wakely via Gcc-patches <
gcc-patches@gcc.gnu.org> wrote:

> Tested powerpc64le-linux, pushed to trunk.
>
> Backports to gcc-11 and gcc-12 needed too.
>
> -- >8 --
>
> This file is missing the GCC Runtime Library Exception text in the
> licence header. That is unintentional, and it should have been present.
>
> libstdc++-v3/ChangeLog:
>
> * include/std/barrier: Add missing runtime exception.
> ---
>  libstdc++-v3/include/std/barrier | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/barrier
> b/libstdc++-v3/include/std/barrier
> index 2a2650546ad..997e0a8f7ab 100644
> --- a/libstdc++-v3/include/std/barrier
> +++ b/libstdc++-v3/include/std/barrier
> @@ -13,8 +13,13 @@
>  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  // GNU General Public License for more details.
>
> -// You should have received a copy of the GNU General Public License along
> -// with this library; see the file COPYING3.  If not see
> +// Under Section 7 of GPL version 3, you are granted additional
> +// permissions described in the GCC Runtime Library Exception, version
> +// 3.1, as published by the Free Software Foundation.
> +
> +// You should have received a copy of the GNU General Public License and
> +// a copy of the GCC Runtime Library Exception along with this program;
> +// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>  // .
>
>  // This implementation is based on libcxx/include/barrier
> --
> 2.37.3
>
>


Re: Patch ping (was Re: [PATCH] libstdc++: Clear padding bits in atomic compare_exchange)

2022-09-01 Thread Thomas Rodgers via Gcc-patches
Sorry for the delay in getting to this.

I am currently working on moving the bulk of the atomic wait implementation
into the .so. I'd like to get that work to a stable state before revisiting
this patch, but obviously if we want this to make it into GCC13, it needs
to happen sooner rather than later.

On Thu, Aug 25, 2022 at 3:11 AM Jakub Jelinek  wrote:

> On Tue, Jan 18, 2022 at 09:48:19PM +, Jonathan Wakely via Gcc-patches
> wrote:
> > On Tue, 2 Nov 2021 at 01:26, Thomas Rodgers  wrote:
> >
> > > This should address Jonathan's feedback and adds support for
> atomic_ref
> > >
> >
> >
> > >This change implements P0528 which requires that padding bits not
> > >participate in atomic compare exchange operations. All arguments to the
> > >generic template are 'sanitized' by the __builtin_clearpadding intrisic
> >
> > The name of the intrinsic and the word "instrinsic" have typos.
>
> I'd like to ping this patch.
> To make some progress, I've tried to incorporate some of Jonathan's
> review comments below, but it is incomplete.
>
> ChangeLog + wording above it fixed.
>
> > >
> > >   explicit
> > >   __atomic_ref(_Tp& __t) : _M_ptr(std::__addressof(__t))
> > >-  { __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) ==
> 0); }
> > >+  {
> > >+ __glibcxx_assert(((uintptr_t)_M_ptr % required_alignment) == 0);
> > >+#if __cplusplus > 201402L && __has_builtin(__builtin_clear_padding)
> > >+ __builtin_clear_padding(_M_ptr);
> > >+#endif
> > >+  }
> >
> > Is this safe to do?
> >
> > What if multiple threads all create a std::atomic_ref round the same
> object
> > at once, they'll all try to clear padding, and so race, won't they?
> > I don't think we can clear padding on atomic_ref construction, only on
> > store and RMW operations.
>
> Didn't touch the above.
> >
> >
> > >--- a/libstdc++-v3/include/std/atomic
> > >+++ b/libstdc++-v3/include/std/atomic
>
> The patch against this file doesn't apply it all.
>
> > >--- /dev/null
> > >+++
> >
> b/libstdc++-v3/testsuite/29_atomics/atomic_ref/compare_exchange_padding.cc
> > >@@ -0,0 +1,43 @@
> > >+// { dg-options "-std=gnu++2a" }
> > >+// { dg-do run { target c++2a } }
> >
> > This new test is using "2a" not "20".
>
> Fixed thus, but the other testcase wasn't in the patch at all.
>
> Here it is:
>
> libstdc++: Clear padding bits in atomic compare_exchange
>
> This change implements P0528 which requires that padding bits not
> participate in atomic compare exchange operations. All arguments to the
> generic template are 'sanitized' by the __builtin_clear_padding intrinsic
> before they are used in comparisons. This requires that any stores
> also sanitize the incoming value.
>
> Signed-off-by: Thomas Rodgers 
>
> libstdc++-v3/ChangeLog:
>
> * include/std/atomic (atomic::atomic(_Tp)): Clear padding for
> __cplusplus > 201703L.
> (atomic::store()): Clear padding.
> (atomic::exchange()): Likewise.
> (atomic::compare_exchange_weak()): Likewise.
> (atomic::compare_exchange_strong()): Likewise.
> * include/bits/atomic_base.h (__atomic_impl::__clear_padding()):
> New function.
> (__atomic_impl::__maybe_has_padding()): Likewise.
> (__atomic_impl::__compare_exchange()): Likewise.
> (__atomic_impl::compare_exchange_weak()): Delegate to
> __compare_exchange().
> (__atomic_impl::compare_exchange_strong()): Likewise.
> * testsuite/29_atomics/atomic/compare_exchange_padding.cc: New
> test.
> * testsuite/28_atomics/atomic_ref/compare_exchange_padding.cc:
> Likewise.
>
> --- a/libstdc++-v3/include/bits/atomic_base.h.jj2022-05-16
> 09:46:02.361059682 +0200
> +++ b/libstdc++-v3/include/bits/atomic_base.h   2022-08-25
> 12:06:13.758883172 +0200
> @@ -954,6 +954,87 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>
>/// @endcond
>
> +  // Implementation details of atomic padding handling
> +  namespace __atomic_impl
> +  {
> +template
> +  _GLIBCXX_ALWAYS_INLINE _Tp*
> +  __clear_padding(_Tp& __val) noexcept
> +  {
> +   auto* __ptr = std::__addressof(__val);
> +#if __has_builtin(__builtin_clear_padding)
> +   __builtin_clear_padding(std::__addressof(__val));
> +#endif
> +   return __ptr;
> +  }
> +
> +template
> +  constexpr bool
> +  __maybe_has_padding()
> +  {
> +#if ! __has_builtin(__builtin_clear_padding)
> +   return false;
> +#elif __has_builtin(__has_unique_object_representations)
> +   return !__has_unique_object_representations(_Tp)
> + && !is_floating_point<_Tp>::value;
> +#else
> +   return true;
> +#endif
> +  }
> +
> +template
> +  _GLIBCXX_ALWAYS_INLINE bool
> +  __compare_exchange(_Tp& __val, _Tp& __e, _Tp& __i, bool __weak,
> +memory_order __s, memory_order __f) noexcept
> +  {
> +   __glibcxx_assert(__is_valid_cmpexch_failure_order(__f));
> +
> +   if _GLIBCXX17_CONSTEXPR 

Re: libstdc++: Minor codegen improvement for atomic wait spinloop

2022-07-26 Thread Thomas Rodgers via Gcc-patches
This is now committed to trunk, backported to releases/gcc-12 and
releases/gcc-11.

Apologies for the delay, it's been a wild couple of weeks.

Tom.

On Thu, Jul 7, 2022 at 2:31 AM Jonathan Wakely  wrote:

> On Wed, 6 Jul 2022 at 22:42, Thomas Rodgers  wrote:
> >
> > Ok for trunk? backport?
>
> Yes, for all branches that have the atomic wait code.
>
>
> >
> > On Wed, Jul 6, 2022 at 1:56 PM Jonathan Wakely 
> wrote:
> >>
> >> On Wed, 6 Jul 2022 at 02:05, Thomas Rodgers via Libstdc++
> >>  wrote:
> >> >
> >> > This patch merges the spin loops in the atomic wait implementation
> which is
> >> > a
> >> > minor codegen improvement.
> >> >
> >> > libstdc++-v3/ChangeLog:
> >> >  * include/bits/atomic_wait.h (__atomic_spin): Merge spin
> loops.
> >>
> >> OK, thanks.
> >>
>
>


Re: libstdc++: Minor codegen improvement for atomic wait spinloop

2022-07-06 Thread Thomas Rodgers via Gcc-patches
Ok for trunk? backport?

On Wed, Jul 6, 2022 at 1:56 PM Jonathan Wakely  wrote:

> On Wed, 6 Jul 2022 at 02:05, Thomas Rodgers via Libstdc++
>  wrote:
> >
> > This patch merges the spin loops in the atomic wait implementation which
> is
> > a
> > minor codegen improvement.
> >
> > libstdc++-v3/ChangeLog:
> >  * include/bits/atomic_wait.h (__atomic_spin): Merge spin loops.
>
> OK, thanks.
>
>


libstdc++: Minor codegen improvement for atomic wait spinloop

2022-07-05 Thread Thomas Rodgers via Gcc-patches
This patch merges the spin loops in the atomic wait implementation which is
a
minor codegen improvement.

libstdc++-v3/ChangeLog:
 * include/bits/atomic_wait.h (__atomic_spin): Merge spin loops.


0001-libstdc-Minor-codegen-improvement-for-atomic-wait-sp.patch
Description: Binary data


Re: [PATCH] libstdc++: Make atomic notify_one and notify_all non-const

2022-04-22 Thread Thomas Rodgers via Gcc-patches
Committed to trunk, backported to releases/gcc-11.

On Fri, Feb 11, 2022 at 12:22 PM Jonathan Wakely  wrote:

> On Fri, 11 Feb 2022 at 17:40, Thomas Rodgers via Libstdc++
>  wrote:
> >
> > 
> > PR102994 "atomics: std::atomic::wait is not marked const" raises the
> > issue that the current libstdc++ implementation marks the notify members
> > const, the implementation strategy used by libstdc++, as well as libc++
> > and the Microsoft STL, do not require the atomic to be mutable (it is
> hard
> > to conceive of a desirable implementation approach that would require
> it).
> > The original paper proposing the wait/notify functionality for atomics
> > (p1185) also had these members marked const for the first three
> revisions,
> > but that was changed without explanation in r3 and subsequent revisions
> of
> > the paper.
> >
> > After raising the issue to the authors of p1185 and the author of the
> > libc++ implementation, the consensus seems to be "meh, it's harmless" so
> > there seems little appetite for an LWG issue to revisit the subject.
> >
> > This patch changes the libstdc++ implementation to be in agreement with
> > the standard by removing const from those notify_one/notify_all members.
> >
> > libstdc++-v3/ChangeLog:
>
> Might as well add a "PR libstdc++/102994" here to the bug gets updated
> automatically.
>
> OK for trunk with that change.
>
> > * include/bits/atomic_base.h (atomic_flag::notify_one,
> > notify_all): Remove const qualification.
> > (__atomic_base::notify_one, notify_all): Likewise.
> > * include/std/atomic (atomic::notify_one, notify_all):
> > Likewise.
> > (atomic::notify_one, notify_all): Likewise.
> > (atomic::notify_one, notify_all): Likewise.
> > (atomic_notify_one, atomic_notify_all): Likewise.
> > * testsuite/29_atomics/atomic/wait_notify/102994.cc: Adjust test
> > to account for change in notify_one/notify_all signature.
> >
> > Tested x86_64-pc-linux-gnu.
>
>


Re: [PATCH] libstdc++: Reduce header dependencies from PSTL headers [PR92546]

2022-03-17 Thread Thomas Rodgers via Gcc-patches
Looks ok to me. I just am curious, does the change to src/c++17/fs_path.cc
need to be part of this change (It's not obvious to me that it is related
to the other changes in the patch).

On Thu, Mar 17, 2022 at 12:01 PM Jonathan Wakely  wrote:

> Tested x86_64-linux. Tom, any objection?
>
> -- >8 --
>
> This avoids including the whole of  in , as the
>  header only actually needs std::pair.
>
> This also avoids including  in , which only
> needs , std::bad_alloc, and std::terminate (which can be
> repalced with std::__terminate). This matters less, because
>  is only included by the  headers and they
> all use  anyway, and are only included by .
>
> libstdc++-v3/ChangeLog:
>
> PR libstdc++/92546
> * include/pstl/glue_algorithm_defs.h: Replace  with
> .
> * include/pstl/utils.h: Replace  with .
> (__pstl::__internal::__except_handler): Use std::__terminate
> instead of std::terminate.
> * src/c++17/fs_path.cc: Include .
> * testsuite/25_algorithms/adjacent_find/constexpr.cc: Include
> .
> * testsuite/25_algorithms/binary_search/constexpr.cc: Likewise.
> * testsuite/25_algorithms/clamp/constrained.cc: Likewise.
> * testsuite/25_algorithms/equal/constrained.cc: Likewise.
> * testsuite/25_algorithms/for_each/constrained.cc: Likewise.
> * testsuite/25_algorithms/includes/constrained.cc: Likewise.
> * testsuite/25_algorithms/is_heap/constexpr.cc: Likewise.
> * testsuite/25_algorithms/is_heap_until/constexpr.cc: Likewise.
> * testsuite/25_algorithms/is_permutation/constrained.cc: Include
> .
> * testsuite/25_algorithms/is_sorted/constexpr.cc: Include
> .
> * testsuite/25_algorithms/is_sorted_until/constexpr.cc:
> Likewise.
> * testsuite/25_algorithms/lexicographical_compare/constexpr.cc:
> Likewise.
> * testsuite/25_algorithms/lexicographical_compare/constrained.cc:
> Likewise.
> * testsuite/25_algorithms/lexicographical_compare_three_way/1.cc:
> Include .
> * testsuite/25_algorithms/lower_bound/constexpr.cc: Include
> .
> * testsuite/25_algorithms/max/constrained.cc: Likewise.
> * testsuite/25_algorithms/max_element/constrained.cc: Likewise.
> * testsuite/25_algorithms/min/constrained.cc: Likewise.
> * testsuite/25_algorithms/min_element/constrained.cc: Likewise.
> * testsuite/25_algorithms/minmax_element/constrained.cc:
> Likewise.
> * testsuite/25_algorithms/mismatch/constexpr.cc: Likewise.
> * testsuite/25_algorithms/move/93872.cc: Likewise.
> * testsuite/25_algorithms/move_backward/93872.cc: Include
> .
> * testsuite/25_algorithms/nth_element/constexpr.cc: Include
> .
> * testsuite/25_algorithms/partial_sort/constexpr.cc: Likewise.
> * testsuite/25_algorithms/partial_sort_copy/constexpr.cc:
> Likewise.
> * testsuite/25_algorithms/search/constexpr.cc: Likewise.
> * testsuite/25_algorithms/search_n/constrained.cc: Likewise.
> * testsuite/25_algorithms/set_difference/constexpr.cc: Likewise.
> * testsuite/25_algorithms/set_difference/constrained.cc:
> Likewise.
> * testsuite/25_algorithms/set_intersection/constexpr.cc:
> Likewise.
> * testsuite/25_algorithms/set_intersection/constrained.cc:
> Likewise.
> * testsuite/25_algorithms/set_symmetric_difference/constexpr.cc:
> Likewise.
> * testsuite/25_algorithms/set_union/constexpr.cc: Likewise.
> * testsuite/25_algorithms/set_union/constrained.cc: Likewise.
> * testsuite/25_algorithms/sort/constexpr.cc: Likewise.
> * testsuite/25_algorithms/sort_heap/constexpr.cc: Likewise.
> * testsuite/25_algorithms/transform/constrained.cc: Likewise.
> * testsuite/25_algorithms/unique/constexpr.cc: Likewise.
> * testsuite/25_algorithms/unique/constrained.cc: Likewise.
> * testsuite/25_algorithms/unique_copy/constexpr.cc: Likewise.
> * testsuite/25_algorithms/upper_bound/constexpr.cc: Likewise.
> * testsuite/std/ranges/adaptors/elements.cc: Include .
> * testsuite/std/ranges/adaptors/lazy_split.cc: Likewise.
> * testsuite/std/ranges/adaptors/split.cc: Likewise.
> ---
>  libstdc++-v3/include/pstl/glue_algorithm_defs.h   | 2 +-
>  libstdc++-v3/include/pstl/utils.h | 4 ++--
>  libstdc++-v3/src/c++17/fs_path.cc | 1 +
>  .../testsuite/25_algorithms/adjacent_find/constexpr.cc| 1 +
>  .../testsuite/25_algorithms/binary_search/constexpr.cc| 1 +
>  libstdc++-v3/testsuite/25_algorithms/clamp/constrained.cc | 1 +
>  libstdc++-v3/testsuite/25_algorithms/equal/constrained.cc | 1 +
>  libstdc++-v3/testsuite/25_algorithms/for_each/constrained.cc  | 1 +
>  

[PATCH] libstdc++: Make atomic notify_one and notify_all non-const

2022-02-11 Thread Thomas Rodgers via Gcc-patches

PR102994 "atomics: std::atomic::wait is not marked const" raises the
issue that the current libstdc++ implementation marks the notify members
const, the implementation strategy used by libstdc++, as well as libc++
and the Microsoft STL, do not require the atomic to be mutable (it is hard
to conceive of a desirable implementation approach that would require it).
The original paper proposing the wait/notify functionality for atomics
(p1185) also had these members marked const for the first three revisions,
but that was changed without explanation in r3 and subsequent revisions of
the paper.

After raising the issue to the authors of p1185 and the author of the
libc++ implementation, the consensus seems to be "meh, it's harmless" so
there seems little appetite for an LWG issue to revisit the subject.

This patch changes the libstdc++ implementation to be in agreement with
the standard by removing const from those notify_one/notify_all members.

libstdc++-v3/ChangeLog:
* include/bits/atomic_base.h (atomic_flag::notify_one,
notify_all): Remove const qualification.
(__atomic_base::notify_one, notify_all): Likewise.
* include/std/atomic (atomic::notify_one, notify_all):
Likewise.
(atomic::notify_one, notify_all): Likewise.
(atomic::notify_one, notify_all): Likewise.
(atomic_notify_one, atomic_notify_all): Likewise.
* testsuite/29_atomics/atomic/wait_notify/102994.cc: Adjust test
to account for change in notify_one/notify_all signature.

Tested x86_64-pc-linux-gnu.
From 7ed6dfae5a0a7a9e56291d780e44f99d644847e0 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Thu, 10 Feb 2022 18:55:16 -0800
Subject: [PATCH] libstdc++: Make atomic notify_one and notify_all non-const


PR102994 "atomics: std::atomic::wait is not marked const" raises the
issue that the current libstdc++ implementation marks the notify members
const, the implementation strategy used by libstdc++, as well as libc++
and the Microsoft STL, do not require the atomic to be mutable (it is hard
to conceive of a desirable implementation approach that would require it).
The original paper proposing the wait/notify functionality for atomics
(p1185) also had these members marked const for the first three revisions,
but that was changed without explanation in r3 and subsequent revisions of
the paper.

After raising the issue to the authors of p1185 and the author of the
libc++ implementation, the consensus seems to be "meh, it's harmless" so
there seems little appetite for an LWG issue to revisit the subject.

This patch changes the libstdc++ implementation to be in agreement with
the standard by removing const from those notify_one/notify_all members.

libstdc++-v3/ChangeLog:
	* include/bits/atomic_base.h (atomic_flag::notify_one,
	notify_all): Remove const qualification.
	(__atomic_base::notify_one, notify_all): Likewise.
	* include/std/atomic (atomic::notify_one, notify_all):
	Likewise.
	(atomic::notify_one, notify_all): Likewise.
	(atomic::notify_one, notify_all): Likewise.
	(atomic_notify_one, atomic_notify_all): Likewise.
	* testsuite/29_atomics/atomic/wait_notify/102994.cc: Adjust test
	to account for change in notify_one/notify_all signature.
---
 libstdc++-v3/include/bits/atomic_base.h  |  8 
 libstdc++-v3/include/std/atomic  | 16 
 .../29_atomics/atomic/wait_notify/102994.cc  |  4 ++--
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index d86766cf39b..adfd9fa3027 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -252,13 +252,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 // TODO add const volatile overload
 
 _GLIBCXX_ALWAYS_INLINE void
-notify_one() const noexcept
+notify_one() noexcept
 { std::__atomic_notify_address(&_M_i, false); }
 
 // TODO add const volatile overload
 
 _GLIBCXX_ALWAYS_INLINE void
-notify_all() const noexcept
+notify_all() noexcept
 { std::__atomic_notify_address(&_M_i, true); }
 
 // TODO add const volatile overload
@@ -600,13 +600,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // TODO add const volatile overload
 
   _GLIBCXX_ALWAYS_INLINE void
-  notify_one() const noexcept
+  notify_one() noexcept
   { std::__atomic_notify_address(&_M_i, false); }
 
   // TODO add const volatile overload
 
   _GLIBCXX_ALWAYS_INLINE void
-  notify_all() const noexcept
+  notify_all() noexcept
   { std::__atomic_notify_address(&_M_i, true); }
 
   // TODO add const volatile overload
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index bc57659b6e7..d819b6bf41e 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -172,11 +172,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 // TODO add const volatile overload
 
 void
-

Re: [PATCH] libstdc++: Strengthen memory order for atomic::wait/notify

2022-02-10 Thread Thomas Rodgers via Gcc-patches
Committed to trunk, backported to gcc-11.

On Wed, Feb 9, 2022 at 12:37 PM Jonathan Wakely  wrote:

> On Wed, 9 Feb 2022 at 17:35, Thomas Rodgers via Libstdc++
>  wrote:
> >
> > This patch changes the memory order used in the spin wait code to match
> > that of libc++.
>
> OK for trunk (and gcc-11 if needed).
>
>


Re: [PATCH] libstdc++: Fix deadlock in atomic wait [PR104442]

2022-02-09 Thread Thomas Rodgers via Gcc-patches
Tested x86_64-pc-linux-gnu, committed to master, backported to gcc-11.

On Wed, Feb 9, 2022 at 9:14 AM Jonathan Wakely  wrote:

> On Wed, 9 Feb 2022 at 17:10, Thomas Rodgers wrote:
> >
> > Updated patch. I reverted the memory order change (and will submit that
> as another patch) and fixed some spelling and grammar errors.
>
> OK for trunk and gcc-11, thanks.
>
>


[PATCH] libstdc++: Strengthen memory order for atomic::wait/notify

2022-02-09 Thread Thomas Rodgers via Gcc-patches
This patch changes the memory order used in the spin wait code to match
that of libc++.
From 92caa08b272520ec4a272b302b37d8fb47afb2ab Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Wed, 9 Feb 2022 09:26:00 -0800
Subject: [PATCH] libstdc++: Strengthen memory order for atomic::wait/notify
 (spinning)

This patch changes the memory order used in the spin wait code to match
that of libc++.

libstdc++-v3/ChangeLog:
	* includ/bits/atomic_wait.h (__waiter_base::_S_do_spin,
	__waiter_base::_S_do_spin_v): Change memory order from relaxed
	to acquire.
---
 libstdc++-v3/include/bits/atomic_wait.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index 6ce7f9343cf..125b1cad886 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -332,7 +332,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  }
 	else
 	  {
-		__atomic_load(__addr, &__val, __ATOMIC_RELAXED);
+		__atomic_load(__addr, &__val, __ATOMIC_ACQUIRE);
 	  }
 	return __atomic_spin(__pred, __spin);
 	  }
@@ -353,7 +353,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		 __platform_wait_t& __val,
 		 _Spin __spin = _Spin{ })
 	  {
-	__atomic_load(__addr, &__val, __ATOMIC_RELAXED);
+	__atomic_load(__addr, &__val, __ATOMIC_ACQUIRE);
 	return __atomic_spin(__pred, __spin);
 	  }
 
-- 
2.34.1



Re: [PATCH] libstdc++: Fix deadlock in atomic wait [PR104442]

2022-02-09 Thread Thomas Rodgers via Gcc-patches
Updated patch. I reverted the memory order change (and will submit that as
another patch) and fixed some spelling and grammar errors.

On Wed, Feb 9, 2022 at 2:43 AM Jonathan Wakely  wrote:

> On Wed, 9 Feb 2022 at 00:57, Thomas Rodgers via Libstdc++
>  wrote:
> >
> > This issue was observed as a deadloack in
> > 29_atomics/atomic/wait_notify/100334.cc on vxworks. When a wait is
> > "laundered" (e.g. type T* does not suffice as a waitable address for the
> > platform's native waiting primitive), the address waited is that of the
> > _M_ver member of __waiter_pool_base, so several threads may wait on the
> > same address for unrelated atomic's. As noted in the PR, the
> > implementation correctly exits the wait for the thread who's data
> > changed, but not for any other threads waiting on the same address.
> >
> > As noted in the PR the __waiter::_M_do_wait_v member was correctly
> exiting
> > but the other waiters were not reloaded the value of _M_ver before
> > re-entering the wait.
> >
> > Moving the spin call inside the loop accomplishes this, and is
> > consistent with the predicate accepting version of __waiter::_M_do_wait.
>
> There is a change to the memory order in _S_do_spin_v which is not
> described in the commit msg or the changelog. Is that unintentional?
>
> (Aside: why do we even have _S_do_spin_v, it's called in exactly one
> place, so could just be inlined into _M_do_spin_v, couldn't it?)
>
>
From b39283d5100305e7a95d59324059de9952d3a858 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Tue, 8 Feb 2022 16:33:36 -0800
Subject: [PATCH] libstdc++: Fix deadlock in atomic wait [PR104442]

This issue was observed as a deadlock in
29_atomics/atomic/wait_notify/100334.cc on vxworks. When a wait is
"laundered" (e.g. type T* does not suffice as a waitable address for the
platform's native waiting primitive), the address waited is that of the
_M_ver member of __waiter_pool_base, so several threads may wait on the
same address for unrelated atomic objects. As noted in the PR, the
implementation correctly exits the wait for the thread whose data
changed, but not for any other threads waiting on the same address.

As noted in the PR the __waiter::_M_do_wait_v member was correctly exiting
but the other waiters were not reloading the value of _M_ver before
re-entering the wait.

Moving the spin call inside the loop accomplishes this, and is
consistent with the predicate accepting version of __waiter::_M_do_wait.

libstdc++-v3/ChangeLog:

	PR libstdc++/104442
	* include/bits/atomic_wait.h (__waiter::_M_do_wait_v): Move spin
	 loop inside do loop so that threads failing the wait, reload
	 _M_ver.
---
 libstdc++-v3/include/bits/atomic_wait.h | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index d7de0d7eb9e..6ce7f9343cf 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -388,12 +388,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  void
 	  _M_do_wait_v(_Tp __old, _ValFn __vfn)
 	  {
-	__platform_wait_t __val;
-	if (__base_type::_M_do_spin_v(__old, __vfn, __val))
-	  return;
-
 	do
 	  {
+		__platform_wait_t __val;
+		if (__base_type::_M_do_spin_v(__old, __vfn, __val))
+		  return;
 		__base_type::_M_w._M_do_wait(__base_type::_M_addr, __val);
 	  }
 	while (__detail::__atomic_compare(__old, __vfn()));
-- 
2.34.1



Re: [PATCH] libstdc++: Fix deadlock in atomic wait [PR104442]

2022-02-09 Thread Thomas Rodgers via Gcc-patches
Excessively enthusiastic refactoring. I expect to rewrite most of this as
part of the work I'm starting now for GCC13 stage1.

On Wed, Feb 9, 2022 at 2:43 AM Jonathan Wakely  wrote:

> On Wed, 9 Feb 2022 at 00:57, Thomas Rodgers via Libstdc++
>  wrote:
> >
> > This issue was observed as a deadloack in
> > 29_atomics/atomic/wait_notify/100334.cc on vxworks. When a wait is
> > "laundered" (e.g. type T* does not suffice as a waitable address for the
> > platform's native waiting primitive), the address waited is that of the
> > _M_ver member of __waiter_pool_base, so several threads may wait on the
> > same address for unrelated atomic's. As noted in the PR, the
> > implementation correctly exits the wait for the thread who's data
> > changed, but not for any other threads waiting on the same address.
> >
> > As noted in the PR the __waiter::_M_do_wait_v member was correctly
> exiting
> > but the other waiters were not reloaded the value of _M_ver before
> > re-entering the wait.
> >
> > Moving the spin call inside the loop accomplishes this, and is
> > consistent with the predicate accepting version of __waiter::_M_do_wait.
>
> There is a change to the memory order in _S_do_spin_v which is not
> described in the commit msg or the changelog. Is that unintentional?
>
> (Aside: why do we even have _S_do_spin_v, it's called in exactly one
> place, so could just be inlined into _M_do_spin_v, couldn't it?)
>
>


[PATCH] libstdc++: Fix deadlock in atomic wait [PR104442]

2022-02-08 Thread Thomas Rodgers via Gcc-patches
This issue was observed as a deadloack in
29_atomics/atomic/wait_notify/100334.cc on vxworks. When a wait is
"laundered" (e.g. type T* does not suffice as a waitable address for the
platform's native waiting primitive), the address waited is that of the
_M_ver member of __waiter_pool_base, so several threads may wait on the
same address for unrelated atomic's. As noted in the PR, the
implementation correctly exits the wait for the thread who's data
changed, but not for any other threads waiting on the same address.

As noted in the PR the __waiter::_M_do_wait_v member was correctly exiting
but the other waiters were not reloaded the value of _M_ver before
re-entering the wait.

Moving the spin call inside the loop accomplishes this, and is
consistent with the predicate accepting version of __waiter::_M_do_wait.
From ee66736beca3dce4bc09350c5407a2ac7219fbec Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Tue, 8 Feb 2022 16:33:36 -0800
Subject: [PATCH] libstdc++: Fix deadlock in atomic wait [PR104442]

This issue was observed as a deadloack in
29_atomics/atomic/wait_notify/100334.cc on vxworks. When a wait is
"laundered" (e.g. type T* does not suffice as a waitable address for the
platform's native waiting primitive), the address waited is that of the
_M_ver member of __waiter_pool_base, so several threads may wait on the
same address for unrelated atomic's. As noted in the PR, the
implementation correctly exits the wait for the thread who's data
changed, but not for any other threads waiting on the same address.

As noted in the PR the __waiter::_M_do_wait_v member was correctly exiting
but the other waiters were not reloaded the value of _M_ver before
re-entering the wait.

Moving the spin call inside the loop accomplishes this, and is
consistent with the predicate accepting version of __waiter::_M_do_wait.

libstdc++-v3/ChangeLog:

	PR libstdc++/104442
	* include/bits/atomic_wait.h (__waiter::_M_do_wait_v): Move spin
	 loop inside do loop so that threads failing the wait, reload
	 _M_ver.
---
 libstdc++-v3/include/bits/atomic_wait.h | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index d7de0d7eb9e..33ce26ade1b 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -332,7 +332,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  }
 	else
 	  {
-		__atomic_load(__addr, &__val, __ATOMIC_RELAXED);
+		__atomic_load(__addr, &__val, __ATOMIC_SEQ_CST);
 	  }
 	return __atomic_spin(__pred, __spin);
 	  }
@@ -388,12 +388,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  void
 	  _M_do_wait_v(_Tp __old, _ValFn __vfn)
 	  {
-	__platform_wait_t __val;
-	if (__base_type::_M_do_spin_v(__old, __vfn, __val))
-	  return;
-
 	do
 	  {
+		__platform_wait_t __val;
+		if (__base_type::_M_do_spin_v(__old, __vfn, __val))
+		  return;
 		__base_type::_M_w._M_do_wait(__base_type::_M_addr, __val);
 	  }
 	while (__detail::__atomic_compare(__old, __vfn()));
-- 
2.34.1



Re: [PATCH] Strengthen memory memory order for atomic::wait/notify

2022-02-01 Thread Thomas Rodgers via Gcc-patches
Tested x86_64-pc-linux-gnu, committed to master.
Backported to GCC-11.

On Sun, Jan 16, 2022 at 12:31 PM Jonathan Wakely  wrote:

>
>
> On Sun, 16 Jan 2022 at 01:48, Thomas Rodgers via Libstdc++ <
> libstd...@gcc.gnu.org> wrote:
>
>> This patch updates the memory order of atomic accesses to the waiter's
>> count to match libc++'s usage. It should be backported to GCC11.
>>
>
> The commit subject line says "memory memory order", OK for trunk and
> gcc-11 with that fixed.
>
>
>> Tested x86_64-pc-linux-gnu.
>>
>


[PATCH] Strengthen memory memory order for atomic::wait/notify

2022-01-15 Thread Thomas Rodgers via Gcc-patches
This patch updates the memory order of atomic accesses to the waiter's
count to match libc++'s usage. It should be backported to GCC11.

Tested x86_64-pc-linux-gnu.
From f5ed7674f86283db4f4ff49a2cc65d4f852413a1 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Sat, 15 Jan 2022 17:40:49 -0800
Subject: [PATCH] Strengthen memory memory order for atomic::wait/notify

This matches the memory order in libc++.

libstdc++-v3/ChangeLog:
	* libstdc++-v3/include/bits/atomic_wait.h: Change memory order
	from Acquire/Release with relaxed loads to SeqCst+Release for
	accesses to the waiter's count.
---
 libstdc++-v3/include/bits/atomic_wait.h | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index 05cf0013d2a..d7de0d7eb9e 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -209,18 +209,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   void
   _M_enter_wait() noexcept
-  { __atomic_fetch_add(&_M_wait, 1, __ATOMIC_ACQ_REL); }
+  { __atomic_fetch_add(&_M_wait, 1, __ATOMIC_SEQ_CST); }
 
   void
   _M_leave_wait() noexcept
-  { __atomic_fetch_sub(&_M_wait, 1, __ATOMIC_ACQ_REL); }
+  { __atomic_fetch_sub(&_M_wait, 1, __ATOMIC_RELEASE); }
 
   bool
   _M_waiting() const noexcept
   {
 	__platform_wait_t __res;
-	__atomic_load(&_M_wait, &__res, __ATOMIC_ACQUIRE);
-	return __res > 0;
+	__atomic_load(&_M_wait, &__res, __ATOMIC_SEQ_CST);
+	return __res != 0;
   }
 
   void
@@ -258,7 +258,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	__platform_wait(__addr, __old);
 #else
 	__platform_wait_t __val;
-	__atomic_load(__addr, &__val, __ATOMIC_RELAXED);
+	__atomic_load(__addr, &__val, __ATOMIC_SEQ_CST);
 	if (__val == __old)
 	  {
 	lock_guard __l(_M_mtx);
@@ -309,7 +309,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	{
 	  if (_M_laundered())
 	{
-	  __atomic_fetch_add(_M_addr, 1, __ATOMIC_ACQ_REL);
+	  __atomic_fetch_add(_M_addr, 1, __ATOMIC_SEQ_CST);
 	  __all = true;
 	}
 	  _M_w._M_notify(_M_addr, __all, __bare);
-- 
2.31.1



[PATCH] libstdc++: Add missing free functions for atomic_flag [PR103934]

2022-01-14 Thread Thomas Rodgers via Gcc-patches

From c2b74fd7cf2668d288f46da42565e5eb954e5e1f Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Fri, 14 Jan 2022 18:30:27 -0800
Subject: [PATCH] libstdc++: Add missing free functions for atomic_flag
 [PR103934]

libstdc++-v3/ChangeLog:

	PR103934
	* include/std/atomic: Add missing free functions.
	* testsuite/29_atomics/atomic_flag/wait_notify/1.cc:
	Add test case to cover missing atomic_flag free functions.
---
 libstdc++-v3/include/std/atomic   | 39 +++
 .../29_atomics/atomic_flag/wait_notify/1.cc   | 27 +++--
 2 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 9df17704f7e..92c96a9b047 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -1216,6 +1216,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 memory_order __m) noexcept
   { return __a->test_and_set(__m); }
 
+#if __cpp_lib_atomic_flag_test
+  inline bool
+  atomic_flag_test(const atomic_flag* __a) noexcept
+  { return __a->test(); }
+
+  inline bool
+  atomic_flag_test(const volatile atomic_flag* __a) noexcept
+  { return __a->test(); }
+
+  inline bool
+  atomic_flag_test_explicit(const atomic_flag* __a,
+			memory_order __m) noexcept
+  { return __a->test(__m); }
+
+  inline bool
+  atomic_flag_test_explicit(const volatile atomic_flag* __a,
+			memory_order __m) noexcept
+  { return __a->test(__m); }
+#endif
+
   inline void
   atomic_flag_clear_explicit(atomic_flag* __a, memory_order __m) noexcept
   { __a->clear(__m); }
@@ -1241,6 +1261,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   atomic_flag_clear(volatile atomic_flag* __a) noexcept
   { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
 
+#if __cpp_lib_atomic_wait
+  inline void
+  atomic_flag_wait(const atomic_flag* __a, bool __old) noexcept
+  { __a->wait(__old); }
+
+  inline void
+  atomic_flag_wait_explicit(const atomic_flag* __a, bool __old,
+		   std::memory_order __m) noexcept
+  { __a->wait(__old, __m); }
+
+  inline void
+  atomic_flag_notify_one(const atomic_flag* __a) noexcept
+  { __a->notify_one(); }
+
+  inline void
+  atomic_flag_notify_all(const atomic_flag* __a) noexcept
+  { __a->notify_all(); }
+#endif // __cpp_lib_atomic_wait
+
 
   template
 using __atomic_val_t = typename atomic<_Tp>::value_type;
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
index 87a104059ff..1050b72a1c6 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
@@ -26,8 +26,8 @@
 
 #include 
 
-int
-main()
+void
+test01()
 {
   std::atomic_flag a;
   VERIFY( !a.test() );
@@ -39,5 +39,26 @@ main()
 });
   a.wait(false);
   t.join();
-  return 0;
+}
+
+void
+test02()
+{
+  std::atomic_flag a;
+  VERIFY( !std::atomic_flag_test() );
+  std::atomic_flag_wait(, true);
+  std::thread t([&]
+{
+  std::atomic_flag_test_and_set();
+  std::atomic_flag_notify_one();
+});
+  std::atomic_flag_wait(, false);
+  t.join();
+}
+
+int
+main()
+{
+  test01();
+  test02();
 }
-- 
2.31.1



Re: libstdc++: Make atomic::wait() const [PR102994]

2021-12-09 Thread Thomas Rodgers via Gcc-patches
Tested uild-x86_64-pc-linux-gnu, pushed to trunk and gcc-11.

On Thu, Nov 25, 2021 at 1:24 PM Jonathan Wakely  wrote:

> On Wed, 24 Nov 2021 at 01:27, Thomas Rodgers wrote:
> >
> > const qualification was also missing in the free functions for
> wait/wait_explicit/notify_one/notify_all. Revised patch attached.
>
> Please tweak the whitespace in the new test:
>
> > +test1(const std::atomic , char*p)
>
> The '&' should be on the type not the variable, and there should be a
> space before 'p':
>
> > +test1(const std::atomic& a, char* p)
>
> OK for trunk and gcc-11 with that tweak, thanks!
>
>


Re: libstdc++: Make atomic::wait() const [PR102994]

2021-11-23 Thread Thomas Rodgers via Gcc-patches
const qualification was also missing in the free functions for
wait/wait_explicit/notify_one/notify_all. Revised patch attached.

On Tue, Nov 9, 2021 at 11:40 AM Jonathan Wakely  wrote:

> On Tue, 9 Nov 2021 at 18:09, Thomas Rodgers wrote:
>
>> Revised patch attached.
>>
>
> OK for trunk and gcc-11, thanks.
>
>
>
>> On Fri, Nov 5, 2021 at 4:46 PM Jonathan Wakely 
>> wrote:
>>
>>> On Fri, 5 Nov 2021 at 21:51, Jonathan Wakely via Libstdc++
>>>  wrote:
>>> >
>>> > OK, thanks.
>>>
>>> Actually, we should really have a test to verify it can be called on a
>>> const object. Please add something when you commit, it can be dumb and
>>> simple, it just needs to verify that it can be called.
>>>
>>>
>>> >
>>> >
>>> > On Fri, 5 Nov 2021 at 21:46, Thomas Rodgers via Libstdc++ <
>>> > libstd...@gcc.gnu.org> wrote:
>>> >
>>> > >
>>> > >
>>>
>>>
From 337c147b5bb0265522d5aac4beefb3dec1ebe026 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Tue, 9 Nov 2021 09:42:49 -0800
Subject: [PATCH] libstdc++: Make atomic::wait() const [PR102994]

This was an oversight in the original commit adding wait/notify
to atomic.

libstdc++-v3/ChangeLog:

	PR libstdc++/102994
	* include/bits/atomic_base.h (__atomic_base<_PTp*>::wait()):
	Add const qualifier.
	* include/std/atomic (atomic<_Tp*>::wait(), atomic_wait(),
	atomic_wait_explicit(), atomic_notify_one(), atomic_notify_all()):
	Likewise.
	* testsuite/29_atomics/atomic/wait_notify/102994.cc:
	New test.
---
 libstdc++-v3/include/bits/atomic_base.h   |  2 +-
 libstdc++-v3/include/std/atomic   |  8 
 .../29_atomics/atomic/wait_notify/102994.cc   | 19 +++
 3 files changed, 24 insertions(+), 5 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 9e18aadadaf..a104adc1a10 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -893,7 +893,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #if __cpp_lib_atomic_wait
   _GLIBCXX_ALWAYS_INLINE void
   wait(__pointer_type __old,
-	   memory_order __m = memory_order_seq_cst) noexcept
+	   memory_order __m = memory_order_seq_cst) const noexcept
   {
 	std::__atomic_wait_address_v(&_M_p, __old,
  [__m, this]
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 936dd50ba1c..9b827b425dc 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -646,9 +646,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	__cmpexch_failure_order(__m));
   }
 
-#if __cpp_lib_atomic_wait 
+#if __cpp_lib_atomic_wait
 void
-wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) noexcept
+wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) const noexcept
 { _M_b.wait(__old, __m); }
 
 // TODO add const volatile overload
@@ -1434,12 +1434,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template
 inline void
-atomic_notify_one(atomic<_Tp>* __a) noexcept
+atomic_notify_one(const atomic<_Tp>* __a) noexcept
 { __a->notify_one(); }
 
   template
 inline void
-atomic_notify_all(atomic<_Tp>* __a) noexcept
+atomic_notify_all(const atomic<_Tp>* __a) noexcept
 { __a->notify_all(); }
 #endif // __cpp_lib_atomic_wait
 
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc
new file mode 100644
index 000..28c3d66f451
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc
@@ -0,0 +1,19 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+// { dg-require-gthreads "" }
+
+#include 
+
+void
+test1(const std::atomic , char*p)
+{
+  a.wait(p);
+}
+
+void
+test2(const std::atomic* a, int v)
+{
+  std::atomic_wait(a, v);
+  std::atomic_notify_one(a);
+  std::atomic_notify_all(a);
+}
-- 
2.31.1



Re: libstdc++: Make atomic::wait() const [PR102994]

2021-11-09 Thread Thomas Rodgers via Gcc-patches
Revised patch attached.

On Fri, Nov 5, 2021 at 4:46 PM Jonathan Wakely 
wrote:

> On Fri, 5 Nov 2021 at 21:51, Jonathan Wakely via Libstdc++
>  wrote:
> >
> > OK, thanks.
>
> Actually, we should really have a test to verify it can be called on a
> const object. Please add something when you commit, it can be dumb and
> simple, it just needs to verify that it can be called.
>
>
> >
> >
> > On Fri, 5 Nov 2021 at 21:46, Thomas Rodgers via Libstdc++ <
> > libstd...@gcc.gnu.org> wrote:
> >
> > >
> > >
>
>
From 69737be7cda5328eb0f67c9725c3b691bcb6cb2f Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Tue, 9 Nov 2021 09:42:49 -0800
Subject: [PATCH] libstdc++: Make atomic::wait() const [PR102994]

This was an oversight in the original commit adding wait/notify
to atomic.

libstdc++-v3/ChangeLog:

	PR libstdc++/102994
	* include/bits/atomic_base.h (__atomic_base<_PTp*>::wait()):
	Add const qualifier.
	* include/std/atomic (atomic<_Tp*>::wait()):
	Likewise.
	* testsuite/29_atomics/atomic/wait_notify/102994.cc:
	New test.
---
 libstdc++-v3/include/bits/atomic_base.h   |  2 +-
 libstdc++-v3/include/std/atomic   |  4 ++--
 .../testsuite/29_atomics/atomic/wait_notify/102994.cc | 11 +++
 3 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 9e18aadadaf..a104adc1a10 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -893,7 +893,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #if __cpp_lib_atomic_wait
   _GLIBCXX_ALWAYS_INLINE void
   wait(__pointer_type __old,
-	   memory_order __m = memory_order_seq_cst) noexcept
+	   memory_order __m = memory_order_seq_cst) const noexcept
   {
 	std::__atomic_wait_address_v(&_M_p, __old,
  [__m, this]
diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic
index 936dd50ba1c..c971b712ef6 100644
--- a/libstdc++-v3/include/std/atomic
+++ b/libstdc++-v3/include/std/atomic
@@ -646,9 +646,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	__cmpexch_failure_order(__m));
   }
 
-#if __cpp_lib_atomic_wait 
+#if __cpp_lib_atomic_wait
 void
-wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) noexcept
+wait(__pointer_type __old, memory_order __m = memory_order_seq_cst) const noexcept
 { _M_b.wait(__old, __m); }
 
 // TODO add const volatile overload
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc
new file mode 100644
index 000..bc814a708aa
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/102994.cc
@@ -0,0 +1,11 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+// { dg-require-gthreads "" }
+
+#include 
+
+void
+test_it(const std::atomic , char*p)
+{
+  a.wait(p);
+}
-- 
2.31.1



libstdc++: Make atomic::wait() const [PR102994]

2021-11-05 Thread Thomas Rodgers via Gcc-patches

From 360c094a0725bb0cc444115c0377db10e5e9ae1f Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Fri, 5 Nov 2021 14:30:24 -0700
Subject: [PATCH] libstdc++: Make atomic::wait() const [PR102994]

This was an oversight in the original commit adding wait/notify
to atomic.

libstdc++-v3/ChangeLog:

	PR libstdc++/102994
	* include/bits/atomic_base.h (__atomic_base<_PTp*>::wait())
	add const qualifier.
---
 libstdc++-v3/include/bits/atomic_base.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 9e18aadadaf..a104adc1a10 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -893,7 +893,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #if __cpp_lib_atomic_wait
   _GLIBCXX_ALWAYS_INLINE void
   wait(__pointer_type __old,
-	   memory_order __m = memory_order_seq_cst) noexcept
+	   memory_order __m = memory_order_seq_cst) const noexcept
   {
 	std::__atomic_wait_address_v(&_M_p, __old,
  [__m, this]
-- 
2.31.1



Re: [PATCH] libstdc++: Clear padding bits in atomic compare_exchange

2021-11-01 Thread Thomas Rodgers via Gcc-patches
This should address Jonathan's feedback and adds support for atomic_ref

On Wed, Sep 29, 2021 at 5:14 AM Jonathan Wakely  wrote:

> On Mon, 27 Sept 2021 at 15:11, Thomas Rodgers 
> wrote:
> >
> > From: Thomas Rodgers 
> >
> > Now with checks for __has_builtin(__builtin_clear_padding)
> >
> > This change implements P0528 which requires that padding bits not
> > participate in atomic compare exchange operations. All arguments to the
> > generic template are 'sanitized' by the __builtin_clearpadding intrisic
> > before they are used in comparisons. This alrequires that any stores
> > also sanitize the incoming value.
> >
> > Signed-off-by: Thomas Rodgers 
> >
> > libstdc++=v3/ChangeLog:
> >
> > * include/std/atomic (atomic::atomic(_Tp) clear padding for
> > __cplusplus > 201703L.
> > (atomic::store()) Clear padding.
> > (atomic::exchange()) Likewise.
> > (atomic::compare_exchange_weak()) Likewise.
> > (atomic::compare_exchange_strong()) Likewise.
>
> Don't we also need this for std::atomic_ref, i.e. for the
> __atomic_impl free functions in ?
>
> There we don't have any distinction between atomic_ref
> and atomic_ref, they both use the same
> implementations. But I think that's OK, as I think the built-in is
> smart enough to be a no-op for types with no padding.
>
> > * testsuite/29_atomics/atomic/compare_exchange_padding.cc: New
> > test.
> > ---
> >  libstdc++-v3/include/std/atomic   | 41 +-
> >  .../atomic/compare_exchange_padding.cc| 42 +++
> >  2 files changed, 81 insertions(+), 2 deletions(-)
> >  create mode 100644
> libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
> >
> > diff --git a/libstdc++-v3/include/std/atomic
> b/libstdc++-v3/include/std/atomic
> > index 936dd50ba1c..4ac9ccdc1ab 100644
> > --- a/libstdc++-v3/include/std/atomic
> > +++ b/libstdc++-v3/include/std/atomic
> > @@ -228,7 +228,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >atomic& operator=(const atomic&) = delete;
> >atomic& operator=(const atomic&) volatile = delete;
> >
> > -  constexpr atomic(_Tp __i) noexcept : _M_i(__i) { }
> > +#if __cplusplus > 201703L && __has_builtin(__builtin_clear_padding)
> > +  constexpr atomic(_Tp __i) noexcept : _M_i(__i)
> > +  { __builtin_clear_padding(std::__addressof(_M_i)); }
> > +#else
> > +  constexpr atomic(_Tp __i) noexcept : _M_i(__i)
> > +  { }
> > +#endif
>
> Please write this as a single function with the preprocessor
> conditions in the body:
>
>   constexpr atomic(_Tp __i) noexcept : _M_i(__i)
>   {
> #if __cplusplus > 201703L && __has_builtin(__builtin_clear_padding)
> __builtin_clear_padding(std::__addressof(_M_i)); }
> #endif
>   }
>
> This not only avoids duplication of the identical parts, but it avoids
> warnings from ld.gold if you use --detect-odr-violations. Otherwise,
> the linker can see a definition of that constructor on two different
> lines (233 and 236), and so warns about possible ODR violations,
> something like "warning: while linking foo: symbol
> 'std::atomic::atomic(int)' defined in multiple places (possible
> ODR violation): ...atomic:233 ... atomic:236"
>
> Can't we clear the padding for >= 201402L instead of only C++20? Only
> C++11 has a problem with the built-in in a constexpr function, right?
> So we can DTRT for C++14 upwards.
>
>
> >
> >operator _Tp() const noexcept
> >{ return load(); }
> > @@ -268,12 +274,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >void
> >store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
> >{
> > +#if __has_builtin(__builtin_clear_padding)
> > +   __builtin_clear_padding(std::__addressof(__i));
> > +#endif
>
> We repeat this *a lot*. When I started work on this I defined a
> non-member function in the __atomic_impl namespace:
>
> template
>   _GLIBCXX_ALWAYS_INLINE void
>   __clear_padding(_Tp& __val) noexcept
>   {
> #if __has_builtin(__builtin_clear_padding)
>__builtin_clear_padding(std::__addressof(__val));
> #endif
>   }
>
> Then you can just use that everywhere (except the constexpr
> constructor), without all the #if checks.
>
>
>
> > __atomic_store(std::__addressof(_M_i), std::__addressof(__i),
> int(__m));
> >}
> >
> >void
> >store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile
> noexcept
> >{
> > +#if __has_builtin(__builtin_clear_padding)
> > +   __builtin_clear_padding(std::__addressof(__i));
> > +#endif
> > __atomic_store(std::__addressof(_M_i), std::__addressof(__i),
> int(__m));
> >}
> >
> > @@ -300,6 +312,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >{
> >  alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
> > _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
> > +#if __has_builtin(__builtin_clear_padding)
> > +   __builtin_clear_padding(std::__addressof(__i));
> > 

Re: [PATCH] libstdc++: Clear padding bits in atomic compare_exchange

2021-09-29 Thread Thomas Rodgers via Gcc-patches
On Wed, Sep 29, 2021 at 5:14 AM Jonathan Wakely  wrote:

> On Mon, 27 Sept 2021 at 15:11, Thomas Rodgers 
> wrote:
> >
> > From: Thomas Rodgers 
> >
> > Now with checks for __has_builtin(__builtin_clear_padding)
> >
> > This change implements P0528 which requires that padding bits not
> > participate in atomic compare exchange operations. All arguments to the
> > generic template are 'sanitized' by the __builtin_clearpadding intrisic
> > before they are used in comparisons. This alrequires that any stores
> > also sanitize the incoming value.
> >
> > Signed-off-by: Thomas Rodgers 
> >
> > libstdc++=v3/ChangeLog:
> >
> > * include/std/atomic (atomic::atomic(_Tp) clear padding for
> > __cplusplus > 201703L.
> > (atomic::store()) Clear padding.
> > (atomic::exchange()) Likewise.
> > (atomic::compare_exchange_weak()) Likewise.
> > (atomic::compare_exchange_strong()) Likewise.
>
> Don't we also need this for std::atomic_ref, i.e. for the
> __atomic_impl free functions in ?
>
> There we don't have any distinction between atomic_ref
> and atomic_ref, they both use the same
> implementations. But I think that's OK, as I think the built-in is
> smart enough to be a no-op for types with no padding.
>
> > * testsuite/29_atomics/atomic/compare_exchange_padding.cc: New
> > test.
> > ---
> >  libstdc++-v3/include/std/atomic   | 41 +-
> >  .../atomic/compare_exchange_padding.cc| 42 +++
> >  2 files changed, 81 insertions(+), 2 deletions(-)
> >  create mode 100644
> libstdc++-v3/testsuite/29_atomics/atomic/compare_exchange_padding.cc
> >
> > diff --git a/libstdc++-v3/include/std/atomic
> b/libstdc++-v3/include/std/atomic
> > index 936dd50ba1c..4ac9ccdc1ab 100644
> > --- a/libstdc++-v3/include/std/atomic
> > +++ b/libstdc++-v3/include/std/atomic
> > @@ -228,7 +228,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >atomic& operator=(const atomic&) = delete;
> >atomic& operator=(const atomic&) volatile = delete;
> >
> > -  constexpr atomic(_Tp __i) noexcept : _M_i(__i) { }
> > +#if __cplusplus > 201703L && __has_builtin(__builtin_clear_padding)
> > +  constexpr atomic(_Tp __i) noexcept : _M_i(__i)
> > +  { __builtin_clear_padding(std::__addressof(_M_i)); }
> > +#else
> > +  constexpr atomic(_Tp __i) noexcept : _M_i(__i)
> > +  { }
> > +#endif
>
> Please write this as a single function with the preprocessor
> conditions in the body:
>
>   constexpr atomic(_Tp __i) noexcept : _M_i(__i)
>   {
> #if __cplusplus > 201703L && __has_builtin(__builtin_clear_padding)
> __builtin_clear_padding(std::__addressof(_M_i)); }
> #endif
>   }
>
> This not only avoids duplication of the identical parts, but it avoids
> warnings from ld.gold if you use --detect-odr-violations. Otherwise,
> the linker can see a definition of that constructor on two different
> lines (233 and 236), and so warns about possible ODR violations,
> something like "warning: while linking foo: symbol
> 'std::atomic::atomic(int)' defined in multiple places (possible
> ODR violation): ...atomic:233 ... atomic:236"
>
> Can't we clear the padding for >= 201402L instead of only C++20? Only
> C++11 has a problem with the built-in in a constexpr function, right?
> So we can DTRT for C++14 upwards.
>
>
We can, I was being conservative expecting guiding elvish feedback :)


>
> >
> >operator _Tp() const noexcept
> >{ return load(); }
> > @@ -268,12 +274,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >void
> >store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
> >{
> > +#if __has_builtin(__builtin_clear_padding)
> > +   __builtin_clear_padding(std::__addressof(__i));
> > +#endif
>
> We repeat this *a lot*. When I started work on this I defined a
> non-member function in the __atomic_impl namespace:
>
> template
>   _GLIBCXX_ALWAYS_INLINE void
>   __clear_padding(_Tp& __val) noexcept
>   {
> #if __has_builtin(__builtin_clear_padding)
>__builtin_clear_padding(std::__addressof(__val));
> #endif
>   }
>
> Then you can just use that everywhere (except the constexpr
> constructor), without all the #if checks.
>
>
>
> > __atomic_store(std::__addressof(_M_i), std::__addressof(__i),
> int(__m));
> >}
> >
> >void
> >store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile
> noexcept
> >{
> > +#if __has_builtin(__builtin_clear_padding)
> > +   __builtin_clear_padding(std::__addressof(__i));
> > +#endif
> > __atomic_store(std::__addressof(_M_i), std::__addressof(__i),
> int(__m));
> >}
> >
> > @@ -300,6 +312,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >{
> >  alignas(_Tp) unsigned char __buf[sizeof(_Tp)];
> > _Tp* __ptr = reinterpret_cast<_Tp*>(__buf);
> > +#if __has_builtin(__builtin_clear_padding)
> > +   __builtin_clear_padding(std::__addressof(__i));
> > 

Re: [PATCH] libstdc++: Clear padding bits in atomic compare_exchange

2021-09-23 Thread Thomas Rodgers via Gcc-patches
Agreed, I'll revise the patch to do so.

On Thu, Sep 23, 2021 at 12:07 PM Jakub Jelinek  wrote:

> On Thu, Sep 23, 2021 at 11:08:37AM -0700, Thomas Rodgers wrote:
> > From: Thomas Rodgers 
> >
> > This change implements P0528 which requires that padding bits not
> > participate in atomic compare exchange operations. All arguments to the
>
> Thanks for working on this.
>
> > generic template are 'sanitized' by the __builtin_clear_padding intrinsic
> > before they are used in atomic compare_exchange. This alrequires that any
> > stores also sanitize the incoming value.
>
> Not a review, just random nit.
> Shouldn't the __builtin_clear_padding calls be guarded with
> #if __has_builtin(__builtin_clear_padding)
> or #ifdef _GLIBCXX_HAVE_BUILTIN_CLEAR_PADDING defined based on that?
> I think clang doesn't support it (yet?), and it doesn't support the MSVC
> __builtin_zero_non_value_bits (with very similar, but slightly different,
> behavior).
>
> > Signed-off-by: Thomas Rodgers 
> >
> > libstdc++=v3/ChangeLog:
> >
> >   * include/std/atomic (atomic::atomic(_Tp) clear padding for
> >   __cplusplus > 201703L.
> >   (atomic::store()) Clear padding.
> >   (atomic::exchange()) Likewise.
> >   (atomic::compare_exchange_weak()) Likewise.
> >   (atomic::compare_exchange_strong()) Likewise.
> >   * testsuite/29_atomics/atomic/compare_exchange_padding.cc: New
> >   test.
>
> Jakub
>
>


Re: [PATCH] libstdc++: Define macro before it is first checked

2021-09-02 Thread Thomas Rodgers via Gcc-patches
Agreed.

On Thu, Sep 2, 2021 at 10:58 AM Jonathan Wakely  wrote:

> Signed-off-by: Jonathan Wakely 
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/atomic_wait.h (_GLIBCXX_HAVE_PLATFORM_WAIT):
> Define before first attempt to check it.
>
> Tested x86_64-linux and powerpc64-linux, not committed yet.
>
> I think we need this, otherwise __platform_wait_uses_type is false
> for all T.
>
>
>


Re: [PATCH] libstdc++: Fix for deadlock in std::counting_semaphore [PR100806]

2021-06-22 Thread Thomas Rodgers via Gcc-patches
Tested x86_64-pc-linux-gnu.
Committed to master, backported to releases/gcc-11.

On Thu, Jun 17, 2021 at 9:46 AM Jonathan Wakely 
wrote:

> On Wed, 16 Jun 2021 at 20:53, Thomas Rodgers 
> wrote:
> >
> > Same as previous version except removing the copyright notice from the
> > test.
> >
> > libstdc++-v3/ChangeLog:
> > libstdc++/PR100806
> > * include/bits/semaphore_base.h
> (__atomic_semaphore::_M_release():
> > Force _M_release() to wake all waiting threads.
> > * testsuite/30_threads/semaphore/100806.cc: New test.
>
> OK for trunk and 11, thanks.
>
>
> > ---
> >  libstdc++-v3/include/bits/semaphore_base.h|  4 +-
> >  .../testsuite/30_threads/semaphore/100806.cc  | 60 +++
> >  2 files changed, 63 insertions(+), 1 deletion(-)
> >  create mode 100644 libstdc++-v3/testsuite/30_threads/semaphore/100806.cc
> >
> > diff --git a/libstdc++-v3/include/bits/semaphore_base.h
> b/libstdc++-v3/include/bits/semaphore_base.h
> > index 9a55978068f..c4565d7e560 100644
> > --- a/libstdc++-v3/include/bits/semaphore_base.h
> > +++ b/libstdc++-v3/include/bits/semaphore_base.h
> > @@ -256,7 +256,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> >if (__update > 1)
> > __atomic_notify_address_bare(&_M_counter, true);
> >else
> > -   __atomic_notify_address_bare(&_M_counter, false);
> > +   __atomic_notify_address_bare(&_M_counter, true);
> > +// FIXME - Figure out why this does not wake a waiting thread
> > +// __atomic_notify_address_bare(&_M_counter, false);
> >  }
> >
> >private:
> > diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/100806.cc
> b/libstdc++-v3/testsuite/30_threads/semaphore/100806.cc
> > new file mode 100644
> > index 000..938c2793be1
> > --- /dev/null
> > +++ b/libstdc++-v3/testsuite/30_threads/semaphore/100806.cc
> > @@ -0,0 +1,60 @@
> > +// { dg-options "-std=gnu++2a -pthread" }
> > +// { dg-do run { target c++2a } }
> > +// { dg-require-effective-target pthread }
> > +// { dg-require-gthreads "" }
> > +// { dg-add-options libatomic }
> > +
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +std::counting_semaphore<4> semaphore{6};
> > +
> > +std::mutex mtx;
> > +std::vector results;
> > +
> > +void thread_main(size_t x)
> > +{
> > +  semaphore.acquire();
> > +  std::this_thread::sleep_for(std::chrono::milliseconds(100));
> > +  semaphore.release();
> > +  {
> > +std::ostringstream stm;
> > +stm << "Thread " << x << " finished.";
> > +std::lock_guard g{ mtx };
> > +results.push_back(stm.str());
> > +  }
> > +}
> > +
> > +int main()
> > +{
> > +
> > +constexpr auto nthreads = 10;
> > +
> > +std::vector threads(nthreads);
> > +
> > +
> > +size_t counter{0};
> > +for(auto& t : threads)
> > +{
> > +t = std::thread(thread_main, counter++);
> > +}
> > +
> > +for(auto& t : threads)
> > +  {
> > +t.join();
> > +{
> > +  std::lock_guard g{ mtx };
> > +  for (auto&& r : results)
> > +std::cout << r << '\n';
> > +  std::cout.flush();
> > +  results.clear();
> > +}
> > +  }
> > +}
> > --
> > 2.26.2
> >
>
>


Re: [PATCH] libstdc++: Fix Wrong param type in :atomic_ref<_Tp*>::wait [PR100889]

2021-06-09 Thread Thomas Rodgers via Gcc-patches
Pretty sure I know this is, I'll work on a fix today.

On Wed, Jun 9, 2021 at 7:30 AM Christophe Lyon 
wrote:

> Hi,
>
>
> On Wed, 9 Jun 2021 at 01:05, Thomas Rodgers via Gcc-patches
>  wrote:
> >
> > Tested x86_64-pc-linux-gnu, committed to master, backported to
> > releases/gcc-11.
> >
> > On Tue, Jun 8, 2021 at 8:44 AM Jonathan Wakely 
> wrote:
> >
> > > On Tue, 8 Jun 2021 at 01:29, Thomas Rodgers wrote:
> > >
> > >> This time without the repeatred [PR] in the subject line.
> > >>
> > >> Fixes libstdc++/100889
> > >>
> > >
> > > This should be part of the ChangeLog entry instead, preceded by PR so
> it
> > > updates bugzilla, i.e.
> > >
> > >
> > >
> > >> libstdc++-v3/ChangeLog:
> > >>
> > >
> > > PR libstdc++/100889
> > >
> > >
> > >> * include/bits/atomic_base.h (atomic_ref<_Tp*>::wait):
> > >> Change parameter type from _Tp to _Tp*.
> > >> * testsuite/29_atomics/atomic_ref/wait_notify.cc: Extend
> > >> coverage of types tested.
> > >>
> > >
> > >
> > > OK for trunk and gcc-11 with that change, thanks.
> > >
> > >
>
> This is causing a regression on old arm targets:
> --target arm-none-linux-gnueabi
> RUNTESTFLAGS: -march=armv5t
>
> FAIL: 29_atomics/atomic_ref/wait_notify.cc (test for excess errors)
> Excess errors:
> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:
> /ccaaHfBz.o: in function `void
> std::__atomic_impl::store(double*,
> std::remove_volatile::type, std::memory_order)':
>
> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:971:
> undefined reference to `__atomic_store_8'
> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:
> /ccaaHfBz.o: in function `std::remove_volatile::type
> std::__atomic_impl::load(double const*, std::memory_order)':
>
> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:979:
> undefined reference to `__atomic_load_8'
> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:
>
> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:979:
> undefined reference to `__atomic_load_8'
> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:
>
> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:979:
> undefined reference to `__atomic_load_8'
> collect2: error: ld returned 1 exit status
>
> Can you check?
>
> Thanks
>
>


Re: [PATCH] [libstdc++] Remove unused hasher instance.

2021-06-08 Thread Thomas Rodgers via Gcc-patches
Tested x86_64-pc-linux-gnu, committed to master, backported to
releases/gcc-11.

On Fri, Jun 4, 2021 at 1:30 PM Jonathan Wakely  wrote:

>
>
> On Fri, 4 Jun 2021 at 20:54, Thomas Rodgers wrote:
>
>> This is a remnant of poorly executed refactoring.
>>
>
> OK for trunk and gcc-11, thanks.
>
>
>
>> libstdc++-v3/ChangeLog:
>>
>> * include/std/barrier (__tree_barrier::_M_arrive): Remove
>> unnecessary hasher instantiation.
>> ---
>>  libstdc++-v3/include/std/barrier | 1 -
>>  1 file changed, 1 deletion(-)
>>
>> diff --git a/libstdc++-v3/include/std/barrier
>> b/libstdc++-v3/include/std/barrier
>> index fd61fb4f9da..4210e30d1ce 100644
>> --- a/libstdc++-v3/include/std/barrier
>> +++ b/libstdc++-v3/include/std/barrier
>> @@ -103,7 +103,6 @@ It looks different from literature pseudocode for two
>> main reasons:
>>static_cast<__barrier_phase_t>(__old_phase_val
>> + 2);
>>
>> size_t __current_expected = _M_expected;
>> -   std::hash __hasher;
>> __current %= ((_M_expected + 1) >> 1);
>>
>> for (int __round = 0; ; ++__round)
>> --
>> 2.26.2
>>
>>


Re: [PATCH] libstdc++: Fix Wrong param type in :atomic_ref<_Tp*>::wait [PR100889]

2021-06-08 Thread Thomas Rodgers via Gcc-patches
Tested x86_64-pc-linux-gnu, committed to master, backported to
releases/gcc-11.

On Tue, Jun 8, 2021 at 8:44 AM Jonathan Wakely  wrote:

> On Tue, 8 Jun 2021 at 01:29, Thomas Rodgers wrote:
>
>> This time without the repeatred [PR] in the subject line.
>>
>> Fixes libstdc++/100889
>>
>
> This should be part of the ChangeLog entry instead, preceded by PR so it
> updates bugzilla, i.e.
>
>
>
>> libstdc++-v3/ChangeLog:
>>
>
> PR libstdc++/100889
>
>
>> * include/bits/atomic_base.h (atomic_ref<_Tp*>::wait):
>> Change parameter type from _Tp to _Tp*.
>> * testsuite/29_atomics/atomic_ref/wait_notify.cc: Extend
>> coverage of types tested.
>>
>
>
> OK for trunk and gcc-11 with that change, thanks.
>
>
>
>


Re: [PATCH] libstdc++: Fix up parallel_backend_serial.h [PR97549]

2021-02-22 Thread Thomas Rodgers via Gcc-patches



- Original Message -
> Hi!
> 
> In GCC 10, parallel_backend.h just included parallel_backend_{serial,tbb}.h
> and
> did nothing beyond that, and parallel_backend_tbb.h provided directly
> namespace __pstl { namespace __par_backend { ... } }
> and defined everything in there, while parallel_backend_serial.h did:
> namespace __pstl { namespace __serial { ... } } and had this
> namespace __pstl { namespace __par_backend { using namespace
> __pstl::__serial; } }
> at the end.
> In GCC 11, parallel_backend.h does:
> namespace __pstl { namespace __par_backend = __serial_backend; }
> after including parallel_backend_serial.h or
> namespace __pstl { namespace __par_backend = __tbb_backend; }
> after including parallel_backend_tbb.h.  The latter then has:
> namespace __pstl { namespace __tbb_backend { ... } }
> and no using etc. at the end, while parallel_backend_serial.h changed to:
> namespace __pstl { namespace __serial_backend { ... } }
> but has this leftover block from the GCC 10 times.  Even changing that
> using namespace __pstl::__serial;
> to
> using namespace __pstl::__serial_backend;
> doesn't work, as it clashes with
> namespace __pstl { namespace __par_backend = __serial_backend; }
> in parallel_backend.h.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux
> both without and with tbb-devel installed.
> 
> Ok for trunk?

Yes, thanks.

> 
> 2021-02-20  Jakub Jelinek  
> 
>   PR libstdc++-v3/97549
>   * include/pstl/parallel_backend_serial.h: Remove __pstl::__par_backend.
> 
> --- libstdc++-v3/include/pstl/parallel_backend_serial.h.jj2020-10-21
> 19:33:24.059872401 +0200
> +++ libstdc++-v3/include/pstl/parallel_backend_serial.h   2021-02-19
> 11:59:56.414645219 +0100
> @@ -127,12 +127,4 @@ __parallel_invoke(_ExecutionPolicy&&, _F
>  } // namespace __serial_backend
>  } // namespace __pstl
>  
> -namespace __pstl
> -{
> -namespace __par_backend
> -{
> -using namespace __pstl::__serial;
> -}
> -} // namespace __pstl
> -
>  #endif /* _PSTL_PARALLEL_BACKEND_SERIAL_H */
> 
>   Jakub
> 



Re: [PATCH] libstdc++: Add support for C++20 barriers

2021-01-07 Thread Thomas Rodgers via Gcc-patches


Tested x86_64-pc-linux-gnu, committed to master.

Jonathan Wakely writes:

> On 17/12/20 15:37 -0800, Thomas Rodgers wrote:
>>From: Thomas Rodgers 
>>
>>Cleans up a few things mentioned on IRC.
>>
>>Adds 
>>
>>libstdc++/ChangeLog:
>>
>>  * doc/doxygen/user.cfg.in: Add new header.
>>  * include/Makefile.am (std_headers): likewise.
>>  * include/Makefile.in: Regenerate.
>>* include/precompiled/stdc++.h: Add new header.
>>  * include/std/barrier: New file.
>>  * include/std/version: Add __cpp_lib_barrier feature test macro.
>>  * testsuite/30_thread/barrier/1.cc: New test.
>>  * testsuite/30_thread/barrier/2.cc: Likewise.
>>  * testsuite/30_thread/barrier/arrive_and_drop.cc: Likewise.
>>  * testsuite/30_thread/barrier/arrive_and_wait.cc: Likewise.
>>  * testsuite/30_thread/barrier/arrive.cc: Likewise.
>>  * testsuite/30_thread/barrier/completion.cc: Likewise.
>>  * testsuite/30_thread/barrier/max.cc: Likewise.
>
>
>>+#ifndef _GLIBCXX_BARRIER
>>+#define _GLIBCXX_BARRIER 1
>>+
>>+#pragma GCC system_header
>>+
>>+#if __cplusplus > 201703L
>>+#include 
>>+#if __cpp_lib_atomic_wait  && __cpp_aligned_new
>
> There's an extra space here before the && operator.
>
>>+#endif // __cpp_lib_atomic_wait  && __cpp_aligned_new
>
> And here.
>
>>+#endif // __cplusplus > 201703L
>>+#endif // _GLIBCXX_BARRIER
>>+
>>diff --git a/libstdc++-v3/include/std/version 
>>b/libstdc++-v3/include/std/version
>>index e4a8bed52ab..07d17433c5b 100644
>>--- a/libstdc++-v3/include/std/version
>>+++ b/libstdc++-v3/include/std/version
>>@@ -200,6 +200,9 @@
>> #if defined _GLIBCXX_HAS_GTHREADS || defined _GLIBCXX_HAVE_LINUX_FUTEX
>> # define __cpp_lib_atomic_wait 201907L
>> #endif
>>+#if __cpp_lib_atomic_wait
>
> This needs to match the condition used in .
>
>>+#define __cpp_lib_barrier 201907L
>>+#endif
>
> You could just put it inside the previous block where
> __cpp_lib_atomic_wait is defined:
>
> #if defined _GLIBCXX_HAS_GTHREADS || defined _GLIBCXX_HAVE_LINUX_FUTEX
> # define __cpp_lib_atomic_wait 201907L
> # if __cpp_aligned_new
> #  define __cpp_lib_barrier 201907L
> # endif
> #endif
>
>> #define __cpp_lib_bind_front 201907L
>> #if __has_builtin(__builtin_bit_cast)
>> # define __cpp_lib_bit_cast 201806L
>>diff --git a/libstdc++-v3/testsuite/30_threads/barrier/1.cc 
>>b/libstdc++-v3/testsuite/30_threads/barrier/1.cc
>>new file mode 100644
>>index 000..0b38160a58b
>>--- /dev/null
>>+++ b/libstdc++-v3/testsuite/30_threads/barrier/1.cc
>>@@ -0,0 +1,27 @@
>>+// Copyright (C) 2020 Free Software Foundation, Inc.
>>+//
>>+// This file is part of the GNU ISO C++ Library.  This library is free
>>+// software; you can redistribute it and/or modify it under the
>>+// terms of the GNU General Public License as published by the
>>+// Free Software Foundation; either version 3, or (at your option)
>>+// any later version.
>>+
>>+// This library is distributed in the hope that it will be useful,
>>+// but WITHOUT ANY WARRANTY; without even the implied warranty of
>>+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>+// GNU General Public License for more details.
>>+
>>+// You should have received a copy of the GNU General Public License along
>>+// with this library; see the file COPYING3.  If not see
>>+// .
>>+
>>+// { dg-options "-std=gnu++2a" }
>>+// { dg-do compile { target c++2a } }
>
> This test will fail for non-gthreads targets, because they don't
> define the macro. This needs the same condition as the similar
> 29_atomics/atomic/wait_notify/1.cc test:
>
> // { dg-require-effective-target gthreads }
>
> (which is the new way to say { dg-requires-gthread "" })
>
>>+#include 
>>+
>>+#ifndef __cpp_lib_barrier
>>+# error "Feature-test macro for barrier missing in "
>>+#elif __cpp_lib_barrier != 201907L
>>+# error "Feature-test macro for barrier has wrong value in "
>>+#endif
>>diff --git a/libstdc++-v3/testsuite/30_threads/barrier/2.cc 
>>b/libstdc++-v3/testsuite/30_threads/barrier/2.cc
>>new file mode 100644
>>index 000..1d8d83639e0
>>--- /dev/null
>>+++ b/libstdc++-v3/testsuite/30_threads/barrier/2.cc
>>@@ -0,0 +1,27 @@
>>+// Copyright (C) 2019-2020 Free Software Foundation, Inc.
>>+//
>>+// This file is part of the GNU ISO C++ Library.  This library is free
>>+// software; you can redistribute it and/or modify it under the
>>+// terms of the GNU General Public License as published by the
>>+// Free Software Foundation; either version 3, or (at your option)
>>+// any later version.
>>+
>>+// This library is distributed in the hope that it will be useful,
>>+// but WITHOUT ANY WARRANTY; without even the implied warranty of
>>+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>+// GNU General Public License for more details.
>>+
>>+// You should have received a copy of the GNU General Public License along
>>+// with this library; see the file COPYING3.  If not see
>>+// .
>>+
>>+// { 

Re: [PATCH] Add feature test macro for atomic::wait

2020-12-01 Thread Thomas Rodgers via Gcc-patches
Tested x86_64-pc-linux-gnu, committed to trunk.

Jonathan Wakely writes:

> On 30/11/20 10:17 -0800, Thomas Rodgers wrote:
>>From: Thomas Rodgers 
>>
>>Adds __cpp_lib_atomic_wait feature test macro which was overlooked in
>>the initial commit of this feature. Replaces uses of
>>_GLIBCXX_HAVE_ATOMIC_WAIT.
>>
>>libstdc++-v3/ChangeLog:
>>
>>  * include/bits/atomic_base.h: Replace usage of
>>  _GLIBCXX_HAVE_ATOMIC_WAIT with __cpp_lib_atomic_wait.
>>  * include/bits/atomic_timed_wait.h: Likewise.
>>  * include/bits/atomic_wait.h: Define __cpp_lib_atomic_wait
>>  feature test macro.
>>  * include/bits/semaphore_base: Replace usage of
>>  _GLIBCXX_HAVE_ATOMIC_WAIT with __cpp_lib_atomic_wait.
>>  * include/std/atomic: Likewise.
>>  * include/std/latch: Likewise.
>>  * include/std/semaphore: Likewise.
>>  * include/std/version: Define __cpp_lib_atomic wait
>>  feature test macro and replace usage of
>>  _GLIBCXX_HAVE_ATOMIC_WAIT.
>>  * testsuite/29_atomics/atomic/wait_notify/1.cc: New test.
>>  * testsuite/29_atomics/atomic/wait_notify/2.cc: Likewise.
>>
>>---
>> libstdc++-v3/include/bits/atomic_base.h   | 36 +--
>> libstdc++-v3/include/bits/atomic_timed_wait.h |  5 +--
>> libstdc++-v3/include/bits/atomic_wait.h   |  3 +-
>> libstdc++-v3/include/bits/semaphore_base.h|  4 +--
>> libstdc++-v3/include/std/atomic   | 16 -
>> libstdc++-v3/include/std/latch|  4 +--
>> libstdc++-v3/include/std/semaphore|  4 +--
>> libstdc++-v3/include/std/version  |  7 ++--
>> .../29_atomics/atomic/wait_notify/1.cc| 28 +++
>> .../29_atomics/atomic/wait_notify/2.cc| 29 +++
>> 10 files changed, 98 insertions(+), 38 deletions(-)
>> create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/1.cc
>> create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/2.cc
>>
>>diff --git a/libstdc++-v3/include/bits/atomic_base.h 
>>b/libstdc++-v3/include/bits/atomic_base.h
>>index d0d962d3047..ad4e24b4d20 100644
>>--- a/libstdc++-v3/include/bits/atomic_base.h
>>+++ b/libstdc++-v3/include/bits/atomic_base.h
>>@@ -230,7 +230,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>   return __v == __GCC_ATOMIC_TEST_AND_SET_TRUEVAL;
>> }
>>
>>-#ifdef _GLIBCXX_HAVE_ATOMIC_WAIT
>>+#ifdef __cpp_lib_atomic_wait
>
> I've not always been consistent about using #if or #ifdef for
> __cpp_lib macros, but let's not make that worse in a single patch. I
> think we should just use #if for __cpp_lib macros. That affects
> several places in the patch.
>
>> _GLIBCXX_ALWAYS_INLINE void
>> wait(bool __old,
>>  memory_order __m = memory_order_seq_cst) const noexcept
>>@@ -253,7 +253,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>> { std::__atomic_notify(&_M_i, true); }
>>
>> // TODO add const volatile overload
>>-#endif // HAVE_ATOMIC_WAIT
>>+#endif // __cpp_lib_atomic_wait
>> #endif // C++20
>>
>> _GLIBCXX_ALWAYS_INLINE void
>>@@ -604,7 +604,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>> __cmpexch_failure_order(__m));
>>   }
>>
>>-#if __cplusplus > 201703L && defined _GLIBCXX_HAVE_ATOMIC_WAIT
>>+#if __cpp_lib_atomic_wait
>>   _GLIBCXX_ALWAYS_INLINE void
>>   wait(__int_type __old,
>>memory_order __m = memory_order_seq_cst) const noexcept
>>@@ -627,7 +627,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>   { std::__atomic_notify(&_M_i, true); }
>>
>>   // TODO add const volatile overload
>>-#endif // C++20 && HAVE_ATOMIC_WAIT
>>+#endif // __cpp_lib_atomic_wait
>>
>>   _GLIBCXX_ALWAYS_INLINE __int_type
>>   fetch_add(__int_type __i,
>>@@ -898,7 +898,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>> int(__m1), int(__m2));
>>   }
>>
>>-#if __cplusplus > 201703L && defined _GLIBCXX_HAVE_ATOMIC_WAIT
>>+#if __cpp_lib_atomic_wait
>>   _GLIBCXX_ALWAYS_INLINE void
>>   wait(__pointer_type __old,
>> memory_order __m = memory_order_seq_cst) noexcept
>>@@ -921,7 +921,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>   { std::__atomic_notify(&_M_p, true); }
>>
>>   // TODO add const volatile overload
>>-#endif // C++20 && HAVE_ATOMIC_WAIT
>>+#endif // __cpp_lib_atomic_wait
>>
>>   _GLIBCXX_ALWAYS_INLINE __pointer_type
>>   fetch_add(ptrdiff_t __d,
>>@@ -1011,7 +1011,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>   int(__success), int(__failure));
>>   }
>>
>>-#if __cplusplus > 201703L && defined _GLIBCXX_HAVE_ATOMIC_WAIT
>>+#if __cpp_lib_atomic_wait
>> template
>>   _GLIBCXX_ALWAYS_INLINE void
>>   wait(const _Tp* __ptr, _Val<_Tp> __old,
>>@@ -1036,7 +1036,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>   { std::__atomic_notify(__ptr, true); }
>>
>>   // TODO add const volatile overload
>>-#endif // C++20 && HAVE_ATOMIC_WAIT
>>+#endif // __cpp_lib_atomic_wait
>>
>> template
>>   _GLIBCXX_ALWAYS_INLINE 

Re: [PATCH] libstdc++: Add c++2a

2020-11-02 Thread Thomas Rodgers via Gcc-patches


Testsed x86_64-pc-linux-gnu, committed to master.

Jonathan Wakely writes:

> On 02/11/20 08:10 -0800, Thomas Rodgers wrote:
>>From: Thomas Rodgers 
>>
>>IGNORE the previous patch.
>>
>>Changes implementation to use a private __mutex type as discussed on
>>IRC.
>>
>>libstdc++/ChangeLog:
>>  libstdc++-v3/doc/doxygen/user.cfg.in (INPUT): Add new header.
>>  libstdc++-v3/include/Makefile.am (std_headers): Add new header.
>>  libstdc++-v3/include/Makefile.in: Regenerate.
>>  libstdc++-v3/include/precompiled/stdc++.h: Include new header.
>>  (basic_streambuf): Befriend __detail::__streambuf_core_access.
>>  libstdc++-v3/include/std/syncstream: New header.
>>  libstdc++-v3/include/std/version: Add __cpp_lib_syncbuf:
>>  libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc: New test.
>>  libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc: Likewise.
>>  libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc:
>>  Likewise.
>>  libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc:
>>  Likewise.
>>  libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc:
>>  Likewise.
>>  libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc: Likewise.
>>  libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc: Likewise.
>>  libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc:
>>  Likewise.
>>  libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc:
>>  Likewise.
>>---
>> libstdc++-v3/doc/doxygen/user.cfg.in  |   1 +
>> libstdc++-v3/include/Makefile.am  |   1 +
>> libstdc++-v3/include/Makefile.in  |   1 +
>> libstdc++-v3/include/precompiled/stdc++.h |   2 +-
>> libstdc++-v3/include/std/syncstream   | 333 ++
>> libstdc++-v3/include/std/version  |   4 +
>> .../testsuite/27_io/basic_syncbuf/1.cc|  28 ++
>> .../testsuite/27_io/basic_syncbuf/2.cc|  28 ++
>> .../27_io/basic_syncbuf/basic_ops/1.cc| 137 +++
>> .../27_io/basic_syncbuf/requirements/types.cc |  42 +++
>> .../27_io/basic_syncbuf/sync_ops/1.cc | 130 +++
>> .../testsuite/27_io/basic_syncstream/1.cc |  28 ++
>> .../testsuite/27_io/basic_syncstream/2.cc |  28 ++
>> .../27_io/basic_syncstream/basic_ops/1.cc | 134 +++
>> .../basic_syncstream/requirements/types.cc|  43 +++
>> 15 files changed, 939 insertions(+), 1 deletion(-)
>> create mode 100644 libstdc++-v3/include/std/syncstream
>> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/1.cc
>> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/2.cc
>> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/basic_ops/1.cc
>> create mode 100644 
>> libstdc++-v3/testsuite/27_io/basic_syncbuf/requirements/types.cc
>> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncbuf/sync_ops/1.cc
>> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/1.cc
>> create mode 100644 libstdc++-v3/testsuite/27_io/basic_syncstream/2.cc
>> create mode 100644 
>> libstdc++-v3/testsuite/27_io/basic_syncstream/basic_ops/1.cc
>> create mode 100644 
>> libstdc++-v3/testsuite/27_io/basic_syncstream/requirements/types.cc
>>
>>diff --git a/libstdc++-v3/doc/doxygen/user.cfg.in 
>>b/libstdc++-v3/doc/doxygen/user.cfg.in
>>index 9b49a15d31b..320f6dea688 100644
>>--- a/libstdc++-v3/doc/doxygen/user.cfg.in
>>+++ b/libstdc++-v3/doc/doxygen/user.cfg.in
>>@@ -897,6 +897,7 @@ INPUT  = 
>>@srcdir@/doc/doxygen/doxygroups.cc \
>>  include/streambuf \
>>  include/string \
>>  include/string_view \
>>+ include/syncstream \
>>  include/system_error \
>>  include/thread \
>>  include/tuple \
>>diff --git a/libstdc++-v3/include/Makefile.am 
>>b/libstdc++-v3/include/Makefile.am
>>index c90ac555e15..8652b921274 100644
>>--- a/libstdc++-v3/include/Makefile.am
>>+++ b/libstdc++-v3/include/Makefile.am
>>@@ -73,6 +73,7 @@ std_headers = \
>>  ${std_srcdir}/shared_mutex \
>>  ${std_srcdir}/span \
>>  ${std_srcdir}/sstream \
>>+ ${std_srcdir}/syncstream \
>>  ${std_srcdir}/stack \
>>  ${std_srcdir}/stdexcept \
>>  ${std_srcdir}/stop_token \
>>diff --git a/libstdc++-v3/include/precompiled/stdc++.h 
>>b/libstdc++-v3/include/precompiled/stdc++.h
>>index 7518a98c25a..8899c323a28 100644
>>--- a/libstdc++-v3/include/precompiled/stdc++.h
>>+++ b/libstdc++-v3/include/precompiled/stdc++.h
>>@@ -141,6 +141,6 @@
>> #include 
>> #include 
>> #include 
>>-// #include 
>>+#include 
>> #include 
>> #endif
>>diff --git a/libstdc++-v3/include/std/syncstream 
>>b/libstdc++-v3/include/std/syncstream
>>new file mode 100644
>>index 000..ff96ca6cf59
>>--- /dev/null
>>+++ b/libstdc++-v3/include/std/syncstream
>>@@ -0,0 +1,333 @@
>>+//  -*- C++ -*-
>>+
>>+// Copyright (C) 2020 Free Software Foundation, Inc.
>>+//

Re: [PATCH] libstdc++: Implement C++20 features for

2020-10-09 Thread Thomas Rodgers via Gcc-patches


Jonathan Wakely writes:

> On 07/10/20 18:15 -0700, Thomas Rodgers wrote:
>>@@ -500,6 +576,40 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
>>   }
>> #endif
>>
>>+#if __cplusplus > 201703L && _GLIBCXX_USE_CXX11_ABI
>>+  basic_istringstream(ios_base::openmode __mode, const allocator_type& 
>>__a)
>>+  : __istream_type(), _M_stringbuf(__mode | ios_base::in, __a)
>>+  { this->init(&_M_stringbuf); }
>
> All these & operators need to be std::__addressof(_M_stringbuf)
> instead. _M_stringbuf potentially depends on program-defined types
> (the traits and allocator classes) which means user namespaces are
> considered for ADL and they could define a operator& that gets used.
>
>
>>+
>>+  explicit basic_istringstream(__string_type&& __str,
>>+ios_base::openmode __mode = ios_base::in )
>>+  : __istream_type(), _M_stringbuf(std::move(__str), __mode | 
>>ios_base::in)
>>+  { this->init(&_M_stringbuf); }
>>+
>>+  template
>>+ basic_istringstream(const basic_string<_CharT, _Traits, _SAlloc>& __str,
>>+ const allocator_type& __a)
>>+ : basic_istringstream(__str, ios_base::in, __a)
>>+ { }
>>+
>>+  using __sv_type = basic_string_view;
>
> This typedef seems to only be used once. Might as well just use
> basic_string_view directly in the return type
> of view().
>
> Similarly in basic_ostringstream and basic_stringstream.
>
>>diff --git a/libstdc++-v3/src/c++20/Makefile.in 
>>b/libstdc++-v3/src/c++20/Makefile.in
>>new file mode 100644
>>index 000..0e2de19ae59
>>diff --git a/libstdc++-v3/src/c++20/sstream-inst.cc 
>>b/libstdc++-v3/src/c++20/sstream-inst.cc
>>new file mode 100644
>>index 000..c419176ae8e
>>--- /dev/null
>>+++ b/libstdc++-v3/src/c++20/sstream-inst.cc
>>@@ -0,0 +1,111 @@
>>+// Explicit instantiation file.
>>+
>>+// Copyright (C) 1997-2020 Free Software Foundation, Inc.
>
> Just 2020 here.
>
>>+//
>>+// This file is part of the GNU ISO C++ Library.  This library is free
>>+// software; you can redistribute it and/or modify it under the
>>+// terms of the GNU General Public License as published by the
>>+// Free Software Foundation; either version 3, or (at your option)
>>+// any later version.
>>+
>>+// This library is distributed in the hope that it will be useful,
>>+// but WITHOUT ANY WARRANTY; without even the implied warranty of
>>+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>>+// GNU General Public License for more details.
>>+
>>+// Under Section 7 of GPL version 3, you are granted additional
>>+// permissions described in the GCC Runtime Library Exception, version
>>+// 3.1, as published by the Free Software Foundation.
>>+
>>+// You should have received a copy of the GNU General Public License and
>>+// a copy of the GCC Runtime Library Exception along with this program;
>>+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>>+// .
>>+
>>+//
>>+// ISO C++ 14882:
>>+//
>>+
>>+#ifndef _GLIBCXX_USE_CXX11_ABI
>>+// Instantiations in this file use the new SSO std::string ABI unless 
>>included
>>+// by another file which defines _GLIBCXX_USE_CXX11_ABI=0.
>
> This copy comment is misleading now if we're not actually going
> to include it from another file to generate the old ABI symbols.
>
> I think just define it unconditionally and add a comment saying that
> these new symbols are only defines for the SSO string ABI.
>
>>+# define _GLIBCXX_USE_CXX11_ABI 1
>>+#endif
>>+#include 
>>+
>>+namespace std _GLIBCXX_VISIBILITY(default)
>>+{
>>+_GLIBCXX_BEGIN_NAMESPACE_VERSION
>>+
>>+template basic_stringbuf::basic_stringbuf(const allocator_type&);
>>+template basic_stringbuf::basic_stringbuf(ios_base::openmode,
>>+  const allocator_type&);
>>+template basic_stringbuf::basic_stringbuf(__string_type&&,
>>+  ios_base::openmode);
>>+template basic_stringbuf::basic_stringbuf(basic_stringbuf&&,
>>+  const allocator_type&);
>>+template basic_stringbuf::allocator_type
>>+basic_stringbuf::get_allocator() const noexcept;
>>+template basic_stringbuf::__sv_type
>
> Looks like this would be a bit simpler if it just used string_view
> here, not basic_stringbuf::__sv_type, and wstring_view below
> for the wchar_t specializations.
>
> And you could use allocator instead of
> basic_stringbuf::allocator_type.
>
> That looks a little cleaner to me, but it's a matter of opinion.
>
> That would be necessary anyway for the basic_*stringstream types if
> they don't have the __sv_type any more.
>
>
>>diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc 
>>b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc
>>new file mode 100644
>>index 000..d93141fc232
>>--- /dev/null
>>+++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc
>>@@ -0,0 +1,85 @@
>>+// Copyright (C) 2020 

Re: [PATCH] libstdc++: Add C++2a synchronization support

2020-09-28 Thread Thomas Rodgers via Gcc-patches


Jonathan Wakely writes:

> On 11/09/20 16:58 -0700, Thomas Rodgers wrote:
>>From: Thomas Rodgers 
>>
>>This patch supercedes both the Add C++2a synchronization support patch
>>being replied to *and* the patch adding wait/notify_* to atomic_flag.
>>
>>Add support for -
>>  * atomic_flag::wait/notify_one/notify_all
>>  * atomic::wait/notify_one/notify_all
>>  * counting_semaphore
>>  * binary_semaphore
>>  * latch
>>
>>libstdc++-v3/ChangeLog:
>>
>>  * include/Makefile.am (bits_headers): Add new header.
>>  * include/Makefile.in: Regenerate.
>>  * include/bits/atomic_base.h (__atomic_flag::wait): Define.
>>  (__atomic_flag::notify_one): Likewise.
>>  (__atomic_flag::notify_all): Likewise.
>>  (__atomic_base<_Itp>::wait): Likewise.
>>  (__atomic_base<_Itp>::notify_one): Likewise.
>>  (__atomic_base<_Itp>::notify_all): Likewise.
>>  (__atomic_base<_Ptp*>::wait): Likewise.
>>  (__atomic_base<_Ptp*>::notify_one): Likewise.
>>  (__atomic_base<_Ptp*>::notify_all): Likewise.
>>  (__atomic_impl::wait): Likewise.
>>  (__atomic_impl::notify_one): Likewise.
>>  (__atomic_impl::notify_all): Likewise.
>>  (__atomic_float<_Fp>::wait): Likewise.
>>  (__atomic_float<_Fp>::notify_one): Likewise.
>>  (__atomic_float<_Fp>::notify_all): Likewise.
>>  (__atomic_ref<_Tp>::wait): Likewise.
>>  (__atomic_ref<_Tp>::notify_one): Likewise.
>>  (__atomic_ref<_Tp>::notify_all): Likewise.
>>  (atomic_wait<_Tp>): Likewise.
>>  (atomic_wait_explicit<_Tp>): Likewise.
>>  (atomic_notify_one<_Tp>): Likewise.
>>  (atomic_notify_all<_Tp>): Likewise.
>>  * include/bits/atomic_wait.h: New file.
>>  * include/bits/atomic_timed_wait.h: New file.
>>  * include/bits/semaphore_base.h: New file.
>>  * include/std/atomic (atomic::wait): Define.
>>  (atomic::wait_one): Likewise.
>>  (atomic::wait_all): Likewise.
>>  (atomic<_Tp>::wait): Likewise.
>>  (atomic<_Tp>::wait_one): Likewise.
>>  (atomic<_Tp>::wait_all): Likewise.
>>  (atomic<_Tp*>::wait): Likewise.
>>  (atomic<_Tp*>::wait_one): Likewise.
>>  (atomic<_Tp*>::wait_all): Likewise.
>>  * include/std/latch: New file.
>>  * include/std/semaphore: New file.
>>  * include/std/version: Add __cpp_lib_semaphore and
>>  __cpp_lib_latch defines.
>>  * testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
>>  * testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
>>  * testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
>>  * testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
>>  * testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
>>  * testsuite/29_atomic/atomic/wait_notify/generic.cc: Liekwise.
>>  * testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
>>  * testsuite/29_atomics/atomic_flag/wait_notify/1.cc: New test.
>>  * testsuite/30_thread/semaphore/1.cc: New test.
>>  * testsuite/30_thread/semaphore/2.cc: Likewise.
>>  * testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
>>  * testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
>>  * testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
>>  * testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
>>  * testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
>>  * testsuite/30_thread/latch/1.cc: New test.
>>  * testsuite/30_thread/latch/2.cc: New test.
>>  * testsuite/30_thread/latch/3.cc: New test.
>>---
>> libstdc++-v3/include/Makefile.am  |   5 +
>> libstdc++-v3/include/Makefile.in  |   5 +
>> libstdc++-v3/include/bits/atomic_base.h   | 195 +++-
>> libstdc++-v3/include/bits/atomic_timed_wait.h | 281 
>> libstdc++-v3/include/bits/atomic_wait.h   | 301 ++
>> libstdc++-v3/include/bits/semaphore_base.h| 283 
>> libstdc++-v3/include/std/atomic   |  73 +
>> libstdc++-v3/include/std/latch|  90 ++
>> libstdc++-v3/include/std/semaphore|  92 ++
>> libstdc++-v3/include/std/version  |   2 +
>> .../atomic/wait_notify/atomic_refs.cc | 103 ++
>> .../29_atomics/atomic/wait_notify/bool.cc |  59 
>> .../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
>> .../29_atomics/atomic/wait_notify/generic.cc  |  31 ++
>> .../29_atomics/atomic/wait_notify/generic.h   | 160 ++
>> .../atomic/wait_notify/integrals.cc   |  65 
>> .../29_atomics/atomic/wait_notify/pointers.cc |  59 
>> .../29_atomics/atomic_flag/wait_notify/1.cc   |  61 
>> libstdc++-v3/testsuite/30_threads/latch/1.cc  |  27 ++
>> libstdc++-v3/testsuite/30_threads/latch/2.cc  |  27 ++
>> libstdc++-v3/testsuite/30_threads/latch/3.cc  |  50 +++
>> .../testsuite/30_threads/semaphore/1.cc   |  27 ++
>> .../testsuite/30_threads/semaphore/2.cc   |  27 ++
>> .../semaphore/least_max_value_neg.cc  

Re: [PATCH] libstdc++: Rebase include/pstl to current upstream

2020-09-21 Thread Thomas Rodgers via Gcc-patches


Thanks, I'll apply locally (and sync those changes to the patch I'm
preparing for upstream).

Jonathan Wakely writes:

> On 21/09/20 08:19 -0700, Thomas Rodgers wrote:
>>
>>
>>> On Sep 21, 2020, at 7:40 AM, Jonathan Wakely  wrote:
>>>
>>> On 15/09/20 20:35 -0700, Thomas Rodgers wrote:
 From: Thomas Rodgers 

 From llvm-project/pstl @ 0b2e0e80d96

 libstdc++-v3/ChangeLog:

* include/pstl/algorithm_impl.h: Update file.
* include/pstl/execution_impl.h: Likewise.
* include/pstl/glue_algorithm_impl.h: Likewise.
* include/pstl/glue_memory_impl.h: Likewise.
* include/pstl/glue_numeric_impl.h: Likewise.
* include/pstl/memory_impl.h: Likewise.
* include/pstl/numeric_impl.h: Likewise.
* include/pstl/parallel_backend.h: Likewise.
* include/pstl/parallel_backend_serial.h: Likewise.
* include/pstl/parallel_backend_tbb.h: Likewise.
* include/pstl/parallel_backend_utils.h: Likewise.
* include/pstl/pstl_config.h: Likewise.
* include/pstl/unseq_backend_simd.h: Likewise.
 ---
 libstdc++-v3/include/pstl/algorithm_impl.h| 181 ++--
 libstdc++-v3/include/pstl/execution_impl.h|   4 +-
 .../include/pstl/glue_algorithm_impl.h| 543 +--
 libstdc++-v3/include/pstl/glue_memory_impl.h  | 264 ++---
 libstdc++-v3/include/pstl/glue_numeric_impl.h |  68 +-
 libstdc++-v3/include/pstl/memory_impl.h   |  67 +-
 libstdc++-v3/include/pstl/numeric_impl.h  |   8 +-
 libstdc++-v3/include/pstl/parallel_backend.h  |   8 +
 .../include/pstl/parallel_backend_serial.h|   8 +-
 .../include/pstl/parallel_backend_tbb.h   | 903 +++---
 .../include/pstl/parallel_backend_utils.h | 248 +++--
 libstdc++-v3/include/pstl/pstl_config.h   |  24 +-
 .../include/pstl/unseq_backend_simd.h |  39 +-
 13 files changed, 1586 insertions(+), 779 deletions(-)

 diff --git a/libstdc++-v3/include/pstl/glue_algorithm_impl.h 
 b/libstdc++-v3/include/pstl/glue_algorithm_impl.h
 index 379de4033ec..d2e30529f78 100644
 --- a/libstdc++-v3/include/pstl/glue_algorithm_impl.h
 +++ b/libstdc++-v3/include/pstl/glue_algorithm_impl.h
 @@ -757,8 +743,7 @@ 
 __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, 
 _ForwardIterator1 __last1, _ForwardIterator2 __first2,
  _ForwardIterator2 __last2)
 {
 -return std::equal(std::forward<_ExecutionPolicy>(__exec), __first1, 
 __last1, __first2, __last2,
 -  __pstl::__internal::__pstl_equal());
 +return equal(std::forward<_ExecutionPolicy>(__exec), __first1, 
 __last1, __first2, __last2, std::equal_to<>());
>>>
>>> Any idea why this is now called unqualified? I don't think we want ADL
>>> here.
>>>
>>I’m sure it is related to ...
>>>
 diff --git a/libstdc++-v3/include/pstl/parallel_backend_tbb.h 
 b/libstdc++-v3/include/pstl/parallel_backend_tbb.h
 index 9c05ade0532..4476486d548 100644
 --- a/libstdc++-v3/include/pstl/parallel_backend_tbb.h
 +++ b/libstdc++-v3/include/pstl/parallel_backend_tbb.h
>>>
>>> This file is full of non-reserved names, like _root and _x_orig and
>>> move_y_range.
>>>
>>
>>The upstream authors not being sufficiently versed in thinking in terms of 
>>writing things up front to avoid the sort of issues that a stdlib requires of 
>>the code.
>>
>>> Fixing those upstream might take a while though.
>>
>>I have already started accumulating a set of patches for upstream which I’ll 
>>manage as independently of getting this rebase into gcc.
>
> Here's a patch to fix
> https://bugs.llvm.org/show_bug.cgi?id=47601
> and
> https://bugs.llvm.org/show_bug.cgi?id=47601
> by essentially rewriting the entire file!



[PATCH] libstdc++: only pull in bits/align.h if C++11 or later

2020-09-11 Thread Thomas Rodgers via Gcc-patches
libstdc++-v3/ChangeLog:

* include/std/memory: Move #include  inside C++11
conditional includes.

Tested x86_64-pc-linux-gnu, committed to master.

---
 libstdc++-v3/include/std/memory | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/memory b/libstdc++-v3/include/std/memory
index a56952fb114..aee7b050bd7 100644
--- a/libstdc++-v3/include/std/memory
+++ b/libstdc++-v3/include/std/memory
@@ -61,7 +61,6 @@
  */
 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -75,6 +74,7 @@
 #  include   // std::basic_ostream
 #  include 
 #  include 
+#  include 
 #  include 
 #  include   // std::less
 #  include 
-- 
2.26.2



Re: [PATCH] Add C++2a synchronization support

2020-05-11 Thread Thomas Rodgers via Gcc-patches
I *think* I have addressed everything in the attached patch.
commit 24a989d2bf2158bdbe2511310d0583d0c6226f71
Author: Thomas Rodgers 
Date:   Mon Apr 6 17:58:47 2020 -0700

Add C++2a synchronization support

Add support for -
atomic wait/notify_one/notify_all
counting_semaphore
binary_semaphore
latch

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_base<_Itp>::wait): Define.
(__atomic_base<_Itp>::notify_one): Likewise.
(__atomic_base<_Itp>::notify_all): Likewise.
(__atomic_base<_Ptp*>::wait): Likewise.
(__atomic_base<_Ptp*>::notify_one): Likewise.
(__atomic_base<_Ptp*>::notify_all): Likewise.
(__atomic_impl::wait): Likewise.
(__atomic_impl::notify_one): Likewise.
(__atomic_impl::notify_all): Likewise.
(__atomic_float<_Fp>::wait): Likewise.
(__atomic_float<_Fp>::notify_one): Likewise.
(__atomic_float<_Fp>::notify_all): Likewise.
(__atomic_ref<_Tp>::wait): Likewise.
(__atomic_ref<_Tp>::notify_one): Likewise.
(__atomic_ref<_Tp>::notify_all): Likewise.
(atomic_wait<_Tp>): Likewise.
(atomic_wait_explicit<_Tp>): Likewise.
(atomic_notify_one<_Tp>): Likewise.
(atomic_notify_all<_Tp>): Likewise.
* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
* include/std/atomic (atomic::wait): Define.
(atomic::wait_one): Likewise.
(atomic::wait_all): Likewise.
(atomic<_Tp>::wait): Likewise.
(atomic<_Tp>::wait_one): Likewise.
(atomic<_Tp>::wait_all): Likewise.
(atomic<_Tp*>::wait): Likewise.
(atomic<_Tp*>::wait_one): Likewise.
(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
* testsuite/30_thread/semaphore/1.cc: New test.
* testsuite/30_thread/semaphore/2.cc: Likewise.
* testsuite/30_thread/semaphore/least_max_value_neg.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_futex.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
* testsuite/30_thread/latch/1.cc: New test.
* testsuite/30_thread/latch/2.cc: New test.
* testsuite/30_thread/latch/3.cc: New test.

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 80aeb3f8959..b3ac1a3365f 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -52,6 +52,7 @@ std_headers = \
 	${std_srcdir}/iostream \
 	${std_srcdir}/istream \
 	${std_srcdir}/iterator \
+	${std_srcdir}/latch\
 	${std_srcdir}/limits \
 	${std_srcdir}/list \
 	${std_srcdir}/locale \
@@ -69,6 +70,7 @@ std_headers = \
 	${std_srcdir}/ratio \
 	${std_srcdir}/regex \
 	${std_srcdir}/scoped_allocator \
+	${std_srcdir}/semaphore \
 	${std_srcdir}/set \
 	${std_srcdir}/shared_mutex \
 	${std_srcdir}/span \
@@ -100,6 +102,8 @@ bits_headers = \
 	${bits_srcdir}/allocated_ptr.h \
 	${bits_srcdir}/allocator.h \
 	${bits_srcdir}/atomic_base.h \
+	${bits_srcdir}/atomic_wait.h \
+	${bits_srcdir}/atomic_timed_wait.h \
 	${bits_srcdir}/atomic_futex.h \
 	${bits_srcdir}/basic_ios.h \
 	${bits_srcdir}/basic_ios.tcc \
@@ -174,6 +178,7 @@ bits_headers = \
 	${bits_srcdir}/regex_compiler.tcc \
 	${bits_srcdir}/regex_executor.h \
 	${bits_srcdir}/regex_executor.tcc \
+	${bits_srcdir}/semaphore_base.h \
 	${bits_srcdir}/shared_ptr.h \
 	${bits_srcdir}/shared_ptr_atomic.h \
 	${bits_srcdir}/shared_ptr_base.h \
diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 87fe0bd6000..73a8a77271e 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -37,6 +37,10 @@
 #include 
 #include 
 
+#if __cplusplus > 201703L
+#include 

Re: [PATCH] Add C++2a synchronization support

2020-05-11 Thread Thomas Rodgers via Gcc-patches


Jonathan Wakely writes:

> On 09/05/20 17:01 -0700, Thomas Rodgers via Libstdc++ wrote:



>>+#include 
>
>  shouldn't be here (it adds runtime cost, as well as
> compile-time).
>
Oversight, not removed after debugging it.



>
> Can't this just be __old instead of *std::__addressof(__old) ?
>
Copypasta from elsewhere in the same class, I believe. I'll change it.



>
> Isn't alignas(64) already implied by the first data member?
>

Yes

>>+{
>>+  int32_t alignas(64) _M_ver = 0;
>>+  int32_t alignas(64) _M_wait = 0;
>>+
>>+  // TODO make this used only where we don't have futexes
>
> Don't we always need these even with futexes, for the types that don't
> use a futex?
>

If we have futexes, we can use the address of _M_ver to wake
_M_do_wait() instead of using a condvar for types that don't use a
futex directly.

>>+  using __lock_t = std::unique_lock;
>+  mutable __lock_t::mutex_type _M_mtx;
>>+
>>+#ifdef __GTHREAD_COND_INIT
>>+  mutable __gthread_cond_t _M_cv = __GTHREAD_COND_INIT;
>>+  __waiters() noexcept = default;
>
> If we moved std::condition_variable into its own header (or
> , could we reuse that here instead of using
> __gthread_cond_t directly?
>
Yes, I started down that route initially, I could revisit it in a future
patch as part of also making it's use only necessary when the platform
doesn't support futex.

>>+__atomic_notify(const _Tp* __addr, bool __all) noexcept
>>+{
>>+  using namespace __detail;
>>+  auto& __w = __waiters::_S_for((void*)__addr);
>>+  if (!__w._M_waiting())
>
> When __platform_wait_uses_type<_Tp> is true, will __w._M_waiting()
> ever be true? Won't this always return before notifying?
>
> Is there meant to be a __waiter constructed here?
>

__waiter (an RAII type) is constructed in the __atomic_wait(), that
increments the _M_wait count on the way into the wait, and decrements it
on the way out, __atomic_notify checks to see if that count is non-zero
before invoking the platform/semaphore notify because it is cheaper
to do the atomic load than it is to make the syscall() when there are no
waiters.

>>+ return;
>>+
>>+  if constexpr (__platform_wait_uses_type<_Tp>::__value)
>>+ {
>>+   __platform_notify((__platform_wait_t*)(void*) __addr, __all);
>>+ }



>>+struct __platform_semaphore
>>+{
>>+  using __clock_t = chrono::system_clock;
>>+
>>+  __platform_semaphore(ptrdiff_t __count) noexcept
>
> Should this constructor be explicit?
>

Yes.

>>+  template
>>+ _GLIBCXX_ALWAYS_INLINE bool
>
> Do we really need this to be always_inline?
>
Probably not, copypasta from elsewhere in the same file.

>>+ __try_acquire_until_impl(const chrono::time_point<__clock_t>& __atime) 
>>noexcept
>>+ {
>>+   auto __s = chrono::time_point_cast(__atime);
>>+   auto __ns = chrono::duration_cast(__atime - __s);



>>+template
>>+  struct __atomic_semaphore
>>+  {
>>+ static constexpr size_t _S_alignment = __alignof__(_Tp);
>>+
>>+ __atomic_semaphore(_Tp __count)
>
> Should this be explicit?
>
Yes.

>>+private:
>>+  alignas(_S_alignment) _Tp _M_a;
>
> Could this just use alignas(__alignof__(_Tp)) _Tp here? There's no
> need for the _S_alignment constant if it's only used in one place.
>
Yes.

>>+};
>>+
>>+#ifdef _GLIBCXX_REQUIRE_POSIX_SEMAPHORE
>>+  template
>
> Rename __least_max_t here too.
>
>>+using __semaphore_base = __platform_semaphore<__least_max_t>;
>>+#else
>>+#  ifdef _GLIBCXX_HAVE_LINUX_FUTEX
>>+  template
>>+using __semaphore_base = std::conditional<(__least_max_t > 0
>
> This should use conditional_t<> not conditional<>::type.
>
> The least-max_value can't be negative. If it's zero, can't we use a
> futex or semaphore? So the '__least_max_t > 0' condition is wrong?
>

Yes.

>>+   && __least_max_t < 
>>std::numeric_limits<__detail::__platform_wait_t>::max()),
>
> Should that be <= rather than < ?
>

Likely.

>>+   
>>__atomic_semaphore<__detail::__platform_wait_t>,
>>+   
>>__atomic_semaphore>::type;
>>+ // __platform_semaphore
>>+#  else





[PATCH] Add C++2a synchronization support

2020-05-09 Thread Thomas Rodgers via Gcc-patches
* Note, this patch supersedes my previous atomic wait and semaphore
patches.

Add support for -
atomic wait/notify_one/notify_all
counting_semaphore
binary_semaphore
latch

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_base<_Itp>:wait): Define.
(__atomic_base<_Itp>::notify_one): Likewise.
(__atomic_base<_Itp>::notify_all): Likewise.
(__atomic_base<_Ptp*>::wait): Likewise.
(__atomic_base<_Ptp*>::notify_one): Likewise.
(__atomic_base<_Ptp*>::notify_all): Likewise.
(__atomic_impl::wait): Likewise.
(__atomic_impl::notify_one): Likewise.
(__atomic_impl::notify_all): Likewise.
(__atomic_float<_Fp>::wait): Likewise.
(__atomic_float<_Fp>::notify_one): Likewise.
(__atomic_float<_Fp>::notify_all): Likewise.
(__atomic_ref<_Tp>::wait): Likewise.
(__atomic_ref<_Tp>::notify_one): Likewise.
(__atomic_ref<_Tp>::notify_all): Likewise.
(atomic_wait<_Tp>): Likewise.
(atomic_wait_explicit<_Tp>): Likewise.
(atomic_notify_one<_Tp>): Likewise.
(atomic_notify_all<_Tp>): Likewise.
* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
* include/std/atomic (atomic::wait): Define.
(atomic::wait_one): Likewise.
(atomic::wait_all): Likewise.
(atomic<_Tp>::wait): Likewise.
(atomic<_Tp>::wait_one): Likewise.
(atomic<_Tp>::wait_all): Likewise.
(atomic<_Tp*>::wait): Likewise.
(atomic<_Tp*>::wait_one): Likewise.
(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
* testsuite/30_thread/semaphore/1.cc: New test.
* testsuite/30_thread/semaphore/2.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_for.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_futex.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_posix.cc: Likewise.
* testsuite/30_thread/semaphore/try_acquire_until.cc: Likewise.
* testsuite/30_thread/latch/1.cc: New test.
* testsuite/30_thread/latch/2.cc: New test.
* testsuite/30_thread/latch/3.cc: New test

>From 436ab6fd5286a6467792263fbfbd603ba0f0c04d Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Mon, 6 Apr 2020 17:58:47 -0700
Subject: [PATCH] Add C++2a synchronization support

Add support for -
atomic wait/notify_one/notify_all
counting_semaphore
binary_semaphore
latch

* include/Makefile.am (bits_headers): Add new header.
	* include/Makefile.in: Regenerate.
	* include/bits/atomic_base.h (__atomic_base<_Itp>:wait): Define.
	(__atomic_base<_Itp>::notify_one): Likewise.
	(__atomic_base<_Itp>::notify_all): Likewise.
	(__atomic_base<_Ptp*>::wait): Likewise.
	(__atomic_base<_Ptp*>::notify_one): Likewise.
	(__atomic_base<_Ptp*>::notify_all): Likewise.
	(__atomic_impl::wait): Likewise.
	(__atomic_impl::notify_one): Likewise.
	(__atomic_impl::notify_all): Likewise.
	(__atomic_float<_Fp>::wait): Likewise.
	(__atomic_float<_Fp>::notify_one): Likewise.
	(__atomic_float<_Fp>::notify_all): Likewise.
	(__atomic_ref<_Tp>::wait): Likewise.
	(__atomic_ref<_Tp>::notify_one): Likewise.
	(__atomic_ref<_Tp>::notify_all): Likewise.
	(atomic_wait<_Tp>): Likewise.
	(atomic_wait_explicit<_Tp>): Likewise.
	(atomic_notify_one<_Tp>): Likewise.
	(atomic_notify_all<_Tp>): Likewise.
	* include/bits/atomic_wait.h: New file.
* include/bits/atomic_timed_wait.h: New file.
* include/bits/semaphore_base.h: New file.
	* include/std/atomic (atomic::wait): Define.
	(atomic::wait_one): Likewise.
	(atomic::wait_all): Likewise.
	(atomic<_Tp>::wait): Likewise.
	(atomic<_Tp>::wait_one): Likewise.
	(atomic<_Tp>::wait_all): Likewise.
	(atomic<_Tp*>::wait): Likewise.
	(atomic<_Tp*>::wait_one): Likewise.
	(atomic<_Tp*>::wait_all): Likewise.
* include/std/latch: New file.
* include/std/semaphore: New file.
* include/std/version: Add __cpp_lib_semaphore and
__cpp_lib_latch defines.
	* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
	* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
	* 

Re: [PATCH] Mark experimental::net::system_context ctor deleted

2020-04-23 Thread Thomas Rodgers via Gcc-patches
Tested x86_64_linux.
Commited to master, backported to releases/gcc-9.

Jonathan Wakely writes:

> On 23/04/20 13:09 -0700, Thomas Rodgers via Libstdc++ wrote:
>>
>>  * include/experimental/net/executor: Mark
>>  system_context::system_context() = default.
>
> s/default/delete/ :-)
>
> But the affected function/type/thingie should be named in parens, not
> in the comment i.e.
>
>   * include/experimental/net/executor (system_context): Define default
> constructor as deleted.
>
>>  * testsuite/experimental/net/executor/1.cc: Add new
>>  test for deleted system_context ::system_context().
>
> There's a stray space in there.
>
> It would be more accurate to say "check system_context isn't default
> constructible" because you can't test if it's deleted, as opposed to
> private or just doesn't exist.
>
> OK with those changelog tweaks.
>
> Please backport to gcc-9 too.
>
>
>
>>---
>> libstdc++-v3/include/experimental/executor| 2 +-
>> libstdc++-v3/testsuite/experimental/net/executor/1.cc | 7 +++
>> 2 files changed, 8 insertions(+), 1 deletion(-)
>>
>>diff --git a/libstdc++-v3/include/experimental/executor 
>>b/libstdc++-v3/include/experimental/executor
>>index b5c6e18a19a..fa39eaa0468 100644
>>--- a/libstdc++-v3/include/experimental/executor
>>+++ b/libstdc++-v3/include/experimental/executor
>>@@ -850,7 +850,7 @@ inline namespace v1
>>
>> // construct / copy / destroy:
>>
>>-system_context() = default;
>>+system_context() = delete;
>> system_context(const system_context&) = delete;
>> system_context& operator=(const system_context&) = delete;
>>
>>diff --git a/libstdc++-v3/testsuite/experimental/net/executor/1.cc 
>>b/libstdc++-v3/testsuite/experimental/net/executor/1.cc
>>index 456d620e193..cd0af4b7737 100644
>>--- a/libstdc++-v3/testsuite/experimental/net/executor/1.cc
>>+++ b/libstdc++-v3/testsuite/experimental/net/executor/1.cc
>>@@ -85,9 +85,16 @@ test02()
>>   VERIFY( e == g );
>> }
>>
>>+void
>>+test03()
>>+{
>>+  static_assert( ! 
>>std::is_default_constructible::value, "" );
>>+}
>>+
>> int
>> main()
>> {
>>   test01();
>>   test02();
>>+  test03();
>> }
>> -- 
>>2.25.3
>>
>>
>>



[PATCH] Mark experimental::net::system_context ctor deleted

2020-04-23 Thread Thomas Rodgers via Gcc-patches


  * include/experimental/net/executor: Mark
  system_context::system_context() = default.
  * testsuite/experimental/net/executor/1.cc: Add new
  test for deleted system_context ::system_context().
---
 libstdc++-v3/include/experimental/executor| 2 +-
 libstdc++-v3/testsuite/experimental/net/executor/1.cc | 7 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/experimental/executor 
b/libstdc++-v3/include/experimental/executor
index b5c6e18a19a..fa39eaa0468 100644
--- a/libstdc++-v3/include/experimental/executor
+++ b/libstdc++-v3/include/experimental/executor
@@ -850,7 +850,7 @@ inline namespace v1
 
 // construct / copy / destroy:
 
-system_context() = default;
+system_context() = delete;
 system_context(const system_context&) = delete;
 system_context& operator=(const system_context&) = delete;
 
diff --git a/libstdc++-v3/testsuite/experimental/net/executor/1.cc 
b/libstdc++-v3/testsuite/experimental/net/executor/1.cc
index 456d620e193..cd0af4b7737 100644
--- a/libstdc++-v3/testsuite/experimental/net/executor/1.cc
+++ b/libstdc++-v3/testsuite/experimental/net/executor/1.cc
@@ -85,9 +85,16 @@ test02()
   VERIFY( e == g );
 }
 
+void
+test03()
+{
+  static_assert( ! std::is_default_constructible::value, 
"" );
+}
+
 int
 main()
 {
   test01();
   test02();
+  test03();
 }
-- 
2.25.3

 



Re: [PATCH] Add C++2a wait/notify_one/notify_all support to std::atomic<>

2020-03-23 Thread Thomas Rodgers via Gcc-patches
Updated patch, fixes some whitespace issues along with ensuring that
libstdc++-v3/include/Makefile.in is regenerated.
>From 2f707faab97abde776bc7c6e06f7a7c471711962 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Thu, 12 Mar 2020 17:50:09 -0700
Subject: [PATCH] Add C++2a wait/notify_one/notify_all support to std::atomic<>

	* include/Makefile.am (bits_headers): Add new header.
	* include/Makefile.in: Regenerate.
	* include/bits/atomic_base.h (__atomic_base<_Itp>:wait): Define.
	(__atomic_base<_Itp>::notify_one): Likewise.
	(__atomic_base<_Itp>::notify_all): Likewise.
	(__atomic_base<_Ptp*>::wait): Likewise.
	(__atomic_base<_Ptp*>::notify_one): Likewise.
	(__atomic_base<_Ptp*>::notify_all): Likewise.
	(__atomic_impl::wait): Likewise.
	(__atomic_impl::notify_one): Likewise.
	(__atomic_impl::notify_all): Likewise.
	(__atomic_float<_Fp>::wait): Likewise.
	(__atomic_float<_Fp>::notify_one): Likewise.
	(__atomic_float<_Fp>::notify_all): Likewise.
	(__atomic_ref<_Tp>::wait): Likewise.
	(__atomic_ref<_Tp>::notify_one): Likewise.
	(__atomic_ref<_Tp>::notify_all): Likewise.
	(atomic_wait<_Tp>): Likewise.
	(atomic_wait_explicit<_Tp>): Likewise.
	(atomic_notify_one<_Tp>): Likewise.
	(atomic_notify_all<_Tp>): Likewise.
	* include/bits/atomic_wait.h: New file.
	* include/std/atomic (atomic::wait): Define.
	(atomic::wait_one): Likewise.
	(atomic::wait_all): Likewise.
	(atomic<_Tp>::wait): Likewise.
	(atomic<_Tp>::wait_one): Likewise.
	(atomic<_Tp>::wait_all): Likewise.
	(atomic<_Tp*>::wait): Likewise.
	(atomic<_Tp*>::wait_one): Likewise.
	(atomic<_Tp*>::wait_all): Likewise.
	* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
	* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.

Tested x86_64-pc-linux-gnu.
---
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   1 +
 libstdc++-v3/include/bits/atomic_base.h   | 178 ++-
 libstdc++-v3/include/bits/atomic_wait.h   | 284 ++
 libstdc++-v3/include/std/atomic   |  61 
 .../atomic/wait_notify/atomic_refs.cc | 103 +++
 .../29_atomics/atomic/wait_notify/bool.cc |  57 
 .../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
 .../29_atomics/atomic/wait_notify/generic.h   |  88 ++
 .../atomic/wait_notify/integrals.cc   |  56 
 .../29_atomics/atomic/wait_notify/pointers.cc |  59 
 11 files changed, 919 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/include/bits/atomic_wait.h
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/atomic_refs.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/bool.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/floats.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/generic.h
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/integrals.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/pointers.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 80aeb3f8959..d195a721fd5 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -100,6 +100,7 @@ bits_headers = \
 	${bits_srcdir}/allocated_ptr.h \
 	${bits_srcdir}/allocator.h \
 	${bits_srcdir}/atomic_base.h \
+	${bits_srcdir}/atomic_wait.h \
 	${bits_srcdir}/atomic_futex.h \
 	${bits_srcdir}/basic_ios.h \
 	${bits_srcdir}/basic_ios.tcc \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index eb437ad8d8d..f19c3342f06 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -445,6 +445,7 @@ bits_headers = \
 	${bits_srcdir}/allocated_ptr.h \
 	${bits_srcdir}/allocator.h \
 	${bits_srcdir}/atomic_base.h \
+	${bits_srcdir}/atomic_wait.h \
 	${bits_srcdir}/atomic_futex.h \
 	${bits_srcdir}/basic_ios.h \
 	${bits_srcdir}/basic_ios.tcc \
diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 87fe0bd6000..b4fbe2c6eb3 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -37,6 +37,11 @@
 #include 
 #include 
 
+#if __cplusplus > 201703L
+#include 
+#include 
+#endif
+
 #ifndef _GLIBCXX_ALWAYS_INLINE
 #define _GLIBCXX_ALWAYS_INLINE inline __attribute__((__always_inline__))
 #endif
@@ -134,7 +139,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   return __ret;
 }
 
-
   // Base types for atomics.
   template
 struct __atomic_base;
@@ -542,6 +546,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    __cmpexch_failure_order(__m));
   }
 
+#if __cplusplus > 201703L
+  _GLIBCXX_ALWAYS_INLINE void
+  

Re: [PATCH] Add C++2a wait/notify_one/notify_all support to std::atomic<>

2020-03-17 Thread Thomas Rodgers via Gcc-patches
Updated patch attached, addresses some minor issues I found after
sending the original version.
>From 0c677da72a058e37d0ea1975dc70e53c4308963c Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Thu, 12 Mar 2020 17:50:09 -0700
Subject: [PATCH] Add C++2a wait/notify_one/notify_all support to std::atomic<>

This patch adds support for wait/notify_one/notify_all to std::atomic<>.
Support for the volatile overloads will be added in a subsequent patch.

	* include/Makefile.am (bits_headers): Add new header.
	* include/Mamefile.in: Regenerate.
	* include/bits/atomic_base.h (__atomic_base<_Itp>:wait): Define.
	(__atomic_base<_Itp>::notify_one): Likewise.
	(__atomic_base<_Itp>::notify_all): Likewise.
	(__atomic_base<_Ptp*>::wait): Likewise.
	(__atomic_base<_Ptp*>::notify_one): Likewise.
	(__atomic_base<_Ptp*>::notify_all): Likewise.
	(__atomic_impl::wait): Likewise.
	(__atomic_impl::notify_one): Likewise.
	(__atomic_impl::notify_all): Likewise.
	(__atomic_float<_Fp>::wait): Likewise.
	(__atomic_float<_Fp>::notify_one): Likewise.
	(__atomic_float<_Fp>::notify_all): Likewise.
	(__atomic_ref<_Tp>::wait): Likewise.
	(__atomic_ref<_Tp>::notify_one): Likewise.
	(__atomic_ref<_Tp>::notify_all): Likewise.
	(atomic_wait<_Tp>): Likewise.
	(atomic_wait_explicit<_Tp>): Likewise.
	(atomic_notify_one<_Tp>): Likewise.
	(atomic_notify_all<_Tp>): Likewise.
	* include/bits/atomic_wait.h: New file.
	* include/std/atomic (atomic::wait): Define.
	(atomic::wait_one): Likewise.
	(atomic::wait_all): Likewise.
	(atomic<_Tp>::wait): Likewise.
	(atomic<_Tp>::wait_one): Likewise.
	(atomic<_Tp>::wait_all): Likewise.
	(atomic<_Tp*>::wait): Likewise.
	(atomic<_Tp*>::wait_one): Likewise.
	(atomic<_Tp*>::wait_all): Likewise.
	* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
	* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
---
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   2 +
 libstdc++-v3/include/bits/atomic_base.h   | 178 ++-
 libstdc++-v3/include/bits/atomic_wait.h   | 295 ++
 libstdc++-v3/include/std/atomic   |  61 
 .../atomic/wait_notify/atomic_refs.cc | 103 ++
 .../29_atomics/atomic/wait_notify/bool.cc |  57 
 .../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
 .../29_atomics/atomic/wait_notify/generic.h   |  88 ++
 .../atomic/wait_notify/integrals.cc   |  56 
 .../29_atomics/atomic/wait_notify/pointers.cc |  59 
 11 files changed, 931 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/include/bits/atomic_wait.h
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/atomic_refs.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/bool.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/floats.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/generic.h
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/integrals.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/pointers.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 80aeb3f8959..d195a721fd5 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -100,6 +100,7 @@ bits_headers = \
 	${bits_srcdir}/allocated_ptr.h \
 	${bits_srcdir}/allocator.h \
 	${bits_srcdir}/atomic_base.h \
+	${bits_srcdir}/atomic_wait.h \
 	${bits_srcdir}/atomic_futex.h \
 	${bits_srcdir}/basic_ios.h \
 	${bits_srcdir}/basic_ios.tcc \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index eb437ad8d8d..4faaac5fb8d 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -445,6 +445,7 @@ bits_headers = \
 	${bits_srcdir}/allocated_ptr.h \
 	${bits_srcdir}/allocator.h \
 	${bits_srcdir}/atomic_base.h \
+	${bits_srcdir}/atomic_wait.h \
 	${bits_srcdir}/atomic_futex.h \
 	${bits_srcdir}/basic_ios.h \
 	${bits_srcdir}/basic_ios.tcc \
@@ -526,6 +527,7 @@ bits_headers = \
 	${bits_srcdir}/specfun.h \
 	${bits_srcdir}/sstream.tcc \
 	${bits_srcdir}/std_abs.h \
+	${bits_srcdir}/std_condvar.h \
 	${bits_srcdir}/std_function.h \
 	${bits_srcdir}/std_mutex.h \
 	${bits_srcdir}/stl_algo.h \
diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 87fe0bd6000..b4fbe2c6eb3 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -37,6 +37,11 @@
 #include 
 #include 
 
+#if __cplusplus > 201703L
+#include 
+#include 
+#endif
+
 #ifndef _GLIBCXX_ALWAYS_INLINE
 #define _GLIBCXX_ALWAYS_INLINE inline __attribute__((__always_inline__))
 

[PATCH] Add C++2a wait/notify_one/notify_all support to std::atomic<>

2020-03-12 Thread Thomas Rodgers via Gcc-patches
From f650ed07ed13c40624b72b7b4bebd967fa33f917 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Thu, 12 Mar 2020 17:50:09 -0700
Subject: [PATCH] Add C++2a wait/notify_one/notify_all support to std::atomic<>

	* include/Makefile.am (bits_headers): Add new header.
	* include/Mamefile.in: Regenerate.
	* include/bits/atomic_base.h (__atomic_base<_Itp>:wait): Define.
	(__atomic_base<_Itp>:notify_one): Likewise.
	(__atomic_base<_Itp>:notify_all): Likewise.
	(__atomic_base<_Ptp*>:wait): Likewise.
	(__atomic_base<_Ptp*>:notify_one): Likewise.
	(__atomic_base<_Ptp*>:notify_all): Likewise.
	(__atomic_impl:wait): Likewise.
	(__atomic_impl:notify_one): Likewise.
	(__atomic_impl:notify_all): Likewise.
	(__atomic_float<_Fp>:wait): Likewise.
	(__atomic_float<_Fp>:notify_one): Likewise.
	(__atomic_float<_Fp>:notify_all): Likewise.
	(__atomic_ref<_Tp>:wait): Likewise.
	(__atomic_ref<_Tp>:notify_one): Likewise.
	(__atomic_ref<_Tp>:notify_all): Likewise.
	* include/bits/atomic_wait.h: New file.
	* include/std/atomic (atomic::wait): Define.
	(atomic::wait_one): Likewise.
	(atomic::wait_all): Likewise.
	(atomic<_Tp>::wait): Likewise.
	(atomic<_Tp>::wait_one): Likewise.
	(atomic<_Tp>::wait_all): Likewise.
	(atomic<_Tp*>::wait): Likewise.
	(atomic<_Tp*>::wait_one): Likewise.
	(atomic<_Tp*>::wait_all): Likewise.
	* testsuite/29_atomic/atomic/wait_notify/atomic_refs.cc: New test.
	* testsuite/29_atomic/atomic/wait_notify/bool.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/integrals.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/floats.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
	* testsuite/29_atomic/atomic/wait_notify/generic.h: New File.
---
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   2 +
 libstdc++-v3/include/bits/atomic_base.h   | 180 ++-
 libstdc++-v3/include/bits/atomic_wait.h   | 295 ++
 libstdc++-v3/include/std/atomic   |  38 +++
 .../atomic/wait_notify/atomic_refs.cc | 103 ++
 .../29_atomics/atomic/wait_notify/bool.cc |  57 
 .../29_atomics/atomic/wait_notify/floats.cc   |  32 ++
 .../29_atomics/atomic/wait_notify/generic.h   |  62 
 .../atomic/wait_notify/integrals.cc   |  56 
 .../29_atomics/atomic/wait_notify/pointers.cc |  59 
 11 files changed, 883 insertions(+), 2 deletions(-)
 create mode 100644 libstdc++-v3/include/bits/atomic_wait.h
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/atomic_refs.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/bool.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/floats.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/generic.h
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/integrals.cc
 create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/pointers.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 80aeb3f8959..d195a721fd5 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -100,6 +100,7 @@ bits_headers = \
 	${bits_srcdir}/allocated_ptr.h \
 	${bits_srcdir}/allocator.h \
 	${bits_srcdir}/atomic_base.h \
+	${bits_srcdir}/atomic_wait.h \
 	${bits_srcdir}/atomic_futex.h \
 	${bits_srcdir}/basic_ios.h \
 	${bits_srcdir}/basic_ios.tcc \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index eb437ad8d8d..4faaac5fb8d 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -445,6 +445,7 @@ bits_headers = \
 	${bits_srcdir}/allocated_ptr.h \
 	${bits_srcdir}/allocator.h \
 	${bits_srcdir}/atomic_base.h \
+	${bits_srcdir}/atomic_wait.h \
 	${bits_srcdir}/atomic_futex.h \
 	${bits_srcdir}/basic_ios.h \
 	${bits_srcdir}/basic_ios.tcc \
@@ -526,6 +527,7 @@ bits_headers = \
 	${bits_srcdir}/specfun.h \
 	${bits_srcdir}/sstream.tcc \
 	${bits_srcdir}/std_abs.h \
+	${bits_srcdir}/std_condvar.h \
 	${bits_srcdir}/std_function.h \
 	${bits_srcdir}/std_mutex.h \
 	${bits_srcdir}/stl_algo.h \
diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 87fe0bd6000..0581c41b30f 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -37,6 +37,11 @@
 #include 
 #include 
 
+#if __cplusplus > 201703L
+#include 
+#include 
+#endif
+
 #ifndef _GLIBCXX_ALWAYS_INLINE
 #define _GLIBCXX_ALWAYS_INLINE inline __attribute__((__always_inline__))
 #endif
@@ -134,7 +139,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   return __ret;
 }
 
-
   // Base types for atomics.
   template
 struct __atomic_base;
@@ -542,6 +546,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    __cmpexch_failure_order(__m));
   }
 
+#if __cplusplus > 201703L
+  _GLIBCXX_ALWAYS_INLINE void
+  wait(__int_type __old, memory_order __m = memory_order_seq_cst)