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

2020-10-21 Thread Thomas Rodgers



> On Oct 21, 2020, at 10:34 AM, Jonathan Wakely  wrote:
> 
> On 21/10/20 09:53 -0700, Thomas Rodgers wrote:
>> From: Thomas Rodgers 
>> 
>> 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.
>>  libstdc++-v3/include/std/streambuf
>>   (__detail::__streambuf_core_access): Define.
>>   (basic_streambuf): Befriend __detail::__streambuf_core_access.
> 
> This file is no longer part of the commit, so the server will reject
> this changelog. Please ensure the changelog is accurate (the
> gcc-verify alias created by contrib/gcc-git-customization.sh can do
> that) and push, thanks.
> 

This patch is dependent on the changes to  so I can’t push until that 
patch lands.

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

2020-10-21 Thread Thomas Rodgers
From: Thomas Rodgers 

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.
libstdc++-v3/include/std/streambuf
(__detail::__streambuf_core_access): Define.
(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   | 279 ++
 libstdc++-v3/include/std/version  |   4 +
 .../testsuite/27_io/basic_syncbuf/1.cc|  28 ++
 .../testsuite/27_io/basic_syncbuf/2.cc|  27 ++
 .../27_io/basic_syncbuf/basic_ops/1.cc| 138 +
 .../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 |  27 ++
 .../27_io/basic_syncstream/basic_ops/1.cc | 135 +
 .../basic_syncstream/requirements/types.cc|  43 +++
 15 files changed, 885 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 28d273924ee..61aaff7a2f4 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..3f78cef1d8d
--- /dev/null
+++ b/libstdc++-v3/include/std/syncstream
@@ -0,0 +1,279 @@
+//  -*- C++ -*-
+
+// 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

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

2020-10-15 Thread Thomas Rodgers
From: Thomas Rodgers 

This should address the cumulative comments (modulo the discussion going
on on the reflector about specification issues/questions).

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: Includ new header.
libstdc++-v3/include/std/streambuf
(__detail::__streambuf_core_access): Define.
(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/sstream  |   2 +-
 libstdc++-v3/include/std/syncstream   | 276 ++
 libstdc++-v3/include/std/version  |   4 +
 .../testsuite/27_io/basic_syncbuf/1.cc|  28 ++
 .../testsuite/27_io/basic_syncbuf/2.cc|  27 ++
 .../27_io/basic_syncbuf/basic_ops/1.cc| 138 +
 .../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 |  27 ++
 .../27_io/basic_syncstream/basic_ops/1.cc | 135 +
 .../basic_syncstream/requirements/types.cc|  43 +++
 16 files changed, 883 insertions(+), 2 deletions(-)
 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 28d273924ee..61aaff7a2f4 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/sstream b/libstdc++-v3/include/std/sstream
index b0d1decfe63..5379f025eef 100644
--- a/libstdc++-v3/include/std/sstream
+++ b/libstdc++-v3/include/std/sstream
@@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   // 27.8.2.2 Assign and swap:
 
   basic_stringbuf&
-  operator=(const basic_stringbuf&) = delete;
+ operator=(const basic_s

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

2020-10-15 Thread Thomas Rodgers
From: Thomas Rodgers 

* Note: depends on a sufficiently C++20ified basic_stringbuf<>.

libstdc++/Changelog:
libstdc++-v3/include/Makefile.am (std_headers): Add new header.
libstdc++-v3/include/Makefile.in: Regenerate.
libstdc++-v3/include/std/streambuf
(__detail::__streambuf_core_access): Define.
(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/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   1 +
 libstdc++-v3/include/std/streambuf|  81 +
 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|  27 ++
 .../27_io/basic_syncbuf/basic_ops/1.cc| 138 
 .../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 |  27 ++
 .../27_io/basic_syncstream/basic_ops/1.cc | 135 +++
 .../basic_syncstream/requirements/types.cc|  43 +++
 14 files changed, 1018 insertions(+)
 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/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 28d273924ee..61aaff7a2f4 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/std/streambuf 
b/libstdc++-v3/include/std/streambuf
index cae35e75bda..d6053e4c1ed 100644
--- a/libstdc++-v3/include/std/streambuf
+++ b/libstdc++-v3/include/std/streambuf
@@ -48,6 +48,84 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #define _IsUnused __attribute__ ((__unused__))
 
+  template
+class basic_streambuf;
+
+#if __cplusplus > 201703L
+  namespace __detail
+  {
+struct __streambuf_core_access
+{
+  template
+   static void
+   _S_imbue(basic_streambuf<_CharT, _Traits>& __b, const locale& __loc)
+   { __b.imbue(__loc); }
+
+  template
+   static basic_streambuf<_CharT, _Traits>*
+   _S_setbuf(basic_streambuf<_CharT, _Traits>& __b,
+ _CharT* __c, streamsize __n)
+   { return __b.setbuf(__c, __n); }
+
+  template
+   static typename _Traits::pos_type
+   _S_seekoff(basic_streambuf<_CharT, _Traits>& __b,
+  typename _Traits::off_type __off, ios_base::seekdir __dir,
+  ios_base::openmode __mode)
+ { return __b.seekoff(__off, __dir, __mode); }
+
+  template
+   static typename _Traits::pos_type
+   _S_seekpos(basic_streambuf<_CharT, _Traits>& __b,
+  typename _Traits::pos_type __pos, ios_base::openmode __mode)
+   { return __b.seekpos(__pos, __mode); }
+
+  template
+   static int
+   _S_sync(basic_streambuf<_CharT, _Traits>& __b)
+   { return __b.sync(); }
+
+  template
+   static streamsize
+   _S_showmanyc(basic_streambuf<_CharT, _Traits>& __b)
+   { return _

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
>>+// <http://www.gnu.org/licenses/>.
>>+
>>+//
>>+// 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

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

2020-10-07 Thread Thomas Rodgers
From: Thomas Rodgers 

New ctors and ::view() accessor for -
  * basic_stingbuf
  * basic_istringstream
  * basic_ostringstream
  * basic_stringstreamm

New ::get_allocator() accessor for basic_stringbuf.

libstdc++-v3/ChangeLog:
* acinclude.m4 (glibcxx_SUBDIRS): Add src/c++20.
* config/abi/pre/gnu.ver: Update GLIBCXX_3.4.29 for the addition of -
basic_stringbuf::basic_stringbuf(allocator const&),
basic_stringbuf::basic_stringbuf(openmode, allocator const&),
basic_stringbuf::basic_stringbuf(basic_string&&, openmode),
basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator const&),
basic_stringbuf::get_allocator(),
basic_stringbuf::view(),
basic_istringstream::basic_istringstream(basic_string&&, openmode),
basic_istringstream::basic_istringstream(openmode, allocator const&),
basic_istringstream::view(),
basic_ostringstream::basic_ostringstream(basic_string&&, openmode),
basic_ostringstream::basic_ostringstream(openmode, allocator const&),
basic_ostringstream::view(),
basic_stringstream::basic_stringstream(basic_string&&, openmode),
basic_stringstream::basic_stringstream(openmode, allocator const&),
basic_stringstream::view().
* configure: Regenerate.
* include/std/sstream:
(basic_stringbuf::basic_stringbuf(allocator const&)): New constructor.
(basic_stringbuf::basic_stringbuf(openmode, allocator const&)): 
Likewise.
(basic_stringbuf::basic_stringbuf(basic_string&&, openmode)): Likewise.
(basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator 
const&)): Likewise.
(basic_stringbuf::get_allocator()): New method.
(basic_stringbuf::view()): Likewise.
(basic_istringstream::basic_istringstream(basic_string&&, openmode)):
New constructor.
(basic_istringstream::basic_istringstream(openmode, allocator const&)):
Likewise
(basic_istringstream::view()): New method.
(basic_ostringstream::basic_ostringstream(basic_string&&, openmode)):
New constructor.
(basic_ostringstream::basic_ostringstream(openmode, allocator const&)):
Likewise
(basic_ostringstream::view()): New method.
(basic_stringstream::basic_stringstream(basic_string&&, openmode)):
New constructor.
(basic_stringstream::basic_stringstream(openmode, allocator const&)):
Likewise
(basic_stringstream::view()): New method.
* src/Makefile.in: Add c++20 directory.
* src/Makefile.am: Regenerate.
* src/c++20/Makefile.am: Add makefile for new sub-directory.
* src/c++20/Makefile.in: Generate.
* src/c++20/sstream-inst.cc: New file defining explicit
instantiations for basic_stringbuf, basic_istringstream,
basic_ostringstream, and basic_stringstream member functions
added in C++20.
* testsuite/27_io/basic_stringbuf/cons/char/2.cc: New test.
* testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_stringbuf/view/char/2.cc: Likewise.
* testsuite/27_io/basic_stringbuf/view/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/cons/char/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/view/char/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/view/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/cons/char/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/view/char/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/view/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/cons/char/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/char/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/wchar_t/2.cc: Likewise.
---
 libstdc++-v3/acinclude.m4 |   2 +-
 libstdc++-v3/config/abi/pre/gnu.ver   |  45 ++
 libstdc++-v3/configure|  16 +-
 libstdc++-v3/include/std/sstream  | 196 +
 libstdc++-v3/src/Makefile.am  |  12 +-
 libstdc++-v3/src/Makefile.in  |  14 +-
 libstdc++-v3/src/c++20/Makefile.am| 105 +++
 libstdc++-v3/src/c++20/Makefile.in| 735 ++
 libstdc++-v3/src/c++20/sstream-inst.cc| 111 +++
 .../27_io/basic_istringstream/cons/char/1.cc  |  85 ++
 .../basic_istringstream/cons/wchar_t/1.cc |  85 ++
 .../27_io/basic_istringstream/view/char/1.cc  |  35 +
 .../basic_istringstream/view/wchar_t/1.cc | 

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

2020-10-07 Thread Thomas Rodgers
From: Thomas Rodgers 

New ctors and ::view() accessor for -
  * basic_stingbuf
  * basic_istringstream
  * basic_ostringstream
  * basic_stringstreamm

New ::get_allocator() accessor for basic_stringbuf.

libstdc++-v3/ChangeLog:
* acinclude.m4 (glibcxx_SUBDIRS): Add src/c++20.
* config/abi/pre/gnu.ver: Update GLIBCXX_3.4.29 for the addition of -
basic_stringbuf::basic_stringbuf(allocator const&),
basic_stringbuf::basic_stringbuf(openmode, allocator const&),
basic_stringbuf::basic_stringbuf(basic_string&&, openmode),
basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator const&),
basic_stringbuf::get_allocator(),
basic_stringbuf::view(),
basic_istringstream::basic_istringstream(basic_string&&, openmode),
basic_istringstream::basic_istringstream(openmode, allocator const&),
basic_istringstream::view(),
basic_ostringstream::basic_ostringstream(basic_string&&, openmode),
basic_ostringstream::basic_ostringstream(openmode, allocator const&),
basic_ostringstream::view(),
basic_stringstream::basic_stringstream(basic_string&&, openmode),
basic_stringstream::basic_stringstream(openmode, allocator const&),
basic_stringstream::view().
* configure: Regenerate.
* include/std/sstream:
(basic_stringbuf::basic_stringbuf(allocator const&)): New constructor.
(basic_stringbuf::basic_stringbuf(openmode, allocator const&)): 
Likewise.
(basic_stringbuf::basic_stringbuf(basic_string&&, openmode)): Likewise.
(basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator 
const&)): Likewise.
(basic_stringbuf::get_allocator()): New method.
(basic_stringbuf::view()): Likewise.
(basic_istringstream::basic_istringstream(basic_string&&, openmode)):
New constructor.
(basic_istringstream::basic_istringstream(openmode, allocator const&)):
Likewise
(basic_istringstream::view()): New method.
(basic_ostringstream::basic_ostringstream(basic_string&&, openmode)):
New constructor.
(basic_ostringstream::basic_ostringstream(openmode, allocator const&)):
Likewise
(basic_ostringstream::view()): New method.
(basic_stringstream::basic_stringstream(basic_string&&, openmode)):
New constructor.
(basic_stringstream::basic_stringstream(openmode, allocator const&)):
Likewise
(basic_stringstream::view()): New method.
* src/Makefile.in: Add c++20 directory.
* src/Makefile.am: Regenerate.
* src/c++20/Makefile.am: Add makefile for new sub-directory.
* src/c++20/Makefile.in: Generate.
* src/c++20/sstream-inst.cc: New file defining explicit
instantiations for basic_stringbuf, basic_istringstream,
basic_ostringstream, and basic_stringstream member functions
added in C++20.
* testsuite/27_io/basic_stringbuf/cons/char/2.cc: New test.
* testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_stringbuf/view/char/2.cc: Likewise.
* testsuite/27_io/basic_stringbuf/view/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/cons/char/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/view/char/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/view/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/cons/char/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/view/char/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/view/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/cons/char/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/char/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/wchar_t/2.cc: Likewise.
---
 .topdeps  |   1 +
 .topmsg   |   2 +
 libstdc++-v3/acinclude.m4 |   2 +-
 libstdc++-v3/config/abi/pre/gnu.ver   |  45 ++
 libstdc++-v3/configure|  16 +-
 libstdc++-v3/include/std/sstream  | 196 +
 libstdc++-v3/src/Makefile.am  |  12 +-
 libstdc++-v3/src/Makefile.in  |  14 +-
 libstdc++-v3/src/c++20/Makefile.am| 105 +++
 libstdc++-v3/src/c++20/Makefile.in| 735 ++
 libstdc++-v3/src/c++20/sstream-inst.cc| 110 +++
 .../27_io/basic_istringstream/cons/char/1.cc  |  85 ++
 .../basic_istringstream/cons/wchar_t/1.cc |

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

2020-10-07 Thread Thomas Rodgers
From: Thomas Rodgers 

New ctors and ::view() accessor for -
  * basic_stingbuf
  * basic_istringstream
  * basic_ostringstream
  * basic_stringstreamm

New ::get_allocator() accessor for basic_stringbuf.

libstdc++-v3/ChangeLog:
* acinclude.m4 (glibcxx_SUBDIRS): Add src/c++20.
* config/abi/pre/gnu.ver: Update GLIBCXX_3.4.29 for the addition of -
basic_stringbuf::basic_stringbuf(allocator const&),
basic_stringbuf::basic_stringbuf(openmode, allocator const&),
basic_stringbuf::basic_stringbuf(basic_string&&, openmode),
basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator const&),
basic_stringbuf::get_allocator(),
basic_stringbuf::view(),
basic_istringstream::basic_istringstream(basic_string&&, openmode),
basic_istringstream::basic_istringstream(openmode, allocator const&),
basic_istringstream::view(),
basic_ostringstream::basic_ostringstream(basic_string&&, openmode),
basic_ostringstream::basic_ostringstream(openmode, allocator const&),
basic_ostringstream::view(),
basic_stringstream::basic_stringstream(basic_string&&, openmode),
basic_stringstream::basic_stringstream(openmode, allocator const&),
basic_stringstream::view().
* configure: Regenerate.
* include/std/sstream:
(basic_stringbuf::basic_stringbuf(allocator const&)): New constructor.
(basic_stringbuf::basic_stringbuf(openmode, allocator const&)): 
Likewise.
(basic_stringbuf::basic_stringbuf(basic_string&&, openmode)): Likewise.
(basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator 
const&)): Likewise.
(basic_stringbuf::get_allocator()): New method.
(basic_stringbuf::view()): Likewise.
(basic_istringstream::basic_istringstream(basic_string&&, openmode)):
New constructor.
(basic_istringstream::basic_istringstream(openmode, allocator const&)):
Likewise
(basic_istringstream::view()): New method.
(basic_ostringstream::basic_ostringstream(basic_string&&, openmode)):
New constructor.
(basic_ostringstream::basic_ostringstream(openmode, allocator const&)):
Likewise
(basic_ostringstream::view()): New method.
(basic_stringstream::basic_stringstream(basic_string&&, openmode)):
New constructor.
(basic_stringstream::basic_stringstream(openmode, allocator const&)):
Likewise
(basic_stringstream::view()): New method.
* src/Makefile.in: Add c++20 directory.
* src/Makefile.am: Regenerate.
* src/c++20/Makefile.am: Add makefile for new sub-directory.
* src/c++20/Makefile.in: Generate.
* src/c++20/sstream-inst.cc: New file defining explicit
instantiations for basic_stringbuf, basic_istringstream,
basic_ostringstream, and basic_stringstream member functions
added in C++20.
* testsuite/27_io/basic_stringbuf/cons/char/2.cc: New test.
* testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_stringbuf/view/char/2.cc: Likewise.
* testsuite/27_io/basic_stringbuf/view/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/cons/char/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/view/char/2.cc: Likewise.
* testsuite/27_io/basic_istringstream/view/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/cons/char/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/view/char/2.cc: Likewise.
* testsuite/27_io/basic_ostringstream/view/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/cons/char/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/cons/wchar_t/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/char/2.cc: Likewise.
* testsuite/27_io/basic_stringstream/view/wchar_t/2.cc: Likewise.
---
 .topdeps  |   1 +
 .topmsg   |   2 +
 libstdc++-v3/acinclude.m4 |   2 +-
 libstdc++-v3/config/abi/pre/gnu.ver   |  60 ++
 libstdc++-v3/configure|  16 +-
 libstdc++-v3/include/std/sstream  | 198 +
 libstdc++-v3/src/Makefile.am  |  12 +-
 libstdc++-v3/src/Makefile.in  |  14 +-
 libstdc++-v3/src/c++20/Makefile.am| 105 +++
 libstdc++-v3/src/c++20/Makefile.in| 735 ++
 libstdc++-v3/src/c++20/sstream-inst.cc| 110 +++
 .../27_io/basic_istringstream/cons/char/1.cc  |  84 ++
 .../basic_istringstream/cons/wchar_t/1.cc |

[PATCH] t/trodgers/c2a_synchronization

2020-10-05 Thread Thomas Rodgers
From: Thomas Rodgers 

This *should* be the correct patch this time.

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/bool.cc: New test.
* testsuite/29_atomic/atomic/wait_notify/pointers.cc: Likewise.
* testsuite/29_atomic/atomic/wait_notify/generic.cc: Liekwise.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: Likewise.
* testsuite/29_atomic/atomic_float/wait_notify.cc: Likewise.
* testsuite/29_atomic/atomic_integral/wait_notify.cc: Likewise.
* testsuite/29_atomic/atomic_ref/wait_notify.cc: Likewise.
* 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.
* testsuite/util/atomic/wait_notify_util.h: New File.

---
 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  | 288 +++
 libstdc++-v3/include/bits/atomic_wait.h| 306 +
 libstdc++-v3/include/bits/semaphore_base.h | 298 
 libstdc++-v3/include/std/atomic|  78 ++
 libstdc++-v3/include/std/latch |  91 ++
 libstdc++-v3/include/std/semaphore |  92 +++
 libstdc++-v3/include/std/version   |   2 +
 .../29_atomics/atomic/wait_notify/bool.cc  |  59 
 .../29_atomics/atomic/wait_notify/generic.cc   |  31 +++
 .../29_atomics/atomic/wait_notify/pointers.cc  |  59 
 .../29_atomics/atomic_flag/wait_notify/1.cc|  61 
 .../29_atomics/atomic_float/wait_notify.cc |  32 +++
 .../29_atomics/atomic_integral/wait_notify.cc  |  65 +
 .../testsuite/29_atomics/atomic_ref/wait_notify.cc | 103 +++
 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   |  69 +
 libstdc++-v3/testsuite/30_threads/semaphore/1.cc   |  27 ++
 libstdc++-v3/testsuite/30_threads/semaphore/2.cc   |  27 ++
 .../30_threads/semaphore/least_max_value_neg.cc|  30 ++
 .../testsuite/30_threads/semaphore/try_ac

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

2020-10-02 Thread Thomas Rodgers
From: Thomas Rodgers 

Updated patch incorporating latest feedback (revised).

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  |  30 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads

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

2020-10-01 Thread Thomas Rodgers
From: Thomas Rodgers 

Updated patch incorporating latest feedback.

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  |  30 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads/semaphore/try_acquire_for.

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/floa

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!



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

2020-09-21 Thread Thomas Rodgers



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

Re: [PATCH] Fix overflow handling in std::align

2020-09-14 Thread Thomas Rodgers



> On Sep 14, 2020, at 7:30 AM, Ville Voutilainen via Libstdc++ 
>  wrote:
> 
> On Mon, 14 Sep 2020 at 15:49, Glen Fernandes  wrote:
>> 
>> On Mon, Sep 14, 2020 at 5:52 AM Ville Voutilainen wrote:
>>> On Mon, 14 Sep 2020 at 12:51, Ville Voutilainen
>>> wrote:
 On Mon, 14 Sep 2020 at 09:18, Glen Fernandes
>>> wrote:
> Edit; Correct patch this time.
> 
> Fix overflow handling in align
 
 Should the test verify that space is unmodified when nullptr is returned?
>>> 
>>> ..and same for ptr.
>> 
>> Sounds like a good idea. Updated patch attached.
> 
> Looks good to me.

Agree.

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

2020-09-12 Thread Thomas Rodgers
From: Thomas Rodgers 

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



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

2020-09-11 Thread Thomas Rodgers
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  |  30 ++

[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



[PATCH] Split std::align/assume_aligned to bits/align.h

2020-09-09 Thread Thomas Rodgers
We would like to be able to use these things without having to pull in
the whole of .

* include/Makefile.am (bits_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/align.h: New file.
* include/std/memory (align): Move definition to bits/align.h.
(assume_aligned): Likewise.
---
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   1 +
 libstdc++-v3/include/bits/align.h | 104 ++
 libstdc++-v3/include/std/memory   |  60 +
 4 files changed, 107 insertions(+), 59 deletions(-)
 create mode 100644 libstdc++-v3/include/bits/align.h

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index bae97852348..eabec88219d 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -99,6 +99,7 @@ bits_srcdir = ${glibcxx_srcdir}/include/bits
 bits_builddir = ./bits
 bits_headers = \
${bits_srcdir}/algorithmfwd.h \
+   ${bits_srcdir}/align.h \
${bits_srcdir}/alloc_traits.h \
${bits_srcdir}/allocated_ptr.h \
${bits_srcdir}/allocator.h \
diff --git a/libstdc++-v3/include/bits/align.h 
b/libstdc++-v3/include/bits/align.h
new file mode 100644
index 000..593b337f897
--- /dev/null
+++ b/libstdc++-v3/include/bits/align.h
@@ -0,0 +1,104 @@
+// align implementation -*- C++ -*-
+
+// Copyright (C) 2008-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.
+
+// 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
+// .
+
+/** @file bits/align.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{memory}
+ */
+
+#ifndef _ALIGN_H
+#define _ALIGN_H 1
+
+#include 
+
+#include   // std::has_single_bit
+#include  // uintptr_t
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+/**
+ *  @brief Fit aligned storage in buffer.
+ *  @ingroup memory
+ *
+ *  This function tries to fit @a __size bytes of storage with alignment
+ *  @a __align into the buffer @a __ptr of size @a __space bytes.  If such
+ *  a buffer fits then @a __ptr is changed to point to the first byte of the
+ *  aligned storage and @a __space is reduced by the bytes used for alignment.
+ *
+ *  C++11 20.6.5 [ptr.align]
+ *
+ *  @param __align   A fundamental or extended alignment value.
+ *  @param __sizeSize of the aligned storage required.
+ *  @param __ptr Pointer to a buffer of @a __space bytes.
+ *  @param __space   Size of the buffer pointed to by @a __ptr.
+ *  @return the updated pointer if the aligned storage fits, otherwise nullptr.
+ *
+ */
+inline void*
+align(size_t __align, size_t __size, void*& __ptr, size_t& __space) noexcept
+{
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+  const auto __intptr = reinterpret_cast(__ptr);
+#else
+  // Cannot use std::uintptr_t so assume that std::size_t can be used instead.
+  static_assert(sizeof(size_t) >= sizeof(void*),
+  "std::size_t must be a suitable substitute for std::uintptr_t");
+  const auto __intptr = reinterpret_cast(__ptr);
+#endif
+  const auto __aligned = (__intptr - 1u + __align) & -__align;
+  const auto __diff = __aligned - __intptr;
+  if ((__size + __diff) > __space)
+return nullptr;
+  else
+{
+  __space -= __diff;
+  return __ptr = reinterpret_cast(__aligned);
+}
+}
+
+#if __cplusplus > 201703L
+#define __cpp_lib_assume_aligned 201811L
+  /** @brief Inform the compiler that a pointer is aligned.
+   *
+   *  @tparam _Align An alignment value (i.e. a power of two)
+   *  @tparam _TpAn object type
+   *  @param  __ptr  A pointer that is aligned to _Align
+   *  @ingroup memory
+   */
+  template
+[[nodiscard,__gnu__::__always_inline__]]
+constexpr _Tp* assume_aligned(_Tp* __ptr)
+{
+  static_assert(std::has_single_bit(_Align));
+  _GLIBCXX_DEBUG_ASSERT((std::uintptr_t)__ptr % _Align == 0);
+  return static_cast<_Tp*>(__builtin_assume_aligned(__ptr, _Align));
+}
+#endif // C++2a
+

[PATCH] Add support for atomic_flag::wait/notify_one/notify_all

2020-09-08 Thread Thomas Rodgers
* include/bits/atomic_base.h (__atomic_flag::wait): Define.
(__atomic_flag::notify_one): Likewise.
(__atomic_flag::notify_all): Likewise.
* testsuite/29_atomics/atomic_flag/wait_notify/1.cc: New test.
---
 libstdc++-v3/include/bits/atomic_base.h   | 23 +++
 .../29_atomics/atomic_flag/wait_notify/1.cc   | 61 +++
 2 files changed, 84 insertions(+)
 create mode 100644 
libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc

diff --git a/libstdc++-v3/include/bits/atomic_base.h 
b/libstdc++-v3/include/bits/atomic_base.h
index c121d993fee..a7ddd03d544 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -229,6 +229,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __atomic_load(&_M_i, &__v, int(__m));
   return __v == __GCC_ATOMIC_TEST_AND_SET_TRUEVAL;
 }
+
+_GLIBCXX_ALWAYS_INLINE void
+wait(bool __old,
+   memory_order __m = memory_order_seq_cst) const noexcept
+{
+  std::__atomic_wait(&_M_i, __old,
+[__m, this, __old]()
+{ return this->test(__m) != __old; });
+}
+
+// TODO add const volatile overload
+
+_GLIBCXX_ALWAYS_INLINE void
+notify_one() const noexcept
+{ std::__atomic_notify(&_M_i, false); }
+
+// TODO add const volatile overload
+
+_GLIBCXX_ALWAYS_INLINE void
+notify_all() const noexcept
+{ std::__atomic_notify(&_M_i, true); }
+
+// TODO add const volatile overload
 #endif // C++20
 
 _GLIBCXX_ALWAYS_INLINE void
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
new file mode 100644
index 000..6de7873ecc2
--- /dev/null
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/wait_notify/1.cc
@@ -0,0 +1,61 @@
+// { dg-options "-std=gnu++2a -pthread" }
+// { dg-do run { target c++2a } }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+
+// 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
+// .
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+int
+main()
+{
+  using namespace std::literals::chrono_literals;
+
+  std::mutex m;
+  std::condition_variable cv;
+
+  std::atomic_flag a;
+  std::atomic_flag b;
+  std::thread t([&]
+   {
+ cv.notify_one();
+ a.wait(false);
+  b.test_and_set();
+  b.notify_one();
+   });
+
+  std::unique_lock l(m);
+  cv.wait(l);
+  std::this_thread::sleep_for(100ms);
+  a.test_and_set();
+  a.notify_one();
+  b.wait(false);
+  t.join();
+
+  VERIFY( a.test() );
+  VERIFY( b.test() );
+  return 0;
+}
-- 
2.26.2



[PATCH] Add support for C++20 barriers

2020-09-07 Thread Thomas Rodgers
Re-sending

Adds 

* include/Makefile.am (std_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/bits/atomic_base.h (__atomic_base<_Itp>::_M_wait): Define.
(__atomic_base<_Itp>::wait): Delegate to _M_wait.
* include/std/barrier: New file.
* 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.
---
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   3 +-
 libstdc++-v3/include/bits/atomic_base.h   |  16 +-
 libstdc++-v3/include/std/barrier  | 230 ++
 libstdc++-v3/include/std/version  |   1 +
 .../testsuite/30_threads/barrier/1.cc |  27 ++
 .../testsuite/30_threads/barrier/2.cc |  27 ++
 .../testsuite/30_threads/barrier/arrive.cc|  34 +++
 .../30_threads/barrier/arrive_and_drop.cc |  32 +++
 .../30_threads/barrier/arrive_and_wait.cc |  33 +++
 .../30_threads/barrier/completion.cc  |  39 +++
 .../testsuite/30_threads/barrier/max.cc   |  26 ++
 12 files changed, 465 insertions(+), 4 deletions(-)
 create mode 100644 libstdc++-v3/include/std/barrier
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/1.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/2.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/arrive.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/arrive_and_drop.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/arrive_and_wait.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/completion.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/max.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index ef8acd4a389..bae97852348 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -30,6 +30,7 @@ std_headers = \
${std_srcdir}/any \
${std_srcdir}/array \
${std_srcdir}/atomic \
+   ${std_srcdir}/barrier \
${std_srcdir}/bit \
${std_srcdir}/bitset \
${std_srcdir}/charconv \
diff --git a/libstdc++-v3/include/bits/atomic_base.h 
b/libstdc++-v3/include/bits/atomic_base.h
index c121d993fee..98f9941c2d4 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -229,6 +229,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   __atomic_load(&_M_i, &__v, int(__m));
   return __v == __GCC_ATOMIC_TEST_AND_SET_TRUEVAL;
 }
+
 #endif // C++20
 
 _GLIBCXX_ALWAYS_INLINE void
@@ -566,13 +567,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 #if __cplusplus > 201703L
+  template
+   _GLIBCXX_ALWAYS_INLINE void
+   _M_wait(__int_type __old, _Pred&& __pred,
+   memory_order __m) const noexcept
+   {
+ std::__atomic_wait(&_M_i, __old,
+std::forward<_Pred&&>(__pred));
+   }
+
   _GLIBCXX_ALWAYS_INLINE void
   wait(__int_type __old,
  memory_order __m = memory_order_seq_cst) const noexcept
   {
-   std::__atomic_wait(&_M_i, __old,
-  [__m, this, __old]
-  { return this->load(__m) != __old; });
+   _M_wait(__old, [__m, this, __old]()
+   { return this->load(__m) != __old; },
+   __m);
   }
 
   // TODO add const volatile overload
diff --git a/libstdc++-v3/include/std/barrier b/libstdc++-v3/include/std/barrier
new file mode 100644
index 000..870db7db2ac
--- /dev/null
+++ b/libstdc++-v3/include/std/barrier
@@ -0,0 +1,230 @@
+//  -*- C++ -*-
+// This implementation is based on libcxx/include/barrier
+//===-- barrier.h --===//
+//
+// 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
+//
+//===---===//
+
+#ifndef _GLIBCXX_BARRIER
+#define _GLIBCXX_BARRIER 1
+
+#pragma GCC system_header
+
+#if __cplusplus > 201703L
+#define __cpp_lib_barrier 201907L
+
+#include 
+
+#if defined(_GLIBCXX_HAS_GTHREADS)
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  struct __empty_completion
+  {
+_GLIBCXX_ALWAYS_INLINE void
+operator()() noexcept
+{ }
+  };
+
+/*
+
+The default implementation of __barrier_base is a classic tree barrier.
+
+It looks different from literature pseudocode for two main 

[PATCH] Add C++2a synchronization support

2020-09-02 Thread Thomas Rodgers
Note - ignore previous version of this patch, didn't filter out
Makefile.in

Adds 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.cc: Liekwise.
* 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_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   | 172 +-
 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 
 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  |  30 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads/semaphore/try_acquire_for.cc   |  85 +
 .../30_threads/semaphore/try_acquire_posix.cc | 153 +
 .../30_threads/semaphore/try_acquire_until.cc |  94 ++
 27 files changed, 2387 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/include/bits/atomic_timed_wait.h
 create mode 100644 libstdc++-v3/include/bits/atomic_wait.h
 create mode 100644 libstdc++-v3/include/bits/semaphore_base.h
 create mode 100644 libstdc++-v3/include/std/latch
 create 

[PATCH] Add C++2a synchronization support

2020-09-02 Thread Thomas Rodgers
Adds 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.cc: Liekwise.
* 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_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   | 172 +-
 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 
 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  |  30 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads/semaphore/try_acquire_for.cc   |  85 +
 .../30_threads/semaphore/try_acquire_posix.cc | 153 +
 .../30_threads/semaphore/try_acquire_until.cc |  94 ++
 27 files changed, 2387 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/include/bits/atomic_timed_wait.h
 create mode 100644 libstdc++-v3/include/bits/atomic_wait.h
 create mode 100644 libstdc++-v3/include/bits/semaphore_base.h
 create mode 100644 libstdc++-v3/include/std/latch
 create mode 100644 libstdc++-v3/include/std/semaphore
 create mode 100644 

[PATCH 3/4] Adjust wait logic to limit spurious eval of wait predicate.

2020-06-06 Thread Thomas Rodgers
* include/bits/atomic_wait.h (__waiters::_M_do_wait): adjust wakeup
  logic.
---
 libstdc++-v3/include/bits/atomic_wait.h | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_wait.h 
b/libstdc++-v3/include/bits/atomic_wait.h
index 92c1e2526ed..cce11ae1cf5 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -138,24 +138,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
   void
-  _M_do_wait(__platform_wait_t __version) noexcept
+  _M_do_wait(__platform_wait_t __old) noexcept
   {
+   __platform_wait_t __cur;
+   __atomic_load(&_M_ver, &__cur, __ATOMIC_ACQUIRE);
+   while (__cur == __old)
+ {
 #ifdef _GLIBCXX_HAVE_LINUX_FUTEX
-   __platform_wait(&_M_ver, __version);
+   __platform_wait(&_M_ver, __cur);
 #else
-   __platform_wait_t __cur = 0;
-   while (__cur <= __version)
- {
__waiters::__lock_t __l(_M_mtx);
auto __e = __gthread_cond_wait(&_M_cv, 
__l.mutex()->native_handle());
if (__e)
  std::terminate();
-   __platform_wait_t __last = __cur;
+#endif
__atomic_load(&_M_ver, &__cur, __ATOMIC_ACQUIRE);
-   if (__cur < __last)
- break; // break the loop if version overflows
  }
-#endif
   }
 
   __platform_wait_t
-- 
2.26.2



[PATCH] Remove binary_semaphore implementation from stop_token

2020-06-06 Thread Thomas Rodgers
* include/std/stop_token: Remove local binary_semaphore implementation.
  (_Stop_state_t::_M_do_try_lock): Use __thread_yield() from
  bits/atomic_wait.h.
---
 libstdc++-v3/include/std/stop_token | 40 ++---
 1 file changed, 2 insertions(+), 38 deletions(-)

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



[PATCH] Add C++2a synchronization support

2020-06-06 Thread Thomas Rodgers
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.
---
 libstdc++-v3/include/Makefile.am  |   5 +
 libstdc++-v3/include/Makefile.in  |   5 +
 libstdc++-v3/include/bits/atomic_base.h   | 161 +-
 libstdc++-v3/include/bits/atomic_timed_wait.h | 282 +
 libstdc++-v3/include/bits/atomic_wait.h   | 291 ++
 libstdc++-v3/include/bits/semaphore_base.h| 272 
 libstdc++-v3/include/std/atomic   |  61 
 libstdc++-v3/include/std/latch|  90 ++
 libstdc++-v3/include/std/semaphore|  86 ++
 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.h   |  88 ++
 .../atomic/wait_notify/integrals.cc   |  56 
 .../29_atomics/atomic/wait_notify/pointers.cc |  59 
 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  |  28 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads/semaphore/try_acquire_for.cc   |  85 +
 .../30_threads/semaphore/try_acquire_futex.cc |  51 +++
 .../30_threads/semaphore/try_acquire_posix.cc | 169 ++
 .../30_threads/semaphore/try_acquire_until.cc |  94 ++
 27 files changed, 2291 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/include/bits/atomic_timed_wait.h
 create mode 100644 libstdc++-v3/include/bits/atomic_wait.h
 create mode 100644 libstdc++-v3/include/bits/semaphore_base.h
 create mode 100644 libstdc++-v3/include/std/latch
 create mode 100644 libstdc++-v3/include/std/semaphore
 create mode 100644 

[PATCH] Add support for C++20 barriers

2020-06-06 Thread Thomas Rodgers
* include/Makefile.am (std_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/std/barrier: New file.
* 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.
---
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   1 +
 libstdc++-v3/include/bits/atomic_base.h   |  15 +-
 libstdc++-v3/include/std/barrier  | 230 ++
 libstdc++-v3/include/std/version  |   5 +-
 .../testsuite/30_threads/barrier/1.cc |  27 ++
 .../testsuite/30_threads/barrier/2.cc |  27 ++
 .../testsuite/30_threads/barrier/arrive.cc|  34 +++
 .../30_threads/barrier/arrive_and_drop.cc |  32 +++
 .../30_threads/barrier/arrive_and_wait.cc |  33 +++
 .../30_threads/barrier/completion.cc  |  39 +++
 .../testsuite/30_threads/barrier/max.cc   |  26 ++
 12 files changed, 465 insertions(+), 5 deletions(-)
 create mode 100644 libstdc++-v3/include/std/barrier
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/1.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/2.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/arrive.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/arrive_and_drop.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/arrive_and_wait.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/completion.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/barrier/max.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index b3ac1a3365f..e2cded53779 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -30,6 +30,7 @@ std_headers = \
${std_srcdir}/any \
${std_srcdir}/array \
${std_srcdir}/atomic \
+   ${std_srcdir}/barrier \
${std_srcdir}/bit \
${std_srcdir}/bitset \
${std_srcdir}/charconv \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index e73ff8b3e64..8e1163e8e18 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -375,6 +375,7 @@ std_headers = \
${std_srcdir}/any \
${std_srcdir}/array \
${std_srcdir}/atomic \
+   ${std_srcdir}/barrier \
${std_srcdir}/bit \
${std_srcdir}/bitset \
${std_srcdir}/charconv \
diff --git a/libstdc++-v3/include/bits/atomic_base.h 
b/libstdc++-v3/include/bits/atomic_base.h
index 68d9e7e3756..271656c6b37 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -566,13 +566,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   }
 
 #if __cplusplus > 201703L
+  template
+   _GLIBCXX_ALWAYS_INLINE void
+   _M_wait(__int_type __old, _Pred&& __pred,
+   memory_order __m) const noexcept
+   {
+ std::__atomic_wait(&_M_i, __old,
+std::forward<_Pred&&>(__pred));
+   }
+
   _GLIBCXX_ALWAYS_INLINE void
   wait(__int_type __old,
  memory_order __m = memory_order_seq_cst) const noexcept
   {
-   std::__atomic_wait(&_M_i, __old,
-  [__m, this, __old]()
-  { return this->load(__m) != __old; });
+   _M_wait(__old, [__m, this, __old]()
+   { return this->load(__m) != __old; },
+   __m);
   }
 
   // TODO add const volatile overload
diff --git a/libstdc++-v3/include/std/barrier b/libstdc++-v3/include/std/barrier
new file mode 100644
index 000..870db7db2ac
--- /dev/null
+++ b/libstdc++-v3/include/std/barrier
@@ -0,0 +1,230 @@
+//  -*- C++ -*-
+// This implementation is based on libcxx/include/barrier
+//===-- barrier.h --===//
+//
+// 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
+//
+//===---===//
+
+#ifndef _GLIBCXX_BARRIER
+#define _GLIBCXX_BARRIER 1
+
+#pragma GCC system_header
+
+#if __cplusplus > 201703L
+#define __cpp_lib_barrier 201907L
+
+#include 
+
+#if defined(_GLIBCXX_HAS_GTHREADS)
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  struct __empty_completion
+  {
+_GLIBCXX_ALWAYS_INLINE void
+operator()() noexcept
+{ }
+  };
+
+/*
+
+The default implementation of __barrier_base is a classic 

[PATCH] Add C++2a synchronization support

2020-06-05 Thread Thomas Rodgers
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.
---
 libstdc++-v3/include/Makefile.am  |   5 +
 libstdc++-v3/include/Makefile.in  |   5 +
 libstdc++-v3/include/bits/atomic_base.h   | 161 +-
 libstdc++-v3/include/bits/atomic_timed_wait.h | 282 +
 libstdc++-v3/include/bits/atomic_wait.h   | 291 ++
 libstdc++-v3/include/bits/semaphore_base.h| 272 
 libstdc++-v3/include/std/atomic   |  61 
 libstdc++-v3/include/std/latch|  90 ++
 libstdc++-v3/include/std/semaphore|  86 ++
 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.h   |  88 ++
 .../atomic/wait_notify/integrals.cc   |  56 
 .../29_atomics/atomic/wait_notify/pointers.cc |  59 
 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  |  28 ++
 .../30_threads/semaphore/try_acquire.cc   |  55 
 .../30_threads/semaphore/try_acquire_for.cc   |  85 +
 .../30_threads/semaphore/try_acquire_futex.cc |  51 +++
 .../30_threads/semaphore/try_acquire_posix.cc | 169 ++
 .../30_threads/semaphore/try_acquire_until.cc |  94 ++
 27 files changed, 2291 insertions(+), 1 deletion(-)
 create mode 100644 libstdc++-v3/include/bits/atomic_timed_wait.h
 create mode 100644 libstdc++-v3/include/bits/atomic_wait.h
 create mode 100644 libstdc++-v3/include/bits/semaphore_base.h
 create mode 100644 libstdc++-v3/include/std/latch
 create mode 100644 libstdc++-v3/include/std/semaphore
 create mode 100644 

Re: [PATCH] Adjust wait logic to limit spurious evalution of wait predicate.

2020-05-24 Thread Thomas Rodgers
And this time, with patch.



wake_up_fix.patch
Description: Binary data


> On May 24, 2020, at 3:06 PM, Thomas Rodgers  wrote:
> 
>   * include/bits/atomic_wait.h (__waiters::_M_do_wait): adjust wakeup 
> logic.



[PATCH] Remove binary_semaphore implementation from stop_token

2020-05-24 Thread Thomas Rodgers
 * include/std/stop_token: Remove local binary_semaphore implementation.
   (_Stop_state_t::_M_do_try_lock): Use __thread_yield() from
   bits/atomic_wait.h.



0001-Remove-binary_semaphore-implementation-from-stop_tok.patch
Description: Binary data


[PATCH] Adjust wait logic to limit spurious evalution of wait predicate.

2020-05-24 Thread Thomas Rodgers
* include/bits/atomic_wait.h (__waiters::_M_do_wait): adjust wakeup 
logic.


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

2020-05-24 Thread Thomas Rodgers



> On May 24, 2020, at 11:11 AM, Jonathan Wakely  wrote:
> 
> On Sun, 24 May 2020 at 18:55, Florian Weimer wrote:
>> 
>> * Thomas Rodgers:
>> 
>>> +  static __gthread_t
>>> +  _S_get_tid() noexcept
>>> +  {
>>> +#ifdef __GLIBC__
>>> + // For the GNU C library pthread_self() is usable without linking to
>>> + // libpthread.so but returns 0, so we cannot use it in single-threaded
>>> + // programs, because this_thread::get_id() != thread::id{} must be 
>>> true.
>>> + // We know that pthread_t is an integral type in the GNU C library.
>>> + if (!__gthread_active_p())
>>> +   return 1;
>>> +#endif
>>> + return __gthread_self();
>>> +  }
>> 
>> This comment seems outdated or incomplete.  pthread_self returns a
>> proper pointer since glibc 2.27, I believe.
> 
> The comment is copied from the  header, and dates from 2015.

Yes, this comes from  to avoid pulling in all of  to just get a 
hash from the current thread identity. I’m now using it in two places, is this 
worth splitting out somewhere?

> 
>> I'm also not sure how the difference is observable for the libstdc++
>> implementation.  Late loading of libpthread isn't quite supported.
> 
> It's nothing to do with late loading. A single threaded program that
> doesn't create any threads and doesn't link to libpthread can still
> expect std::this_thread::get_id() != std::thread::id() to be true in
> the main (and only) thread. If pthread_self() returns 0, and
> thread::id() default constructs with a value of 0, then we can't
> distinguish "the main thread" from "not a thread".
> 
> But I do see a non-zero value from glibc now, which is great. I'll add
> it to my TODO list to remove that workaround from .



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

2020-05-24 Thread Thomas Rodgers
This time with 100% more patch…



0001-Add-support-for-C-20-barriers_f.patch
Description: Binary data


> On May 23, 2020, at 3:58 PM, Thomas Rodgers  wrote:
> 
> This patch requires the patch for atomic::wait/notify to be applied first.
> 
> This implementation is based on the libc++ implementation, but excludes the 
> alternative “central barrier” implementation for now as there is no standard 
> way to switch between the two.
> 
>* include/Makefile.am (std_headers): Add new header.
>* include/Makefile.in: Regenerate.
>* include/std/barrier: New file.
>* 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.
> 



[PATCH] Add support for C++20 barriers

2020-05-23 Thread Thomas Rodgers
This patch requires the patch for atomic::wait/notify to be applied first.

This implementation is based on the libc++ implementation, but excludes the 
alternative “central barrier” implementation for now as there is no standard 
way to switch between the two.

* include/Makefile.am (std_headers): Add new header.
* include/Makefile.in: Regenerate.
* include/std/barrier: New file.
* 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.



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_

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 f

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_N

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 __cplusplu

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

2020-03-15 Thread Thomas Rodgers
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 

[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 __cpluspl

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

2020-02-24 Thread Thomas Rodgers
Hopefully less borked than the previous one, adds futex support.

- Original Message -
From: "Thomas Rodgers" 
To: gcc-patches@gcc.gnu.org, libstd...@gcc.gnu.org
Sent: Wednesday, February 19, 2020 7:18:36 PM
Subject: Re: [PATCH] Add c++2a binary_semaphore

Should address the previous issues, adds backoff logic.

* include/std/semaphore: New file.
* include/std/version (__cpp_lib_semaphore): Add feature test macro.
* include/Makefile.am (std_headers): add semaphore.
* include/Makefile.in: Regenerate.
* testsuite/30_threads/semaphore/1.cc: New test.
* testsuite/30_threads/semaphore/2.cc: New test.
* testsuite/30_threads/semaphore/binary_semaphore.cc: New test.
* testsuite/30_threads/semaphore/try_acquire.cc: New test.
* testsuite/30_threads/semaphore/try_acquire_for.cc: New test.
* testsuite/30_threads/semaphore/try_acquire_until.cc: New test.

- Original Message -
From: "Jonathan Wakely" 
To: "Thomas Rodgers" 
Cc: gcc-patches@gcc.gnu.org, libstd...@gcc.gnu.org
Sent: Tuesday, February 18, 2020 6:25:41 AM
Subject: Re: [PATCH] Add c++2a binary_semaphore

On 18/02/20 01:46 -0500, Thomas Rodgers wrote:
>This patch adds the c++2a semaphore header and binary_semaphore type. The 
>implementation is not complete, this patch is just to solicit initial feedback.

Here is some initial feedback on comments and whitespace :-)

>diff --git a/libstdc++-v3/include/Makefile.am 
>b/libstdc++-v3/include/Makefile.am
>index 89835759069..2dbb7d3a6b1 100644
>--- a/libstdc++-v3/include/Makefile.am
>+++ b/libstdc++-v3/include/Makefile.am
>@@ -69,6 +69,7 @@ std_headers = \
>   ${std_srcdir}/ratio \
>   ${std_srcdir}/regex \
>   ${std_srcdir}/scoped_allocator \
>+  ${std_srcdir}/semaphore \

Indentation is borked.

>   ${std_srcdir}/set \
>   ${std_srcdir}/shared_mutex \
>   ${std_srcdir}/span \
>diff --git a/libstdc++-v3/include/std/semaphore 
>b/libstdc++-v3/include/std/semaphore
>new file mode 100644
>index 000..e3e88a50eec
>--- /dev/null
>+++ b/libstdc++-v3/include/std/semaphore
>@@ -0,0 +1,131 @@
>+//  -*- C++ -*-

Wrong header name in comment.

>+
>+// 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.
>+
>+// 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
>+// <http://www.gnu.org/licenses/>.
>+
>+/** @file include/stop_token

Wrong name again.

>+ *  This is a Standard C++ Library header.
>+ */
>+
>+#ifndef _GLIBCXX_SEMAPHORE
>+#define _GLIBCXX_SEMAPHORE
>+
>+#if __cplusplus > 201703L
>+#define __cpp_lib_semaphore 201907L

We shouldn't define this until the file is complete, i.e. when it
provides binary_semaphore and counting_semaphore.

>+
>+#include 

Is this header needed? ptrdiff_t and size_t are both defined in
 which every header already includes.

>+#include 
>+#include 
>+
>+namespace std _GLIBCXX_VISIBILITY(default)
>+{
>+_GLIBCXX_BEGIN_NAMESPACE_VERSION
>+
>+  // TODO: replace this with a real implementation of std::binary_semaphore
>+  struct binary_semaphore
>+{

Indentation is borked here too.

>+  explicit binary_semaphore(int __d) : _M_counter(__d > 0) { }
>+
>+  static constexpr std::ptrdiff_t
>+  max() noexcept
>+  {
>+   return 1;
>+  }
>+
>+  void release() { _M_counter.fetch_add(1, memory_order::release); }
>+
>+  void acquire()
>+  {
>+   while (!_M_try_acquire())
>+ {
>+  _S_yield();
>+ }
>+  }
>+
>+  bool
>+  try_acquire() noexcept
>+  {
>+   return _M_try_acquire(1u);
>+  }
>+
>+  template
>+  bool try_acquire_for(const std::chrono::duration<_Rep, _Period>& __rel_time)
>+  {
>+   auto __abst = std::chrono::steady_clock::now() + __rel_time;
>+   return try_acquire_until(__abst);
>+  }
>+
>+  template
>+  bool try_acquire_until(const 

[PATCH] Add c++2a binary_semaphore

2020-02-17 Thread Thomas Rodgers
This patch adds the c++2a semaphore header and binary_semaphore type. The 
implementation is not complete, this patch is just to solicit initial feedback.

* include/std/semaphore: New file.
* include/std/version (__cpp_lib_semaphore): Add feature test macro.
* include/Makefile.am (std_headers): add semaphore.
* include/Makefile.in: Regenerate.
* testsuite/30_threads/semaphore/1.cc: New test.
* testsuite/30_threads/semaphore/2.cc: New test.
* testsuite/30_threads/semaphore/binary_semaphore.cc: New test.
* testsuite/30_threads/semaphore/try_acquire.cc: New test.
* testsuite/30_threads/semaphore/try_acquire_for.cc: New test.
* testsuite/30_threads/semaphore/try_acquire_until.cc: New test.

From 8ce4252605361ed33b389a91fb7e3aeec529d9ac Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Mon, 17 Feb 2020 19:58:57 -0800
Subject: [PATCH] Add c++2a binary_semaphore

* include/std/semaphore: New file.
* include/std/version (__cpp_lib_semaphore): Add feature test macro.
* include/Makefile.am (std_headers): add semaphore.
* include/Makefile.in: Regenerate.
* testsuite/30_threads/semaphore/1.cc: New test.
* testsuite/30_threads/semaphore/2.cc: New test.
* testsuite/30_threads/semaphore/binary_semaphore.cc: New test.
* testsuite/30_threads/semaphore/try_acquire.cc: New test.
* testsuite/30_threads/semaphore/try_acquire_for.cc: New test.
* testsuite/30_threads/semaphore/try_acquire_until.cc: New test.
---
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   1 +
 libstdc++-v3/include/std/semaphore| 131 ++
 libstdc++-v3/include/std/version  |   1 +
 .../testsuite/30_threads/semaphore/1.cc   |  27 
 .../testsuite/30_threads/semaphore/2.cc   |  27 
 .../30_threads/semaphore/binary_semaphore.cc  |  47 +++
 .../30_threads/semaphore/try_acquire.cc   |  36 +
 .../30_threads/semaphore/try_acquire_for.cc   |  72 ++
 .../30_threads/semaphore/try_acquire_until.cc |  74 ++
 10 files changed, 417 insertions(+)
 create mode 100644 libstdc++-v3/include/std/semaphore
 create mode 100644 libstdc++-v3/testsuite/30_threads/semaphore/1.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/semaphore/2.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/semaphore/binary_semaphore.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/semaphore/try_acquire.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_for.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 89835759069..2dbb7d3a6b1 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -69,6 +69,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 \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index 123d24bb1c6..8f2780c86ce 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -414,6 +414,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 \
diff --git a/libstdc++-v3/include/std/semaphore b/libstdc++-v3/include/std/semaphore
new file mode 100644
index 000..e3e88a50eec
--- /dev/null
+++ b/libstdc++-v3/include/std/semaphore
@@ -0,0 +1,131 @@
+//  -*- C++ -*-
+
+// 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.
+
+// 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
+// <http://www.gnu.org/licenses/>.
+
+/** @file include/stop_token
+ *  This is a Standard C++ Library header.
+ */
+
+#ifndef _GLIBCXX_SEMAPHORE
+#define _GLIBCXX_SEMAPHORE
+
+#if __cplusplus >

Re: [PATCH] libstdc++: Fix conformance issues in (PR92895)

2020-01-29 Thread Thomas Rodgers
Looks good to me, ok for trunk.

Thanks.

Jonathan Wakely writes:

> Fix synchronization issues in . Replace shared_ptr with
> _Stop_state_ref and a reference count embedded in the shared state.
> Replace std::mutex with spinlock using one bit of a std::atomic<> that
> also tracks whether a stop request has been made and how many
> stop_source objects share ownership of the state.
>
> The synchronization with callbacks being destroyed is based on the
> implementation by Lewis Baker and Nico Josuttis. It allows the
> callback being destroyed to detect whether it's currently running, and
> if so whether on the current thread or a different one.
>
> Tom, please take a look and give a review. As discussed, the
> binary_semaphore is temporary, until we have the real thing.



[PATCH] Suppress deprecation warnings in tbb effective target check

2020-01-23 Thread Thomas Rodgers
From cfd3c2e2a49dd3e29b42baa0f22feffd4b346231 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Thu, 23 Jan 2020 21:54:44 -0800
Subject: [PATCH] Suppress deprecation warnings in tbb effective target check

TBB 2020 added deprecation warnings which produced output not expected by
check_effective_target_tbb-backend
---
 libstdc++-v3/testsuite/lib/libstdc++.exp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index 94f3fdb2bc8..f451719bdd4 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -1597,7 +1597,8 @@ proc check_effective_target_tbb-backend { } {
 puts $f "}"
 close $f
 
-set lines [v3_target_compile $src $exe executable "additional_flags=-std=c++17 additional_flags=-ltbb"]
+set lines [v3_target_compile $src $exe executable "additional_flags=-std=c++17 additional_flags=-ltbb
+   additional_flags=-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1"]
 file delete $src
 
 if [string match "" $lines] {
-- 
2.21.1



Re: [PATCH] Rename condition_variable_any::wait_on_* methods

2020-01-07 Thread Thomas Rodgers


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

Jonathan Wakely writes:

> On 10/12/19 22:38 -0800, Thomas Rodgers wrote:
>>User-agent: mu4e 1.3.4; emacs 26.2
>>  * include/std/condition_variable
>>  (condition_variable_any::wait_on(_Lock&, stop_token, _Predicate): Rename
>>  to match current draft standard.
>>  (condition_variable_any::wait_on_until(_Lock&, stop_token,
>>  const chrono::time_point<>&, _Predicate): Likewise.
>>  (condition_variable_any::wait_on_for(_Lock&, stop_token,
>>  const chrono::duration<>&, _Predicate(: Likewise.
>
> The closing paren here is an opening one. OK for trunk with that
> fixed.
>
> Optional tweaks ...
>
> Since the names wait_on, wait_on_until and wait_on_for are
> unambiguous, you could just list them without parameters i.e.
>
>   * include/std/condition_variable (condition_variable_any::wait_on)
>(condition_variable_any::wait_on_until)
>(condition_variable_any::wait_on_for): Rename to match current
>draft standard.
>
>>  * testsuite/30_threads/condition_variable_any/stop_token/wait_on.cc 
>> (main):
>
> We don't generally both to say which functions were modified in tests,
> so the (main) isn't needed here, but is harmless.
>
>>  Adjust tests to account for renamed methods.



[PATCH] Rename condition_variable_any::wait_on_* methods

2019-12-10 Thread Thomas Rodgers
User-agent: mu4e 1.3.4; emacs 26.2
* include/std/condition_variable
(condition_variable_any::wait_on(_Lock&, stop_token, _Predicate): Rename
to match current draft standard.
(condition_variable_any::wait_on_until(_Lock&, stop_token,
const chrono::time_point<>&, _Predicate): Likewise.
(condition_variable_any::wait_on_for(_Lock&, stop_token,
const chrono::duration<>&, _Predicate(: Likewise.
* testsuite/30_threads/condition_variable_any/stop_token/wait_on.cc 
(main):
Adjust tests to account for renamed methods.
---
 libstdc++-v3/include/std/condition_variable   | 30 +--
 .../stop_token/wait_on.cc | 22 +++---
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/libstdc++-v3/include/std/condition_variable 
b/libstdc++-v3/include/std/condition_variable
index 8887cee29fa..3346a28e5dd 100644
--- a/libstdc++-v3/include/std/condition_variable
+++ b/libstdc++-v3/include/std/condition_variable
@@ -369,9 +369,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #ifdef __cpp_lib_jthread
 template 
-bool wait_on(_Lock& __lock,
- stop_token __stoken,
- _Predicate __p)
+bool wait(_Lock& __lock,
+  stop_token __stoken,
+  _Predicate __p)
 {
   if (__stoken.stop_requested())
 {
@@ -397,10 +397,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 }
 
 template 
-bool wait_on_until(_Lock& __lock,
-   stop_token __stoken,
-   const chrono::time_point<_Clock, _Duration>& __abs_time,
-   _Predicate __p)
+bool wait_until(_Lock& __lock,
+stop_token __stoken,
+const chrono::time_point<_Clock, _Duration>& __abs_time,
+_Predicate __p)
 {
   if (__stoken.stop_requested())
 {
@@ -432,16 +432,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 }
 
 template 
-bool wait_on_for(_Lock& __lock,
- stop_token __stoken,
- const chrono::duration<_Rep, _Period>& __rel_time,
- _Predicate __p)
+bool wait_for(_Lock& __lock,
+  stop_token __stoken,
+  const chrono::duration<_Rep, _Period>& __rel_time,
+  _Predicate __p)
 {
   auto __abst = std::chrono::steady_clock::now() + __rel_time;
-  return wait_on_until(__lock,
-   std::move(__stoken),
-   __abst,
-   std::move(__p));
+  return wait_until(__lock,
+std::move(__stoken),
+__abst,
+std::move(__p));
 }
 #endif
   };
diff --git 
a/libstdc++-v3/testsuite/30_threads/condition_variable_any/stop_token/wait_on.cc
 
b/libstdc++-v3/testsuite/30_threads/condition_variable_any/stop_token/wait_on.cc
index 212fc949b3f..636425b43fc 100644
--- 
a/libstdc++-v3/testsuite/30_threads/condition_variable_any/stop_token/wait_on.cc
+++ 
b/libstdc++-v3/testsuite/30_threads/condition_variable_any/stop_token/wait_on.cc
@@ -28,7 +28,7 @@
 
 using namespace::std::literals;
 
-void test_wait_on_stop()
+void test_wait_stop()
 {
   bool ready = false;
   std::mutex mtx;
@@ -40,7 +40,7 @@ void test_wait_on_stop()
   std::thread t([, , , tok]
 {
   std::unique_lock lck(mtx);
-  auto res = cv.wait_on(lck, tok, [] { return ready; });
+  auto res = cv.wait(lck, tok, [] { return ready; });
   if (!res)
 {
   VERIFY(tok.stop_requested());
@@ -54,7 +54,7 @@ void test_wait_on_stop()
   VERIFY(src.stop_requested());
 }
 
-void test_wait_on_until(bool ck = true)
+void test_wait_until(bool ck = true)
 {
   bool ready = false;
   std::mutex mtx;
@@ -67,7 +67,7 @@ void test_wait_on_until(bool ck = true)
   std::thread t([ck, , , , abst, tok]
 {
   std::unique_lock lck(mtx);
-  auto res = cv.wait_on_until(lck, tok, abst, [] { 
return ready; });
+  auto res = cv.wait_until(lck, tok, abst, [] { return 
ready; });
   if (!res && ck)
 {
   VERIFY(tok.stop_requested());
@@ -90,7 +90,7 @@ void test_wait_on_until(bool ck = true)
 }
 }
 
-void test_wait_on_for(bool ck = true)
+void test_wait_for(bool ck = true)
 {
   bool ready = false;
   std::mutex mtx;
@@ -102,7 +102,7 @@ void test_wait_on_for(bool ck = true)
   std::thread t([ck, , , , tok]
 {
   std::unique_lock lck(mtx);
-  auto res = cv.wait_on_for(lck, tok, 1.0s, [] { return 
ready; });
+  auto res = cv.wait_for(lck, tok, 1.0s, [] { return 
ready; });
   if (!res && ck)
 {
   VERIFY(tok.stop_requested());
@@ -127,10 +127,10 @@ void 

Re: [PATCH] Restore enable_if lost during original import of pstl

2019-12-10 Thread Thomas Rodgers


Tested x86_64-pc-linux-gnu, committed to trunk, backported to
gcc-9-branch.

Jonathan Wakely writes:

> On 18/11/19 20:54 -0800, Thomas Rodgers wrote:
>>
>>  * include/pstl/glue_numeric_defs.h: Restore enable_if lost during 
>> original
>>  import of pstl.
>>  * include/pstl/glue_numeric_impl.h: Likewise.
>
> OK for trunk and gcc-9-branch, thanks.



[PATCH] Restore enable_if lost during original import of pstl

2019-11-18 Thread Thomas Rodgers


* include/pstl/glue_numeric_defs.h: Restore enable_if lost during 
original
import of pstl.
* include/pstl/glue_numeric_impl.h: Likewise.
---
 libstdc++-v3/include/pstl/glue_numeric_defs.h | 2 +-
 libstdc++-v3/include/pstl/glue_numeric_impl.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/pstl/glue_numeric_defs.h 
b/libstdc++-v3/include/pstl/glue_numeric_defs.h
index cc5a94e801a..78df1703079 100644
--- a/libstdc++-v3/include/pstl/glue_numeric_defs.h
+++ b/libstdc++-v3/include/pstl/glue_numeric_defs.h
@@ -55,7 +55,7 @@ exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 
__first, _ForwardIte
_ForwardIterator2 __result, _Tp __init);
 
 template 
-_ForwardIterator2
+__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, 
_ForwardIterator2>
 exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, 
_ForwardIterator1 __last,
_ForwardIterator2 __result, _Tp __init, _BinaryOperation 
__binary_op);
 
diff --git a/libstdc++-v3/include/pstl/glue_numeric_impl.h 
b/libstdc++-v3/include/pstl/glue_numeric_impl.h
index b1786fd387e..d5acbac5561 100644
--- a/libstdc++-v3/include/pstl/glue_numeric_impl.h
+++ b/libstdc++-v3/include/pstl/glue_numeric_impl.h
@@ -100,7 +100,7 @@ exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 
__first, _ForwardIte
 }
 
 template 
-_ForwardIterator2
+__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, 
_ForwardIterator2>
 exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, 
_ForwardIterator1 __last,
_ForwardIterator2 __result, _Tp __init, _BinaryOperation 
__binary_op)
 {
-- 
2.21.0



Re: [PATCH] Add support for C++2a stop_token

2019-11-14 Thread Thomas Rodgers
Tested x86_64-pc-linux-gnu, committed to trunk.

Jonathan Wakely writes:

> On 13/11/19 17:59 -0800, Thomas Rodgers wrote:
>>+/** @file include/stop_token
>>+ *  This is a Standard C++ Library header.
>>+ */
>>+
>>+#ifndef _GLIBCXX_STOP_TOKEN
>>+#define _GLIBCXX_STOP_TOKEN
>>+
>>+#if __cplusplus >= 201703L
>
> This should be > not >=
>
> OK for trunk with that change.



Re: [PATCH] Add support for C++2a stop_token

2019-11-13 Thread Thomas Rodgers

The attached patch should be a complete implementation of C++20
stop_token, jthread, and changes to condition_variable_any which also
addresses the comments on the previous patch.
From 2cdaa367ed919b24f3bbb84d6f7391a350dce77b Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Wed, 13 Nov 2019 17:51:11 -0800
Subject: [PATCH] Support for jthread and stop_token

	* include/Makefile.am: Add  header.
  * include/Makefile.in: Regenerate.
	* include/std/condition_variable: Add overloads for stop_token support
	to condition_variable_any.
	* include/std/stop_token: New file.
	* include/std/thread: Add jthread type.
	* include/std/version (__cpp_lib_jthread): New value.
	* testsuite/30_threads/condition_variable_any/stop_token/1.cc: New test.
	* testsuite/30_threads/condition_variable_any/stop_token/2.cc: New test.
	* testsuite/30_threads/condition_variable_any/stop_token/wait_on.cc: New test.
	* testsuite/30_threads/jthread/1.cc: New test.
	* testsuite/30_threads/jthread/2.cc: New test.
	* testsuite/30_threads/jthread/jthread.cc: New test.
	* testsuite/30_threads/stop_token/1.cc: New test.
	* testsuite/30_threads/stop_token/2.cc: New test.
	* testsuite/30_threads/stop_token/stop_token.cc: New test.
---
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/std/condition_variable   |  84 
 libstdc++-v3/include/std/stop_token   | 370 ++
 libstdc++-v3/include/std/thread   | 125 ++
 libstdc++-v3/include/std/version  |   1 +
 .../condition_variable_any/stop_token/1.cc|  27 ++
 .../condition_variable_any/stop_token/2.cc|  27 ++
 .../stop_token/wait_on.cc | 136 +++
 .../testsuite/30_threads/jthread/1.cc |  27 ++
 .../testsuite/30_threads/jthread/2.cc |  27 ++
 .../testsuite/30_threads/jthread/jthread.cc   | 198 ++
 .../testsuite/30_threads/stop_token/1.cc  |  27 ++
 .../testsuite/30_threads/stop_token/2.cc  |  27 ++
 .../30_threads/stop_token/stop_token.cc   | 100 +
 14 files changed, 1177 insertions(+)
 create mode 100644 libstdc++-v3/include/std/stop_token
 create mode 100644 libstdc++-v3/testsuite/30_threads/condition_variable_any/stop_token/1.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/condition_variable_any/stop_token/2.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/condition_variable_any/stop_token/wait_on.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/jthread/1.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/jthread/2.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/jthread/jthread.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/stop_token/1.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/stop_token/2.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/stop_token/stop_token.cc

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 49fd41360bc..6300de9e96d 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -74,6 +74,7 @@ std_headers = \
 	${std_srcdir}/sstream \
 	${std_srcdir}/stack \
 	${std_srcdir}/stdexcept \
+	${std_srcdir}/stop_token \
 	${std_srcdir}/streambuf \
 	${std_srcdir}/string \
 	${std_srcdir}/string_view \
diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable
index cc96661e94c..8887cee29fa 100644
--- a/libstdc++-v3/include/std/condition_variable
+++ b/libstdc++-v3/include/std/condition_variable
@@ -36,6 +36,7 @@
 #else
 
 #include 
+
 #include 
 #include 
 #include 
@@ -45,6 +46,11 @@
 #include 
 #include 
 
+#if __cplusplus > 201703L
+#define __cpp_lib_jthread 201907L
+#include 
+#endif
+
 #if defined(_GLIBCXX_HAS_GTHREADS)
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -360,6 +366,84 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   wait_for(_Lock& __lock,
 	   const chrono::duration<_Rep, _Period>& __rtime, _Predicate __p)
   { return wait_until(__lock, __clock_t::now() + __rtime, std::move(__p)); }
+
+#ifdef __cpp_lib_jthread
+template 
+bool wait_on(_Lock& __lock,
+ stop_token __stoken,
+ _Predicate __p)
+{
+  if (__stoken.stop_requested())
+{
+  return __p();
+}
+ 
+  std::stop_callback __cb(__stoken, [this] { notify_all(); });
+  shared_ptr __mutex = _M_mutex;
+  while (!__p())
+{
+  unique_lock __my_lock(*__mutex);
+  if (__stoken.stop_requested())
+{
+  return false;
+}
+  // *__mutex must be unlocked before re-locking __lock so move
+  // ownership of *__mutex lock to an object with shorter lifetime.
+  _Unlock<_Lock> __unlock(__lock);
+  unique_lock __my_lock2(std::move(__my_lock));
+  _M_cond.wait(__my_lock2);
+}
+  return true;
+}
+
+template 
+bool wait_on_until(_Lock& __lock,
+   

Re: [PATCH] Add support for C++2a stop_token

2019-10-23 Thread Thomas Rodgers

Thomas Rodgers writes:

Let's try this again.From 23e1c9402cc15666d099fd61b58a0019181a9115 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Tue, 22 Oct 2019 17:53:00 -0700
Subject: [PATCH] Add support for C++2a stop_token

  * include/Makefile.am: Add  header.
  * include/Makefile.in: Regenerate.
	* include/std/stop_token: New file.
	* include/std/version (__cpp_lib_jthread): New value.
	* testsuite/30_threads/stop_token/1.cc: New test.
	* testsuite/30_threads/stop_token/2.cc: New test.
	* testsuite/30_threads/stop_token/stop_token.cc: New test.
---
 libstdc++-v3/ChangeLog|  10 +
 libstdc++-v3/include/Makefile.am  |   1 +
 libstdc++-v3/include/Makefile.in  |   1 +
 libstdc++-v3/include/std/stop_token   | 338 ++
 libstdc++-v3/include/std/version  |   1 +
 .../testsuite/30_threads/stop_token/1.cc  |  27 ++
 .../testsuite/30_threads/stop_token/2.cc  |  27 ++
 .../30_threads/stop_token/stop_token.cc   |  93 +
 8 files changed, 498 insertions(+)
 create mode 100644 libstdc++-v3/include/std/stop_token
 create mode 100644 libstdc++-v3/testsuite/30_threads/stop_token/1.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/stop_token/2.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/stop_token/stop_token.cc

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 2ea0fe4ec40..970c5c2a018 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,13 @@
+2019-10-22  Thomas Rodgers  
+
+	* include/Makefile.am: Add  header.
+* include/Makefile.in: Regenerate.
+	* include/std/stop_token: New file.
+	* include/std/version (__cpp_lib_jthread): New value.
+	* testsuite/30_threads/stop_token/1.cc: New test.
+	* testsuite/30_threads/stop_token/2.cc: New test.
+	* testsuite/30_threads/stop_token/stop_token.cc: New test.
+
 2019-09-05  Jonathan Wakely  
 
 	* doc/xml/manual/status_cxx2020.xml: Update status for P0122R7 and
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index b8b786d9260..fb6777366bd 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -72,6 +72,7 @@ std_headers = \
 	${std_srcdir}/sstream \
 	${std_srcdir}/stack \
 	${std_srcdir}/stdexcept \
+	${std_srcdir}/stop_token \
 	${std_srcdir}/streambuf \
 	${std_srcdir}/string \
 	${std_srcdir}/string_view \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index cd1e9df5482..9b4ab670315 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -416,6 +416,7 @@ std_headers = \
 	${std_srcdir}/sstream \
 	${std_srcdir}/stack \
 	${std_srcdir}/stdexcept \
+	${std_srcdir}/stop_token \
 	${std_srcdir}/streambuf \
 	${std_srcdir}/string \
 	${std_srcdir}/string_view \
diff --git a/libstdc++-v3/include/std/stop_token b/libstdc++-v3/include/std/stop_token
new file mode 100644
index 000..b3655b85eae
--- /dev/null
+++ b/libstdc++-v3/include/std/stop_token
@@ -0,0 +1,338 @@
+//  -*- C++ -*-
+
+// Copyright (C) 2008-2019 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.
+
+// 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
+// <http://www.gnu.org/licenses/>.
+
+/** @file include/stop_token
+ *  This is a Standard C++ Library header.
+ */
+
+#ifndef _GLIBCXX_STOP_TOKEN
+#define _GLIBCXX_STOP_TOKEN
+
+#include 
+#include 
+#include 
+#include 
+
+#define __cpp_lib_jthread 201907L
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+  _GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  class stop_source;
+  template
+  class stop_callback;
+
+  struct nostopstate_t { explicit nostopstate_t() = default; };
+  inline constexpr nostopstate_t nostopstate();
+
+  class stop_token {
+  public:
+stop_token() noexcept = default;
+
+stop_token(const stop_token& __other) noexcept
+  : _M_state(__other._M_state)
+{ }
+
+stop_token(stop_token&& __other) noexcept
+  : _M_state(std::move(__other._M_state))
+{ }
+
+~stop_token() = default;
+
+stop_token&
+oper

[PATCH] Add C++20 jthread type to (2nd attempt)

2019-10-23 Thread Thomas Rodgers
From 56b78956a003b91e538cd5c680d614fdaee9c9eb Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Wed, 23 Oct 2019 12:32:31 -0700
Subject: [PATCH] Add C++20 jthread type to 

---
 libstdc++-v3/ChangeLog|   8 +
 libstdc++-v3/include/std/stop_token   |  14 ++
 libstdc++-v3/include/std/thread   | 125 +++
 .../testsuite/30_threads/jthread/1.cc |  27 +++
 .../testsuite/30_threads/jthread/2.cc |  27 +++
 .../testsuite/30_threads/jthread/jthread.cc   | 198 ++
 6 files changed, 399 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/30_threads/jthread/1.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/jthread/2.cc
 create mode 100644 libstdc++-v3/testsuite/30_threads/jthread/jthread.cc

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 970c5c2a018..523620da1c3 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,11 @@
+2019-10-23  Thomas Rodgers  
+
+	* include/std/stop_token (stop_token): Add operator==(), operator!=().
+	* include/std/thread: Add jthread type.
+	* testsuite/30_threads/jthread/1.cc: New test.
+	* testsuite/30_threads/jthread/2.cc: New test.
+	* testsuite/30_threads/jthread/jthread.cc: New test.
+
 2019-10-22  Thomas Rodgers  
 
 	* include/Makefile.am: Add  header.
diff --git a/libstdc++-v3/include/std/stop_token b/libstdc++-v3/include/std/stop_token
index b3655b85eae..04b9521d24e 100644
--- a/libstdc++-v3/include/std/stop_token
+++ b/libstdc++-v3/include/std/stop_token
@@ -87,6 +87,20 @@ namespace std _GLIBCXX_VISIBILITY(default)
   return stop_possible() && _M_state->_M_stop_requested();
 }
 
+[[nodiscard]]
+friend bool
+operator==(const stop_token& __a, const stop_token& __b)
+{
+  return __a._M_state == __b._M_state;
+}
+
+[[nodiscard]]
+friend bool
+operator!=(const stop_token& __a, const stop_token& __b)
+{
+  return __a._M_state == __b._M_state;
+}
+
   private:
 friend stop_source;
 template
diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread
index 90b4be6cd16..93afa766d18 100644
--- a/libstdc++-v3/include/std/thread
+++ b/libstdc++-v3/include/std/thread
@@ -39,6 +39,13 @@
 #include 
 #include 
 #include 
+
+#if __cplusplus > 201703L
+#define __cpp_lib_jthread 201907L
+#include 
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -409,6 +416,124 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // @} group threads
 
+#ifdef __cpp_lib_jthread
+
+  class jthread
+  {
+  public:
+using id = std::thread::id;
+using native_handle_type = std::thread::native_handle_type;
+
+jthread() noexcept
+: _M_stop_source{ nostopstate_t{ } }
+{ }
+
+template, jthread>>>
+explicit
+jthread(_Callable&& __f, _Args&&... __args)
+  : _M_thread{[](stop_token __token, auto&& __cb, auto&&... __args)
+  {
+if constexpr(std::is_invocable_v<_Callable, stop_token, _Args...>)
+  {
+std::invoke(std::forward(__cb),
+std::move(__token),
+std::forward(__args)...);
+  }
+else
+  {
+std::invoke(std::forward(__cb),
+std::forward(__args)...);
+  }
+  },
+  _M_stop_source.get_token(),
+  std::forward<_Callable>(__f),
+  std::forward<_Args>(__args)...}
+{ }
+
+jthread(const jthread&) = delete;
+jthread(jthread&&) noexcept = default;
+
+~jthread()
+{
+  if (joinable())
+{
+  request_stop();
+  join();
+}
+}
+
+jthread&
+operator=(const jthread&) = delete;
+
+jthread&
+operator=(jthread&&) noexcept = default;
+
+void
+swap(jthread& __other) noexcept
+{
+  std::swap(_M_stop_source, __other._M_stop_source);
+  std::swap(_M_thread, __other._M_thread);
+}
+
+bool
+joinable() const noexcept
+{
+  return _M_thread.joinable();
+}
+
+void
+join()
+{
+  _M_thread.join();
+}
+
+void
+detach()
+{
+  _M_thread.detach();
+}
+
+id
+get_id() const noexcept
+{
+  _M_thread.get_id();
+}
+
+native_handle_type
+native_handle()
+{
+  return _M_thread.native_handle();
+}
+
+static unsigned
+hardware_concurrency() noexcept
+{
+  return std::thread::hardware_concurrency();
+}
+
+[[nodiscard]] stop_source
+get_stop_source() noexcept
+{
+  return _M_stop_source;
+}
+
+[[nodiscard]] stop_token
+get_stop_token() const noexcept
+{
+  return _M_stop_source.get_token();
+}
+
+

[PATCH] Add C++20 jthread type to --text follows this line-<#part type="text/x-patch" filename="/home/remote/trodgers/src/oss/gcc/jt/0001-Add-C-20-jthread-type-to-thread.patch" disposition=at

2019-10-23 Thread Thomas Rodgers




[PATCH] Add support for C++2a stop_token

2019-10-22 Thread Thomas Rodgers


0001-Add-support-for-C-2a-stop_token.patch
Description: le patch


Re: [PATCH] Include netinet/in.h in include/experimental/internet

2019-09-30 Thread Thomas Rodgers
Looks good to me.

Andreas Tobler writes:

> Hi all,
>
> I'm going to commit the attached patch to trunk.
> It is preapproved by Jonathan. (via #irc)
>
> On FreeBSD the netinet/in.h header is not included by arpa/inet.h, so do the
> include if we have the _GLIBCXX_HAVE_NETINET_IN_H defined.
>
> This makes all the experimental/net/internet test cases pass here.
>
> Any comments?
>
> TIA,
> Andreas
>
> Commit one-liner:
>
> Include netinet/in.h in include/experimental/internet
>
> 2019-09-30  Andreas Tobler  
>
>   * include/experimental/internet: Include netinet/in.h if we have
>   _GLIBCXX_HAVE_NETINET_IN_H defined.
>
> Index: include/experimental/internet
> ===
> --- include/experimental/internet (revision 276342)
> +++ include/experimental/internet (working copy)
> @@ -51,6 +51,9 @@
>  #ifdef _GLIBCXX_HAVE_ARPA_INET_H
>  # include   // inet_ntop
>  #endif
> +#ifdef _GLIBCXX_HAVE_NETINET_IN_H
> +# include  // IPPROTO_IP
> +#endif
>  #ifdef _GLIBCXX_HAVE_NETINET_TCP_H
>  # include // TCP_NODELAY
>  #endif



Re: [PATCH] Enable use of #pragma omp simd reduction(inscan,...) even for GCC10+ in PSTL

2019-06-24 Thread Thomas Rodgers


Ok for trunk.

> Can you push it into upstream PSTL?

Yes.

Thanks,
Tom.

Jakub Jelinek writes:

> Hi!
>
> Now that GCC supports inclusive/exclusive scans (like ICC 19.0 so far in
> simd constructs only), we can enable it in PSTL as well.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, additionally tested
> with
> #include 
> #include 
>
> auto
> foo (std::vector , std::vector )
> {
>   return std::inclusive_scan(std::execution::unseq, ca.begin(), ca.end(), 
> co.begin());
> }
>
> auto
> bar (std::vector , std::vector )
> {
>   return std::exclusive_scan(std::execution::unseq, ca.begin(), ca.end(), 
> co.begin(), 0);
> }
> and verifying with -O2 -fopenmp-simd it is vectorized.  Ok for trunk?
> Can you push it into upstream PSTL?
>
> 2019-06-21  Jakub Jelinek  
>
>   * include/pstl/pstl_config.h (_PSTL_PRAGMA_SIMD_SCAN,
>   _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN, _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN):
>   Define to OpenMP 5.0 pragmas even for GCC 10.0+.
>   (_PSTL_UDS_PRESENT): Define to 1 for GCC 10.0+.
>
> --- libstdc++-v3/include/pstl/pstl_config.h.jj2019-06-10 
> 18:18:01.551191212 +0200
> +++ libstdc++-v3/include/pstl/pstl_config.h   2019-06-20 17:03:31.466367344 
> +0200
> @@ -70,7 +70,7 @@
>  #define _PSTL_PRAGMA_FORCEINLINE
>  #endif
>  
> -#if (__INTEL_COMPILER >= 1900)
> +#if (__INTEL_COMPILER >= 1900) || (_PSTL_GCC_VERSION >= 10)
>  #define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd 
> reduction(inscan, PRM))
>  #define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan 
> inclusive(PRM))
>  #define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan 
> exclusive(PRM))
> @@ -100,7 +100,11 @@
>  #define _PSTL_UDR_PRESENT 0
>  #endif
>  
> -#define _PSTL_UDS_PRESENT (__INTEL_COMPILER >= 1900 && 
> __INTEL_COMPILER_BUILD_DATE >= 20180626)
> +#if ((__INTEL_COMPILER >= 1900 && __INTEL_COMPILER_BUILD_DATE >= 20180626) 
> || _PSTL_GCC_VERSION >= 10)
> +#define _PSTL_UDS_PRESENT 1
> +#else
> +#define _PSTL_UDS_PRESENT 0
> +#endif
>  
>  #if _PSTL_EARLYEXIT_PRESENT
>  #define _PSTL_PRAGMA_SIMD_EARLYEXIT _PSTL_PRAGMA(omp simd early_exit)
>
>   Jakub



Re: [PATCH] Synchronize libstdc++ parallel algorithms with upstream project

2019-06-11 Thread Thomas Rodgers


Tested x86_64-linux, committed to trunk.

Jonathan Wakely writes:

> On 29/05/19 23:53 +0100, Jonathan Wakely wrote:
>>On 29/05/19 15:32 -0700, Thomas Rodgers wrote:
>>> * include/pstl/algorithm_fwd.h: Synchronize with
>>> upstream PSTL project.
>>> * include/pstl/algorithm_impl.h: Likewise.
>>> * include/pstl/execution_defs.h: Likewise.
>>> * include/pstl/execution_impl.h: Likewise.
>>> * include/pstl/glue_algorithm_impl.h: Likewise.
>>> * include/pstl/glue_execution_defs.h: Likewise.
>>> * include/pstl/numeric_fwd.h: Likewise.
>>> * include/pstl/numeric_impl.h: Likewise.
>>> * include/pstl/parallel_backend.h: Likewise.
>>> * include/pstl/pstl_config.h: Likewise.
>>> * include/pstl/unseq_backend_simd.h: Likewise.
>>> * include/pstl/parallel_backend_serial.h: New file.
>>> * include/Makefile.am (pstl_headers): Add
>>> parallel_backend_serial.h.
>>> * include/Makefile.in: Regenerate.
>>>
>>>
>>
>>A couple of non-uglified names crept in, "f" and "n":
>>
>>template >_ForwardIterator2, class _Function,
>>  class _IsVector>
>>_ForwardIterator2
>>-__pattern_walk2_n(_ExecutionPolicy&&, _ForwardIterator1 __first1, _Size __n, 
>>_ForwardIterator2 __first2, _Function __f,
>>+__pattern_walk2_n(_ExecutionPolicy&&, _ForwardIterator1 __first1, _Size n, 
>>_ForwardIterator2 __first2, _Function f,
>>  _IsVector is_vector, /*parallel=*/std::false_type) noexcept
>>{
>>-return __internal::__brick_walk2_n(__first1, __n, __first2, __f, 
>>is_vector);
>>+return __internal::__brick_walk2_n(__first1, n, __first2, f, is_vector);
>>}
>>
>>template >class _RandomAccessIterator2,
>>  class _Function, class _IsVector>
>>_RandomAccessIterator2
>>-__pattern_walk2_n(_ExecutionPolicy&& __exec, _RandomAccessIterator1 
>>__first1, _Size __n, _RandomAccessIterator2 __first2,
>>-  _Function __f, _IsVector __is_vector, 
>>/*parallel=*/std::true_type)
>>+__pattern_walk2_n(_ExecutionPolicy&& __exec, _RandomAccessIterator1 
>>__first1, _Size n, _RandomAccessIterator2 __first2,
>>+  _Function f, _IsVector is_vector, 
>>/*parallel=*/std::true_type)
>>{
>>
>>
>>"n" is actually a reserved name (it's a member function of the
>>chi_squared_distribution and the fisher_f_distribution) but for
>>consistency we should uglify it here. And "f" isn't a reserve name at
>>all.
>
> OK for trunk with the "n" and "f" fixes, the pre-existing stuff can be
> fixed later.
>
>
>>Also as mentioned on IRC< there are pre-existing uses of _T which
>>should be _Tp (because _T is a macro in some BSD system ehaders IIRC)
>>and there are also local variables called copy_range1 and copy_range2
>>which should be uglified.
>>
>>



Re: [PATCH] Rename header guards to be consistent with upstream project's conventions.

2019-06-11 Thread Thomas Rodgers
Tested x86_64-linux, committed to trunk.

Jonathan Wakely writes:

> On 29/05/19 15:30 -0700, Thomas Rodgers wrote:
>>
>>  * include/pstl/glue_memory_impl.h: Rename all macros of the form
>>  _PSTL_(.*)_H to _PSTL_\U\1_H.
>>  * include/pstl/numeric_impl.h: Likewise.
>>  * include/pstl/glue_memory_defs.h: Likewise.
>>  * include/pstl/execution_defs.h: Likewise.
>>  * include/pstl/utils.h: Likewise.
>>  * include/pstl/algorithm_fwd.h: Likewise.
>>  * include/pstl/unseq_backend_simd.h: Likewise.
>>  * include/pstl/glue_execution_defs.h: Likewise.
>>  * include/pstl/algorithm_impl.h: Likewise.
>>  * include/pstl/parallel_impl.h: Likewise.
>>  * include/pstl/memory_impl.h: Likewise.
>>  * include/pstl/glue_numeric_defs.h: Likewise.
>>  * include/pstl/parallel_backend_utils.h: Likewise.
>>  * include/pstl/glue_algorithm_defs.h: Likewise.
>>  * include/pstl/parallel_backend.h: Likewise.
>>  * include/pstl/glue_numeric_impl.h: Likewise.
>>  * include/pstl/parallel_backend_tbb.h: Likewise.
>>  * include/pstl/numeric_fwd.h: Likewise.
>>  * include/pstl/glue_algorithm_impl.h: Likewise.
>>  * include/pstl/execution_impl.h: Likewise.
>>  * include/pstl/pstl_config.h: Likewise.
>>  * testsuite/util/pstl/pstl_test_config.h: Likewise.
>
> OK for trunk, thanks.



Re: [PATCH] Clean up non-conforming names

2019-06-11 Thread Thomas Rodgers
Tested x86_64-linux, committed to trunk.

Thomas Rodgers writes:

> Jonathan Wakely writes:
>
>> On 31/05/19 17:15 -0700, Thomas Rodgers wrote:
>>>
>>>Revising previous version of this patch to pick another missed
>>>uglification.
>>
>> OK for trunk, thanks.
>>
>> I also see this one:
>>
>> include/pstl/parallel_backend_tbb.h:__buffer(std::size_t n) : 
>> _M_allocator(), _M_ptr(_M_allocator.allocate(n)), _M_buf_size(n) {}
>
> Ok, I'll clean that one up and commit along with these changes.



Re: [PATCH] Integrate non-TBB serial backend support

2019-06-11 Thread Thomas Rodgers


Tested x86_64-linux, committed to trunk.

Thomas Rodgers writes:

>   * include/bits/c++config: Adjust TBB detection logic to select serial
>   PSTL backend if no TBB present.
>   * testsuite/utils/pstl/test_utils.h: Remove check for
>   __PSTL_USE_PAR_POLICIES
> ---
>  libstdc++-v3/include/bits/c++config   |  8 ++--
>  libstdc++-v3/testsuite/util/pstl/test_utils.h | 40 +++
>  2 files changed, 19 insertions(+), 29 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/c++config 
> b/libstdc++-v3/include/bits/c++config
> index 4b8574bf433..746e35efbfc 100644
> --- a/libstdc++-v3/include/bits/c++config
> +++ b/libstdc++-v3/include/bits/c++config
> @@ -656,9 +656,7 @@ namespace std
>  
>  #if __cplusplus >= 201703L
>  // Preserved here so we have some idea which version of upstream we've 
> pulled in
> -// #define PSTL_VERSION 104
> -// #define PSTL_VERSION_MAJOR (PSTL_VERSION/100)
> -// #define PSTL_VERSION_MINOR (PSTL_VERSION - PSTL_VERSION_MAJOR * 100)
> +// #define PSTL_VERSION 9000
>  
>  // For now this defaults to being based on the presence of Thread Building 
> Blocks
>  # ifndef _GLIBCXX_USE_TBB_PAR_BACKEND
> @@ -666,7 +664,9 @@ namespace std
>  # endif
>  // This section will need some rework when a new (default) backend type is 
> added
>  # if _GLIBCXX_USE_TBB_PAR_BACKEND
> -#  define _PSTL_USE_PAR_POLICIES 1
> +#  define _PSTL_PAR_BACKEND_TBB
> +# else
> +#  define _PSTL_PAR_BACKEND_SERIAL
>  # endif
>  
>  # define _PSTL_ASSERT(_Condition) __glibcxx_assert(_Condition)
> diff --git a/libstdc++-v3/testsuite/util/pstl/test_utils.h 
> b/libstdc++-v3/testsuite/util/pstl/test_utils.h
> index 9d16fa566e2..6547d931c29 100644
> --- a/libstdc++-v3/testsuite/util/pstl/test_utils.h
> +++ b/libstdc++-v3/testsuite/util/pstl/test_utils.h
> @@ -10,14 +10,15 @@
>  // File contains common utilities that tests rely on
>  
>  // Do not #include , because if we do we will not detect 
> accidental dependencies.
> -#include 
> -#include 
> +#include 
> +#include 
> +#include 
>  #include 
> +#include 
>  #include 
> -#include 
> -#include 
>  #include 
> -#include 
> +#include 
> +#include 
>  
>  #include "pstl_test_config.h"
>  
> @@ -38,32 +39,30 @@ template 
>  class Sequence;
>  
>  // Handy macros for error reporting
> -#define EXPECT_TRUE(condition, message) TestUtils::expect(condition, 
> __FILE__, __LINE__, message)
> -#define EXPECT_FALSE(condition, message) TestUtils::expect(condition, 
> __FILE__, __LINE__, message)
> +#define EXPECT_TRUE(condition, message) ::TestUtils::expect(true, condition, 
> __FILE__, __LINE__, message)
> +#define EXPECT_FALSE(condition, message) ::TestUtils::expect(false, 
> condition, __FILE__, __LINE__, message)
>  
>  // Check that expected and actual are equal and have the same type.
> -#define EXPECT_EQ(expected, actual, message) 
> TestUtils::expect_equal(expected, actual, __FILE__, __LINE__, message)
> +#define EXPECT_EQ(expected, actual, message) 
> ::TestUtils::expect_equal(expected, actual, __FILE__, __LINE__, message)
>  
>  // Check that sequences started with expected and actual and have had size n 
> are equal and have the same type.
>  #define EXPECT_EQ_N(expected, actual, n, message)
>   \
> -TestUtils::expect_equal(expected, actual, n, __FILE__, __LINE__, message)
> +::TestUtils::expect_equal(expected, actual, n, __FILE__, __LINE__, 
> message)
>  
>  // Issue error message from outstr, adding a newline.
>  // Real purpose of this routine is to have a place to hang a breakpoint.
> -static void
> +inline void
>  issue_error_message(std::stringstream& outstr)
>  {
>  outstr << std::endl;
>  std::cerr << outstr.str();
> +std::exit(EXIT_FAILURE);
>  }
>  
> -template 
> -void
> -expect(bool condition, const char* file, int32_t line, const char* message)
> +inline void
> +expect(bool expected, bool condition, const char* file, int32_t line, const 
> char* message)
>  {
> -// Templating this function is somewhat silly, but avoids the need to 
> declare it static
> -// or have a separate translation unit.
> -if (condition != B)
> +if (condition != expected)
>  {
>  std::stringstream outstr;
>  outstr << "error at " << file << ":" << line << " - " << message;
> @@ -607,13 +606,6 @@ multiply_matrix(const Matrix2x2& left, const 
> Matrix2x2& right)
>  return result;
>  }
>  
> -// Check that Intel(R) Threading Building Blocks he

[PATCH] Integrate non-TBB serial backend support

2019-06-04 Thread Thomas Rodgers
* include/bits/c++config: Adjust TBB detection logic to select serial
PSTL backend if no TBB present.
* testsuite/utils/pstl/test_utils.h: Remove check for
__PSTL_USE_PAR_POLICIES
---
 libstdc++-v3/include/bits/c++config   |  8 ++--
 libstdc++-v3/testsuite/util/pstl/test_utils.h | 40 +++
 2 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config 
b/libstdc++-v3/include/bits/c++config
index 4b8574bf433..746e35efbfc 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -656,9 +656,7 @@ namespace std
 
 #if __cplusplus >= 201703L
 // Preserved here so we have some idea which version of upstream we've pulled 
in
-// #define PSTL_VERSION 104
-// #define PSTL_VERSION_MAJOR (PSTL_VERSION/100)
-// #define PSTL_VERSION_MINOR (PSTL_VERSION - PSTL_VERSION_MAJOR * 100)
+// #define PSTL_VERSION 9000
 
 // For now this defaults to being based on the presence of Thread Building 
Blocks
 # ifndef _GLIBCXX_USE_TBB_PAR_BACKEND
@@ -666,7 +664,9 @@ namespace std
 # endif
 // This section will need some rework when a new (default) backend type is 
added
 # if _GLIBCXX_USE_TBB_PAR_BACKEND
-#  define _PSTL_USE_PAR_POLICIES 1
+#  define _PSTL_PAR_BACKEND_TBB
+# else
+#  define _PSTL_PAR_BACKEND_SERIAL
 # endif
 
 # define _PSTL_ASSERT(_Condition) __glibcxx_assert(_Condition)
diff --git a/libstdc++-v3/testsuite/util/pstl/test_utils.h 
b/libstdc++-v3/testsuite/util/pstl/test_utils.h
index 9d16fa566e2..6547d931c29 100644
--- a/libstdc++-v3/testsuite/util/pstl/test_utils.h
+++ b/libstdc++-v3/testsuite/util/pstl/test_utils.h
@@ -10,14 +10,15 @@
 // File contains common utilities that tests rely on
 
 // Do not #include , because if we do we will not detect accidental 
dependencies.
-#include 
-#include 
+#include 
+#include 
+#include 
 #include 
+#include 
 #include 
-#include 
-#include 
 #include 
-#include 
+#include 
+#include 
 
 #include "pstl_test_config.h"
 
@@ -38,32 +39,30 @@ template 
 class Sequence;
 
 // Handy macros for error reporting
-#define EXPECT_TRUE(condition, message) TestUtils::expect(condition, 
__FILE__, __LINE__, message)
-#define EXPECT_FALSE(condition, message) TestUtils::expect(condition, 
__FILE__, __LINE__, message)
+#define EXPECT_TRUE(condition, message) ::TestUtils::expect(true, condition, 
__FILE__, __LINE__, message)
+#define EXPECT_FALSE(condition, message) ::TestUtils::expect(false, condition, 
__FILE__, __LINE__, message)
 
 // Check that expected and actual are equal and have the same type.
-#define EXPECT_EQ(expected, actual, message) TestUtils::expect_equal(expected, 
actual, __FILE__, __LINE__, message)
+#define EXPECT_EQ(expected, actual, message) 
::TestUtils::expect_equal(expected, actual, __FILE__, __LINE__, message)
 
 // Check that sequences started with expected and actual and have had size n 
are equal and have the same type.
 #define EXPECT_EQ_N(expected, actual, n, message)  
\
-TestUtils::expect_equal(expected, actual, n, __FILE__, __LINE__, message)
+::TestUtils::expect_equal(expected, actual, n, __FILE__, __LINE__, message)
 
 // Issue error message from outstr, adding a newline.
 // Real purpose of this routine is to have a place to hang a breakpoint.
-static void
+inline void
 issue_error_message(std::stringstream& outstr)
 {
 outstr << std::endl;
 std::cerr << outstr.str();
+std::exit(EXIT_FAILURE);
 }
 
-template 
-void
-expect(bool condition, const char* file, int32_t line, const char* message)
+inline void
+expect(bool expected, bool condition, const char* file, int32_t line, const 
char* message)
 {
-// Templating this function is somewhat silly, but avoids the need to 
declare it static
-// or have a separate translation unit.
-if (condition != B)
+if (condition != expected)
 {
 std::stringstream outstr;
 outstr << "error at " << file << ":" << line << " - " << message;
@@ -607,13 +606,6 @@ multiply_matrix(const Matrix2x2& left, const 
Matrix2x2& right)
 return result;
 }
 
-// Check that Intel(R) Threading Building Blocks header files are not used 
when parallel policies are off
-#if !_PSTL_USE_PAR_POLICIES
-#if defined(TBB_INTERFACE_VERSION)
-#error The parallel backend is used while it should not 
(_PSTL_USE_PAR_POLICIES==0)
-#endif
-#endif
-
 //
 // Adapters for creating different types of iterators.
 //
@@ -1052,10 +1044,8 @@ invoke_on_all_policies(Op op, T&&... rest)
 // Try static execution policies
 invoke_on_all_iterator_types()(seq, op, std::forward(rest)...);
 invoke_on_all_iterator_types()(unseq, op, std::forward(rest)...);
-#if _PSTL_USE_PAR_POLICIES
 invoke_on_all_iterator_types()(par, op, std::forward(rest)...);
 invoke_on_all_iterator_types()(par_unseq, op, std::forward(rest)...);
-#endif
 }
 
 

Re: [PATCH] Clean up non-conforming names

2019-06-02 Thread Thomas Rodgers


Jonathan Wakely writes:

> On 31/05/19 17:15 -0700, Thomas Rodgers wrote:
>>
>>Revising previous version of this patch to pick another missed
>>uglification.
>
> OK for trunk, thanks.
>
> I also see this one:
>
> include/pstl/parallel_backend_tbb.h:__buffer(std::size_t n) : 
> _M_allocator(), _M_ptr(_M_allocator.allocate(n)), _M_buf_size(n) {}

Ok, I'll clean that one up and commit along with these changes.


Re: [PATCH] Clean up non-conforming names

2019-05-31 Thread Thomas Rodgers

Revising previous version of this patch to pick another missed
uglification.

>From 543d6be586ad8c29ef0ceefd55a249c715bd2480 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Fri, 31 May 2019 13:28:32 -0700
Subject: [PATCH] Clean up non-conforming names

	* include/pstl/algorithm_impl.h (__parallel_set_union_op):
	Uglfiy copy_range1 and copy_range2
	(__pattern_walk2_n): Rename local n to __n
	* include/pstl/parallel_backend_tbb.h (struct __binary_no_op):
	Rename parameter _T to _Tp.
---
 libstdc++-v3/include/pstl/algorithm_impl.h | 18 +-
 .../include/pstl/parallel_backend_tbb.h|  4 ++--
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index 3491e002c94..2216420d1c3 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -282,7 +282,7 @@ _RandomAccessIterator2
 __pattern_walk2_n(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1, _Size __n, _RandomAccessIterator2 __first2,
   _Function __f, _IsVector __is_vector, /*parallel=*/std::true_type)
 {
-return __internal::__pattern_walk2(std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + n, __first2, __f,
+return __internal::__pattern_walk2(std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n, __first2, __f,
__is_vector, std::true_type());
 }
 
@@ -2855,22 +2855,22 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _
 const auto __n1 = __last1 - __first1;
 const auto __n2 = __last2 - __first2;
 
-auto copy_range1 = [__is_vector](_ForwardIterator1 __begin, _ForwardIterator1 __end, _OutputIterator __res) {
+auto __copy_range1 = [__is_vector](_ForwardIterator1 __begin, _ForwardIterator1 __end, _OutputIterator __res) {
 return __internal::__brick_copy(__begin, __end, __res, __is_vector);
 };
-auto copy_range2 = [__is_vector](_ForwardIterator2 __begin, _ForwardIterator2 __end, _OutputIterator __res) {
+auto __copy_range2 = [__is_vector](_ForwardIterator2 __begin, _ForwardIterator2 __end, _OutputIterator __res) {
 return __internal::__brick_copy(__begin, __end, __res, __is_vector);
 };
 
 // {1} {}: parallel copying just first sequence
 if (__n2 == 0)
 return __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __result,
- copy_range1, std::true_type());
+ __copy_range1, std::true_type());
 
 // {} {2}: parallel copying justmake  second sequence
 if (__n1 == 0)
 return __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2, __last2, __result,
- copy_range2, std::true_type());
+ __copy_range2, std::true_type());
 
 // testing  whether the sequences are intersected
 _ForwardIterator1 __left_bound_seq_1 = std::lower_bound(__first1, __last1, *__first2, __comp);
@@ -2882,7 +2882,7 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _
 std::forward<_ExecutionPolicy>(__exec),
 [=] {
 __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __result,
-  copy_range1, std::true_type());
+  __copy_range1, std::true_type());
 },
 [=] {
 __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
@@ -2901,7 +2901,7 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _
 std::forward<_ExecutionPolicy>(__exec),
 [=] {
 __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2, __last2, __result,
-  copy_range2, std::true_type());
+  __copy_range2, std::true_type());
 },
 [=] {
 __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
@@ -2920,7 +2920,7 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _
 //do parallel copying of [first1; left_bound_seq_1)
 [=] {
 __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1, __left_bound_seq_1,
-  __res_or, copy_range1, std::true_type());
+  __res_or, __copy_ra

[PATCH] Clean up non-conforming names

2019-05-31 Thread Thomas Rodgers


* include/pstl/algorithm_impl.h (__parallel_set_union_op):
Uglfiy copy_range1 and copy_range2
* include/pstl/parallel_backend_tbb.h (struct __binary_no_op):
Rename parameter _T to _Tp.
---
 libstdc++-v3/include/pstl/algorithm_impl.h   | 16 
 libstdc++-v3/include/pstl/parallel_backend_tbb.h |  4 ++--
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h 
b/libstdc++-v3/include/pstl/algorithm_impl.h
index 3491e002c94..a224b2b3633 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -2855,22 +2855,22 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, 
_ForwardIterator1 __first1, _
 const auto __n1 = __last1 - __first1;
 const auto __n2 = __last2 - __first2;
 
-auto copy_range1 = [__is_vector](_ForwardIterator1 __begin, 
_ForwardIterator1 __end, _OutputIterator __res) {
+auto __copy_range1 = [__is_vector](_ForwardIterator1 __begin, 
_ForwardIterator1 __end, _OutputIterator __res) {
 return __internal::__brick_copy(__begin, __end, __res, __is_vector);
 };
-auto copy_range2 = [__is_vector](_ForwardIterator2 __begin, 
_ForwardIterator2 __end, _OutputIterator __res) {
+auto __copy_range2 = [__is_vector](_ForwardIterator2 __begin, 
_ForwardIterator2 __end, _OutputIterator __res) {
 return __internal::__brick_copy(__begin, __end, __res, __is_vector);
 };
 
 // {1} {}: parallel copying just first sequence
 if (__n2 == 0)
 return 
__internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), 
__first1, __last1, __result,
- copy_range1, 
std::true_type());
+ __copy_range1, 
std::true_type());
 
 // {} {2}: parallel copying justmake  second sequence
 if (__n1 == 0)
 return 
__internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), 
__first2, __last2, __result,
- copy_range2, 
std::true_type());
+ __copy_range2, 
std::true_type());
 
 // testing  whether the sequences are intersected
 _ForwardIterator1 __left_bound_seq_1 = std::lower_bound(__first1, __last1, 
*__first2, __comp);
@@ -2882,7 +2882,7 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, 
_ForwardIterator1 __first1, _
 std::forward<_ExecutionPolicy>(__exec),
 [=] {
 
__internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), 
__first1, __last1, __result,
-  copy_range1, 
std::true_type());
+  __copy_range1, 
std::true_type());
 },
 [=] {
 
__internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), 
__first2, __last2,
@@ -2901,7 +2901,7 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, 
_ForwardIterator1 __first1, _
 std::forward<_ExecutionPolicy>(__exec),
 [=] {
 
__internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), 
__first2, __last2, __result,
-  copy_range2, 
std::true_type());
+  __copy_range2, 
std::true_type());
 },
 [=] {
 
__internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), 
__first1, __last1,
@@ -2920,7 +2920,7 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, 
_ForwardIterator1 __first1, _
 //do parallel copying of [first1; left_bound_seq_1)
 [=] {
 
__internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), 
__first1, __left_bound_seq_1,
-  __res_or, copy_range1, 
std::true_type());
+  __res_or, __copy_range1, 
std::true_type());
 },
 [=, &__result] {
 __result = __internal::__parallel_set_op(
@@ -2942,7 +2942,7 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, 
_ForwardIterator1 __first1, _
 //do parallel copying of [first2; left_bound_seq_2)
 [=] {
 
__internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), 
__first2, __left_bound_seq_2,
-  __res_or, copy_range2, 
std::true_type());
+  __res_or, __copy_range2, 
std::true_type());
 },
 [=, &__result] {
 __result = __internal::__parallel_set_op(
diff --git a/libstdc++-v3/include/pstl/parallel_backend_tbb.h 
b/libstdc++-v3/include/pstl/parallel_backend_tbb.h
index c6f5bb8d5ab..9c05ade0532 100644
--- 

[PATCH] Synchronize libstdc++ parallel algorithms with upstream project

2019-05-29 Thread Thomas Rodgers
* include/pstl/algorithm_fwd.h: Synchronize with
upstream PSTL project.
* include/pstl/algorithm_impl.h: Likewise.
* include/pstl/execution_defs.h: Likewise.
* include/pstl/execution_impl.h: Likewise.
* include/pstl/glue_algorithm_impl.h: Likewise.
* include/pstl/glue_execution_defs.h: Likewise.
* include/pstl/numeric_fwd.h: Likewise.
* include/pstl/numeric_impl.h: Likewise.
* include/pstl/parallel_backend.h: Likewise.
* include/pstl/pstl_config.h: Likewise.
* include/pstl/unseq_backend_simd.h: Likewise.
* include/pstl/parallel_backend_serial.h: New file.
* include/Makefile.am (pstl_headers): Add
parallel_backend_serial.h.
* include/Makefile.in: Regenerate.



0001-Synchronize-libstdc-parallel-algorithms-with-upstrea.patch.bz2
Description: BZip2 compressed data


[PATCH] Rename header guards to be consistent with upstream project's conventions.

2019-05-29 Thread Thomas Rodgers

* include/pstl/glue_memory_impl.h: Rename all macros of the form
_PSTL_(.*)_H to _PSTL_\U\1_H.
* include/pstl/numeric_impl.h: Likewise.
* include/pstl/glue_memory_defs.h: Likewise.
* include/pstl/execution_defs.h: Likewise.
* include/pstl/utils.h: Likewise.
* include/pstl/algorithm_fwd.h: Likewise.
* include/pstl/unseq_backend_simd.h: Likewise.
* include/pstl/glue_execution_defs.h: Likewise.
* include/pstl/algorithm_impl.h: Likewise.
* include/pstl/parallel_impl.h: Likewise.
* include/pstl/memory_impl.h: Likewise.
* include/pstl/glue_numeric_defs.h: Likewise.
* include/pstl/parallel_backend_utils.h: Likewise.
* include/pstl/glue_algorithm_defs.h: Likewise.
* include/pstl/parallel_backend.h: Likewise.
* include/pstl/glue_numeric_impl.h: Likewise.
* include/pstl/parallel_backend_tbb.h: Likewise.
* include/pstl/numeric_fwd.h: Likewise.
* include/pstl/glue_algorithm_impl.h: Likewise.
* include/pstl/execution_impl.h: Likewise.
* include/pstl/pstl_config.h: Likewise.
* testsuite/util/pstl/pstl_test_config.h: Likewise.

>From bb1e91fadde1ef813959bfb1d44a98531c256f8c Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Thu, 23 May 2019 16:49:49 -0700
Subject: [PATCH] Rename PSTL header guards

   Rename header guards to be consistent with upstream project's conventions.
	* include/pstl/glue_memory_impl.h: Rename all macros of the form
	_PSTL_(.*)_H to _PSTL_\U\1_H.
	* include/pstl/numeric_impl.h: Likewise.
	* include/pstl/glue_memory_defs.h: Likewise.
	* include/pstl/execution_defs.h: Likewise.
	* include/pstl/utils.h: Likewise.
	* include/pstl/algorithm_fwd.h: Likewise.
	* include/pstl/unseq_backend_simd.h: Likewise.
	* include/pstl/glue_execution_defs.h: Likewise.
	* include/pstl/algorithm_impl.h: Likewise.
	* include/pstl/parallel_impl.h: Likewise.
	* include/pstl/memory_impl.h: Likewise.
	* include/pstl/glue_numeric_defs.h: Likewise.
	* include/pstl/parallel_backend_utils.h: Likewise.
	* include/pstl/glue_algorithm_defs.h: Likewise.
	* include/pstl/parallel_backend.h: Likewise.
	* include/pstl/glue_numeric_impl.h: Likewise.
	* include/pstl/parallel_backend_tbb.h: Likewise.
	* include/pstl/numeric_fwd.h: Likewise.
	* include/pstl/glue_algorithm_impl.h: Likewise.
	* include/pstl/execution_impl.h: Likewise.
	* include/pstl/pstl_config.h: Likewise.
	* testsuite/util/pstl/pstl_test_config.h: Likewise.
---
 libstdc++-v3/include/pstl/algorithm_fwd.h   | 6 +++---
 libstdc++-v3/include/pstl/algorithm_impl.h  | 6 +++---
 libstdc++-v3/include/pstl/execution_defs.h  | 6 +++---
 libstdc++-v3/include/pstl/execution_impl.h  | 6 +++---
 libstdc++-v3/include/pstl/glue_algorithm_defs.h | 6 +++---
 libstdc++-v3/include/pstl/glue_algorithm_impl.h | 6 +++---
 libstdc++-v3/include/pstl/glue_execution_defs.h | 6 +++---
 libstdc++-v3/include/pstl/glue_memory_defs.h| 6 +++---
 libstdc++-v3/include/pstl/glue_memory_impl.h| 6 +++---
 libstdc++-v3/include/pstl/glue_numeric_defs.h   | 6 +++---
 libstdc++-v3/include/pstl/glue_numeric_impl.h   | 6 +++---
 libstdc++-v3/include/pstl/memory_impl.h | 6 +++---
 libstdc++-v3/include/pstl/numeric_fwd.h | 6 +++---
 libstdc++-v3/include/pstl/numeric_impl.h| 6 +++---
 libstdc++-v3/include/pstl/parallel_backend.h| 6 +++---
 libstdc++-v3/include/pstl/parallel_backend_tbb.h| 6 +++---
 libstdc++-v3/include/pstl/parallel_backend_utils.h  | 6 +++---
 libstdc++-v3/include/pstl/parallel_impl.h   | 6 +++---
 libstdc++-v3/include/pstl/pstl_config.h | 6 +++---
 libstdc++-v3/include/pstl/unseq_backend_simd.h  | 6 +++---
 libstdc++-v3/include/pstl/utils.h   | 6 +++---
 libstdc++-v3/testsuite/util/pstl/pstl_test_config.h | 6 +++---
 22 files changed, 66 insertions(+), 66 deletions(-)

diff --git a/libstdc++-v3/include/pstl/algorithm_fwd.h b/libstdc++-v3/include/pstl/algorithm_fwd.h
index 0edeb98adbb..8af3aacbcdb 100644
--- a/libstdc++-v3/include/pstl/algorithm_fwd.h
+++ b/libstdc++-v3/include/pstl/algorithm_fwd.h
@@ -7,8 +7,8 @@
 //
 //===--===//
 
-#ifndef _PSTL_algorithm_fwd_H
-#define _PSTL_algorithm_fwd_H
+#ifndef _PSTL_ALGORITHM_FWD_H
+#define _PSTL_ALGORITHM_FWD_H
 
 #include 
 #include 
@@ -1333,4 +1333,4 @@ __pattern_lexicographical_compare(_ExecutionPolicy&&, _ForwardIterator1, _Forwar
 
 } // namespace __internal
 } // namespace __pstl
-#endif /* _PSTL_algorithm_fwd_H */
+#endif /* _PSTL_ALGORITHM_FWD_H */
diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index 60e5e75a64d..83213084e89 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@

Re: RFC: [PATCH] Remove using-declarations that add std names to __gnu_cxx

2019-05-29 Thread Thomas Rodgers
Concur

Ville Voutilainen writes:

> On Wed, 29 May 2019 at 23:00, Jonathan Wakely  wrote:
>> Does anybody think we should keep __gnu_cxx::size_t,
>> __gnu_cxx::input_iterator_tag, __gnu_cxx::vector, __gnu_cxx::pair etc.
>> or should I go ahead and commit this?
>
> +1 go ahead.



[PATCH] [Patch] Rename PSTL macro's consistent with libstdc++ standards.

2019-05-22 Thread Thomas Rodgers


0001-Patch-Rename-PSTL-macro-s-consistent-with-libstdc-st.patch.bz2
Description: Compressed patch

* include/bits/c++config: Rename all macros of the form __PSTL* to 
_PSTL*.
* include/std/algorithm: Likewise.
* include/std/execution: Likewise.
* include/std/numeric: Likewise.
* include/std/memory: Likewise.
* include/pstl/glue_memory_impl.h: Likewise.
* include/pstl/numeric_impl.h: Likewise.
* include/pstl/glue_memory_defs.h: Likewise.
* include/pstl/execution_defs.h: Likewise.
* include/pstl/utils.h: Likewise.
* include/pstl/algorithm_fwd.h: Likewise.
* include/pstl/unseq_backend_simd.h: Likewise.
* include/pstl/glue_execution_defs.h: Likewise.
* include/pstl/algorithm_impl.h: Likewise.
* include/pstl/parallel_impl.h: Likewise.
* include/pstl/memory_impl.h: Likewise.
* include/pstl/glue_numeric_defs.h: Likewise.
* include/pstl/parallel_backend_utils.h: Likewise.
* include/pstl/glue_algorithm_defs.h: Likewise.
* include/pstl/parallel_backend.h: Likewise.
* include/pstl/glue_numeric_impl.h: Likewise.
* include/pstl/parallel_backend_tbb.h: Likewise.
* include/pstl/numeric_fwd.h: Likewise.
* include/pstl/glue_algorithm_impl.h: Likewise.
* include/pstl/execution_impl.h: Likewise.
* include/pstl/pstl_config.h: Likewise.
* testsuite/util/pstl/pstl_test_config.h: Likewise.
* testsuite/util/pstl/test_utils.h: Likewise.
* 
testsuite/20_util/specialized_algorithms/pstl/uninitialized_construct.cc: 
Likewise.
* 
testsuite/20_util/specialized_algorithms/pstl/uninitialized_copy_move.cc: 
Likewise.
* testsuite/26_numerics/pstl/numeric_ops/adjacent_difference.cc: 
Likewise.
* testsuite/26_numerics/pstl/numeric_ops/scan.cc: Likewise.
* testsuite/26_numerics/pstl/numeric_ops/transform_scan.cc: Likewise.
* testsuite/26_numerics/pstl/numeric_ops/reduce.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/reverse.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/nth_element.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/find_end.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/find_if.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/none_of.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/count.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/reverse_copy.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/equal.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/search_n.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/find.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/all_of.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/find_first_of.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_sorting/is_heap.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_sorting/partial_sort_copy.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_sorting/lexicographical_compare.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc: Likewise.
* testsuite/25_algorithms/pstl/alg_merge/merge.cc: Likewise.
* 
testsuite/25_algorithms/pstl/alg_modifying_operations/unique_copy_equal.cc: 
Likewise.
* 
testsuite/25_algorithms/pstl/alg_modifying_operations/replace_copy.cc: Likewise.
* 
testsuite/25_algorithms/pstl/alg_modifying_operations/is_partitioned.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_modifying_operations/rotate_copy.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_modifying_operations/remove.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_modifying_operations/copy_if.cc: 
Likewise.
* 
testsuite/25_algorithms/pstl/alg_modifying_operations/partition_copy.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_modifying_operations/partition.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_modifying_operations/copy_move.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_modifying_operations/unique.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_modifying_operations/rotate.cc: 
Likewise.
* testsuite/25_algorithms/pstl/alg_nonmodifying/any_of.cc: Likewise.


Re: [PATCH] Implement LWG 3062, Unnecessary decay_t in is_execution_policy_v

2019-05-21 Thread Thomas Rodgers
The revised attached patch has been ested x86_64-linux, committed to trunk.
>From 5f8aeeb98477d6555d65a45d1d2aed84b26863c9 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Tue, 21 May 2019 12:02:35 -0700
Subject: [PATCH] LWG 3062 - Unnecessary decay_t in is_execution_policy_v

* include/pstl/execution_defs.h (__enable_if_execution_policy):
Use std::__remove_cv_ref_t when building with GCC.
---
 libstdc++-v3/ChangeLog | 6 ++
 libstdc++-v3/include/pstl/execution_defs.h | 6 ++
 2 files changed, 12 insertions(+)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 804bace5e03..8ce445e39b8 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,9 @@
+2019-05-21  Thomas Rodgers  
+
+	LWG 3062 - Unnecessary decay_t in is_execution_policy_v
+	* include/pstl/execution_defs.h (__enable_if_execution_policy):
+	Use std::__remove_cv_ref_t when building with GCC.
+
 2019-05-21  Jonathan Wakely  
 
 	PR libstdc++/90252
diff --git a/libstdc++-v3/include/pstl/execution_defs.h b/libstdc++-v3/include/pstl/execution_defs.h
index 1a551c7871c..34b0e3d6350 100644
--- a/libstdc++-v3/include/pstl/execution_defs.h
+++ b/libstdc++-v3/include/pstl/execution_defs.h
@@ -152,9 +152,15 @@ constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<_T
 namespace __internal
 {
 template 
+#if _GLIBCXX_RELEASE >= 9
+using __enable_if_execution_policy =
+typename std::enable_if<__pstl::execution::is_execution_policy>::value,
+_Tp>::type;
+#else
 using __enable_if_execution_policy =
 typename std::enable_if<__pstl::execution::is_execution_policy::type>::value,
 _Tp>::type;
+#endif
 } // namespace __internal
 
 } // namespace __pstl
-- 
2.20.1


Thomas Rodgers writes:

> Revised patch.
>
> From 074685cf74b48604244c0c6f1d8cba63ff8915e5 Mon Sep 17 00:00:00 2001
> From: Thomas Rodgers 
> Date: Wed, 24 Apr 2019 15:53:45 -0700
> Subject: [PATCH] Implement LWG 3062, Unnecessary decay_t in
>  is_execution_policy_v
>
>   should be remove_cvref_t
>   * include/pstl/execution_defs.h (__enable_if_execution_policy):
> Use std::__remove_cv_ref_t when building with GCC.
> ---
>  libstdc++-v3/include/pstl/execution_defs.h | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/libstdc++-v3/include/pstl/execution_defs.h 
> b/libstdc++-v3/include/pstl/execution_defs.h
> index 86c7a5a770d..0ed4cc30914 100644
> --- a/libstdc++-v3/include/pstl/execution_defs.h
> +++ b/libstdc++-v3/include/pstl/execution_defs.h
> @@ -152,9 +152,15 @@ constexpr bool is_execution_policy_v = 
> __pstl::execution::is_execution_policy<_T
>  namespace __internal
>  {
>  template 
> +#if _GLIBCXX_RELEASE >= 9
> +using __enable_if_execution_policy =
> +typename 
> std::enable_if<__pstl::execution::is_execution_policy>::value,
> +_T>::type;
> +#else
>  using __enable_if_execution_policy =
>  typename std::enable_if<__pstl::execution::is_execution_policy std::decay<_ExecPolicy>::type>::value,
>  _T>::type;
> +#endif
>  } // namespace __internal
>  
>  } // namespace __pstl



Re: [PATCH] tbb-backend effective target should check ability to link TBB

2019-05-20 Thread Thomas Rodgers
With the addition of "-ltbb" to the v3_target_compile flags (so as to,
you know, actually try to link tbb).

Tested x86_64-linux, committed to trunk.

Thomas Rodgers writes:

>   PR libstdc++/90252
>   * testsuite/lib/libstdc++.exp (check_effective_target_tbb-backend):
>   Changed v3_target_compile check from preprocess to executable.
> ---
>  libstdc++-v3/testsuite/lib/libstdc++.exp | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp 
> b/libstdc++-v3/testsuite/lib/libstdc++.exp
> index c48b4d78bbb..fa61bccc9f6 100644
> --- a/libstdc++-v3/testsuite/lib/libstdc++.exp
> +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
> @@ -1612,15 +1612,20 @@ proc check_effective_target_tbb-backend { } {
>  # Set up and preprocess a C++ test program that depends
>  # on tbb
>  set src tbb_backend[pid].cc
> -
> +set exe tbb_backend[pid].x
> +
>  set f [open $src "w"]
>  puts $f "#include "
>  puts $f "#if TBB_INTERFACE_VERSION < 1"
>  puts $f "#  error Intel(R) Threading Building Blocks 2018 is required; 
> older versions are not supported."
>  puts $f "#endif"
> +puts $f "int main ()"
> +puts $f "{"
> +puts $f "  return 0;"
> +puts $f "}"
>  close $f
>  
> -set lines [v3_target_compile $src /dev/null preprocess ""]
> +set lines [v3_target_compile $src $exe executable ""]
>  file delete $src
>  
>  if [string match "" $lines] {



Re: [PATCH] Check TBB version in tbb-backed effective target check

2019-05-20 Thread Thomas Rodgers
Tested x86_64-linux, committed to trunk.

Thomas Rodgers writes:

>   * testsuite/lib/libstdc++.exp (check_effective_target_tbb-backend):
>   Add check for Thread Building Blocks 2018 or later.
>
> From bd3de7b67f184ed1387b63dc3bda1d12f7ebee04 Mon Sep 17 00:00:00 2001
> From: Thomas Rodgers 
> Date: Wed, 24 Apr 2019 11:34:14 -0700
> Subject: [PATCH] Check TBB version in tbb-backed effective target check
>
>   * testsuite/lib/libstdc++.exp (check_effective_target_tbb-backend):
>   Add check for Thread Building Blocks 2018 or later.
> ---
>  libstdc++-v3/testsuite/lib/libstdc++.exp | 42 +---
>  1 file changed, 23 insertions(+), 19 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp 
> b/libstdc++-v3/testsuite/lib/libstdc++.exp
> index d0efc90a1ba..c48b4d78bbb 100644
> --- a/libstdc++-v3/testsuite/lib/libstdc++.exp
> +++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
> @@ -1607,25 +1607,29 @@ proc check_effective_target_random_device { } {
>  
>  # Return 1 if tbb parallel backend is available
>  proc check_effective_target_tbb-backend { } {
> - global cxxflags
> -
> - # Set up and preprocess a C++ test program that depends
> - # on tbb
> - set src tbb_backend[pid].cc
> -
> - set f [open $src "w"]
> - puts $f "#include "
> - close $f
> - set lines [v3_target_compile $src /dev/null preprocess ""]
> - file delete $src
> -
> - if [string match "" $lines] {
> - # No error message, preprocessing succeeded.
> - verbose "check_v3_tbb-backend: `1'" 2
> - return 1
> - }
> - verbose "check_v3_tbb-backend: `0'" 2
> - return 0
> +global cxxflags
> +
> +# Set up and preprocess a C++ test program that depends
> +# on tbb
> +set src tbb_backend[pid].cc
> +
> +set f [open $src "w"]
> +puts $f "#include "
> +puts $f "#if TBB_INTERFACE_VERSION < 1"
> +puts $f "#  error Intel(R) Threading Building Blocks 2018 is required; 
> older versions are not supported."
> +puts $f "#endif"
> +close $f
> +
> +set lines [v3_target_compile $src /dev/null preprocess ""]
> +file delete $src
> +
> +if [string match "" $lines] {
> + # No error message, preprocessing succeeded.
> + verbose "check_v3_tbb-backend: `1'" 2
> + return 1
> +}
> +verbose "check_v3_tbb-backend: `0'" 2
> +return 0
>  }
>  
>  set additional_prunes ""



Re: [PATCH] tbb-backend effective target should check ability to link TBB

2019-05-17 Thread Thomas Rodgers
I have it fixed locally, but yeah I have not yet committed it.

Jonathan Wakely writes:

> On 25/04/19 15:58 -0700, Thomas Rodgers wrote:
>>
>>  PR libstdc++/90252
>>  * testsuite/lib/libstdc++.exp (check_effective_target_tbb-backend):
>>  Changed v3_target_compile check from preprocess to executable.
>>---
>> libstdc++-v3/testsuite/lib/libstdc++.exp | 9 +++--
>> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> This patch is still pending, but I think it's missing -ltbb that would
> actually make the link succeed, isn't it?
>
>>diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp 
>>b/libstdc++-v3/testsuite/lib/libstdc++.exp
>>index c48b4d78bbb..fa61bccc9f6 100644
>>--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
>>+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
>>@@ -1612,15 +1612,20 @@ proc check_effective_target_tbb-backend { } {
>> # Set up and preprocess a C++ test program that depends
>> # on tbb
>> set src tbb_backend[pid].cc
>>-
>>+set exe tbb_backend[pid].x
>>+
>> set f [open $src "w"]
>> puts $f "#include "
>> puts $f "#if TBB_INTERFACE_VERSION < 1"
>> puts $f "#  error Intel(R) Threading Building Blocks 2018 is required; 
>> older versions are not supported."
>> puts $f "#endif"
>>+puts $f "int main ()"
>>+puts $f "{"
>>+puts $f "  return 0;"
>>+puts $f "}"
>> close $f
>>
>>-set lines [v3_target_compile $src /dev/null preprocess ""]
>>+set lines [v3_target_compile $src $exe executable ""]
>> file delete $src
>>
>> if [string match "" $lines] {
>> -- 
>>2.20.1
>>



[PATCH] Add myself to MAINTAINERS

2019-05-17 Thread Thomas Rodgers
diff --git a/ChangeLog b/ChangeLog
index 8a6638497b8..4c8e3c91d55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2019-05-17  Thomas Rodgers  
+
+	* MAINTAINERS (Write After Approval): Add myself.
+
 2019-05-16  Jun Ma  
 
 	* MAINTAINERS (Write After Approval): Add myself.
diff --git a/MAINTAINERS b/MAINTAINERS
index 7c5942ad817..a1809f1ad34 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -554,6 +554,7 @@ Fritz Reese	
 Volker Reichelt	
 Bernhard Reutner-Fischer			
 Tom Rix		
+Thomas Rodgers	
 Craig Rodrigues	
 Erven Rohou	
 Ira Rosen	


[PATCH] tbb-backend effective target should check ability to link TBB

2019-04-25 Thread Thomas Rodgers


PR libstdc++/90252
* testsuite/lib/libstdc++.exp (check_effective_target_tbb-backend):
Changed v3_target_compile check from preprocess to executable.
---
 libstdc++-v3/testsuite/lib/libstdc++.exp | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp 
b/libstdc++-v3/testsuite/lib/libstdc++.exp
index c48b4d78bbb..fa61bccc9f6 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -1612,15 +1612,20 @@ proc check_effective_target_tbb-backend { } {
 # Set up and preprocess a C++ test program that depends
 # on tbb
 set src tbb_backend[pid].cc
-
+set exe tbb_backend[pid].x
+
 set f [open $src "w"]
 puts $f "#include "
 puts $f "#if TBB_INTERFACE_VERSION < 1"
 puts $f "#  error Intel(R) Threading Building Blocks 2018 is required; 
older versions are not supported."
 puts $f "#endif"
+puts $f "int main ()"
+puts $f "{"
+puts $f "  return 0;"
+puts $f "}"
 close $f
 
-set lines [v3_target_compile $src /dev/null preprocess ""]
+set lines [v3_target_compile $src $exe executable ""]
 file delete $src
 
 if [string match "" $lines] {
-- 
2.20.1



Re: [PATCH] Implement LWG 3062, Unnecessary decay_t in is_execution_policy_v

2019-04-25 Thread Thomas Rodgers
Revised patch.

>From 074685cf74b48604244c0c6f1d8cba63ff8915e5 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Wed, 24 Apr 2019 15:53:45 -0700
Subject: [PATCH] Implement LWG 3062, Unnecessary decay_t in
 is_execution_policy_v

	should be remove_cvref_t
	* include/pstl/execution_defs.h (__enable_if_execution_policy):
Use std::__remove_cv_ref_t when building with GCC.
---
 libstdc++-v3/include/pstl/execution_defs.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libstdc++-v3/include/pstl/execution_defs.h b/libstdc++-v3/include/pstl/execution_defs.h
index 86c7a5a770d..0ed4cc30914 100644
--- a/libstdc++-v3/include/pstl/execution_defs.h
+++ b/libstdc++-v3/include/pstl/execution_defs.h
@@ -152,9 +152,15 @@ constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<_T
 namespace __internal
 {
 template 
+#if _GLIBCXX_RELEASE >= 9
+using __enable_if_execution_policy =
+typename std::enable_if<__pstl::execution::is_execution_policy>::value,
+_T>::type;
+#else
 using __enable_if_execution_policy =
 typename std::enable_if<__pstl::execution::is_execution_policy::type>::value,
 _T>::type;
+#endif
 } // namespace __internal
 
 } // namespace __pstl
-- 
2.20.1


Jonathan Wakely writes:

> On 24/04/19 16:01 -0700, Thomas Rodgers wrote:
>>
>>  should be remove_cvref_t
>>  * include/pstl/execution_defs.h (__enable_if_execution_policy):
>>Use std::__remove_cv_ref_t when building with GCC
>>
>
>>From cb7bd9a39acacbf81df0d03da8714fa463057cc5 Mon Sep 17 00:00:00 2001
>>From: Thomas Rodgers 
>>Date: Wed, 24 Apr 2019 15:53:45 -0700
>>Subject: [PATCH] Implement LWG 3062, Unnecessary decay_t in
>> is_execution_policy_v
>>
>>  should be remove_cvref_t
>>  * include/pstl/execution_defs.h (__enable_if_execution_policy):
>>Use std::__remove_cv_ref_t when building with GCC.
>>---
>> libstdc++-v3/include/pstl/execution_defs.h | 6 ++
>> 1 file changed, 6 insertions(+)
>>
>>diff --git a/libstdc++-v3/include/pstl/execution_defs.h 
>>b/libstdc++-v3/include/pstl/execution_defs.h
>>index 86c7a5a770d..9b9b212b1bd 100644
>>--- a/libstdc++-v3/include/pstl/execution_defs.h
>>+++ b/libstdc++-v3/include/pstl/execution_defs.h
>>@@ -152,9 +152,15 @@ constexpr bool is_execution_policy_v = 
>>__pstl::execution::is_execution_policy<_T
>> namespace __internal
>> {
>> template 
>>+#if __GNUC__
>
> Clang and Intel both define that macro, but that doesn't mean
> __remove_cvref_t is available. I think you want __GLIBCXX__ to tell
> that libstdc++ is in use, or better still:
>
> #if _GLIBCXX_RELEASE >= 9
>
>>+using __enable_if_execution_policy =
>>+typename std::enable_if<__pstl::execution::is_execution_policy>std::__remove_cvref_t<_ExecPolicy>>::value,
>
> The typename before std::__remove_cvref_t shouldn't be there.
>
>>+_T>::type;
>>+#else
>> using __enable_if_execution_policy =
>> typename std::enable_if<__pstl::execution::is_execution_policy> std::decay<_ExecPolicy>::type>::value,
>> _T>::type;
>>+#endif
>> } // namespace __internal
>>
>> } // namespace __pstl
>> -- 
>>2.20.1
>>



[PATCH] Implement LWG 3062, Unnecessary decay_t in is_execution_policy_v

2019-04-24 Thread Thomas Rodgers

should be remove_cvref_t
* include/pstl/execution_defs.h (__enable_if_execution_policy):
Use std::__remove_cv_ref_t when building with GCC

>From cb7bd9a39acacbf81df0d03da8714fa463057cc5 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Wed, 24 Apr 2019 15:53:45 -0700
Subject: [PATCH] Implement LWG 3062, Unnecessary decay_t in
 is_execution_policy_v

	should be remove_cvref_t
	* include/pstl/execution_defs.h (__enable_if_execution_policy):
Use std::__remove_cv_ref_t when building with GCC.
---
 libstdc++-v3/include/pstl/execution_defs.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libstdc++-v3/include/pstl/execution_defs.h b/libstdc++-v3/include/pstl/execution_defs.h
index 86c7a5a770d..9b9b212b1bd 100644
--- a/libstdc++-v3/include/pstl/execution_defs.h
+++ b/libstdc++-v3/include/pstl/execution_defs.h
@@ -152,9 +152,15 @@ constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<_T
 namespace __internal
 {
 template 
+#if __GNUC__
+using __enable_if_execution_policy =
+typename std::enable_if<__pstl::execution::is_execution_policy>::value,
+_T>::type;
+#else
 using __enable_if_execution_policy =
 typename std::enable_if<__pstl::execution::is_execution_policy::type>::value,
 _T>::type;
+#endif
 } // namespace __internal
 
 } // namespace __pstl
-- 
2.20.1



[PATCH] Uglify names in pstl/execution_defs.h

2019-04-24 Thread Thomas Rodgers
Missed in prior uglification passes.

* include/pstl/execution_defs.h:
Uglfiy inline namespace.
Uglify ExecPolicy and T template parameters.

>From 07d15a71f60d9dec58882f9cfbf80e4b1ed043f3 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Wed, 24 Apr 2019 14:57:26 -0700
Subject: [PATCH] Uglify names in pstl/execution_defs.h

Missed in prior uglification passes.

	* include/pstl/execution_defs.h:
	Uglfiy inline namespace.
	Uglify ExecPolicy and T template parameters.
---
 libstdc++-v3/include/pstl/execution_defs.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libstdc++-v3/include/pstl/execution_defs.h b/libstdc++-v3/include/pstl/execution_defs.h
index 9a4b49bd46a..86c7a5a770d 100644
--- a/libstdc++-v3/include/pstl/execution_defs.h
+++ b/libstdc++-v3/include/pstl/execution_defs.h
@@ -16,7 +16,7 @@ namespace __pstl
 {
 namespace execution
 {
-inline namespace v1
+inline namespace __v1
 {
 
 // 2.4, Sequential execution policy
@@ -117,7 +117,7 @@ constexpr parallel_unsequenced_policy par_unseq{};
 constexpr unsequenced_policy unseq{};
 
 // 2.3, Execution policy type trait
-template 
+template 
 struct is_execution_policy : std::false_type
 {
 };
@@ -142,8 +142,8 @@ struct is_execution_policy<__pstl::execution::unsequenced_policy> : std::true_ty
 };
 
 #if __PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT
-template 
-constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy::value;
+template 
+constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<_T>::value;
 #endif
 
 } // namespace v1
@@ -151,10 +151,10 @@ constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy
 
 namespace __internal
 {
-template 
+template 
 using __enable_if_execution_policy =
-typename std::enable_if<__pstl::execution::is_execution_policy::type>::value,
-T>::type;
+typename std::enable_if<__pstl::execution::is_execution_policy::type>::value,
+_T>::type;
 } // namespace __internal
 
 } // namespace __pstl
-- 
2.20.1



[PATCH] Check TBB version in tbb-backed effective target check

2019-04-24 Thread Thomas Rodgers

* testsuite/lib/libstdc++.exp (check_effective_target_tbb-backend):
Add check for Thread Building Blocks 2018 or later.

>From bd3de7b67f184ed1387b63dc3bda1d12f7ebee04 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Wed, 24 Apr 2019 11:34:14 -0700
Subject: [PATCH] Check TBB version in tbb-backed effective target check

	* testsuite/lib/libstdc++.exp (check_effective_target_tbb-backend):
	Add check for Thread Building Blocks 2018 or later.
---
 libstdc++-v3/testsuite/lib/libstdc++.exp | 42 +---
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index d0efc90a1ba..c48b4d78bbb 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -1607,25 +1607,29 @@ proc check_effective_target_random_device { } {
 
 # Return 1 if tbb parallel backend is available
 proc check_effective_target_tbb-backend { } {
-		global cxxflags
-
-		# Set up and preprocess a C++ test program that depends
-		# on tbb
-		set src tbb_backend[pid].cc
-
-		set f [open $src "w"]
-		puts $f "#include "
-		close $f
-		set lines [v3_target_compile $src /dev/null preprocess ""]
-		file delete $src
-
-		if [string match "" $lines] {
-# No error message, preprocessing succeeded.
-verbose "check_v3_tbb-backend: `1'" 2
-return 1
-		}
-		verbose "check_v3_tbb-backend: `0'" 2
-		return 0
+global cxxflags
+
+# Set up and preprocess a C++ test program that depends
+# on tbb
+set src tbb_backend[pid].cc
+
+set f [open $src "w"]
+puts $f "#include "
+puts $f "#if TBB_INTERFACE_VERSION < 1"
+puts $f "#  error Intel(R) Threading Building Blocks 2018 is required; older versions are not supported."
+puts $f "#endif"
+close $f
+
+set lines [v3_target_compile $src /dev/null preprocess ""]
+file delete $src
+
+if [string match "" $lines] {
+	# No error message, preprocessing succeeded.
+	verbose "check_v3_tbb-backend: `1'" 2
+	return 1
+}
+verbose "check_v3_tbb-backend: `0'" 2
+return 0
 }
 
 set additional_prunes ""
-- 
2.20.1



Re: [PATCH] Document PSTL linker flags

2019-04-23 Thread Thomas Rodgers


Jonathan Wakely writes:

> On 23/04/19 09:54 -0700, Thomas Rodgers wrote:
>>
>>   * doc/xml/manual/using.xml: Add PSTL linker flags to table 3.1.
>
> OK - thanks.

Committed to trunk


[PATCH] Document PSTL linker flags

2019-04-23 Thread Thomas Rodgers

 * doc/xml/manual/using.xml: Add PSTL linker flags to table 3.1.

>From eabe72642bf51b813f454c54ae3cc4e873cf34be Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Tue, 23 Apr 2019 09:50:13 -0700
Subject: [PATCH] Document PSTL linker flags

	 * doc/xml/manual/using.xml: Add PSTL linker flags to table
   3.1.
---
 libstdc++-v3/doc/xml/manual/using.xml | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libstdc++-v3/doc/xml/manual/using.xml b/libstdc++-v3/doc/xml/manual/using.xml
index 9e8fe0715a3..8e099d9c3d8 100644
--- a/libstdc++-v3/doc/xml/manual/using.xml
+++ b/libstdc++-v3/doc/xml/manual/using.xml
@@ -107,6 +107,15 @@
   -fopenmp
   For parallel mode.
 
+
+
+  -ltbb
+  Linking to tbb (Thread Building Blocks) is required for use of the
+Parallel Standard Algorithms and execution policies in
+execution.
+  
+
+
   
 
 
-- 
2.20.1



Re: [PATCH] Delegate PSTL configuration to pstl/pstl_config.h

2019-04-20 Thread Thomas Rodgers


Jonathan Wakely writes:

> On 18/04/19 17:02 -0700, Thomas Rodgers wrote:
>>
>>   * include/bits/c++config: Remove explicit PSTL configuration
>>   macros and use definitions from .
>
> OK for trunk, thanks.

Tested x86_64-linux-gnu, committed to trunk.


Re: [PATCH] Cleanup algorithm implementations

2019-04-20 Thread Thomas Rodgers


Jonathan Wakely writes:

> On 19/04/19 11:59 -0700, Thomas Rodgers wrote:
>>  * include/pstl/glue_algorithm_impl.h (stable_sort): Forward
>>execution policy.
>>  (mismatch): Forward execution policy.
>>  (equal): Qualify call to std::equal().
>>  (partial_sort): Forward execution policy.
>>  (inplace_merge): Forward execution policy.
>
> OK for trunk, thanks.

Tested x86_64-linux-gnu, committed to trunk.


Re: [PATCH] Improve implementation of parallel equal()

2019-04-20 Thread Thomas Rodgers


Jonathan Wakely writes:

> On 16/04/19 12:39 -0700, Thomas Rodgers wrote:
>>
>>  * include/pstl/algorithm_impl.h
>>  (__internal::__brick_equal): use "4 iterator" version of
>>  std::equal().
>>  (__internal::__brick_equal): use simd for random access
>>  iterators on unsequenced execution policies.
>>  (__internal::__pattern_equal): add "4 iterator" version
>>  (__internal::__pattern_equal): dispatch to simd __brick_equal
>>  for vector-only execution policies.
>>  (__internal::__pattern_equal): disptach to __parallel_or for
>
> s/disptach/dispatch/ in the changelog
>
>
>
>>--- a/libstdc++-v3/include/pstl/glue_algorithm_impl.h
>>+++ b/libstdc++-v3/include/pstl/glue_algorithm_impl.h
>>@@ -757,7 +757,7 @@ 
>>__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
>> equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, 
>> _ForwardIterator1 __last1, _ForwardIterator2 __first2,
>>   _ForwardIterator2 __last2)
>> {
>>-return equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, 
>>__first2,
>>+return equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, 
>>__first2, __last2,
>
> N.B. I don't think this should be an unqualified call, but that can be
> fixed in a later patch.
>
> OK for trunk, thanks.

Tested x86_64-linux-gnu, committed to trunk.


[PATCH] Cleanup algorithm implementations

2019-04-19 Thread Thomas Rodgers
* include/pstl/glue_algorithm_impl.h (stable_sort): Forward
execution policy.
(mismatch): Forward execution policy.
(equal): Qualify call to std::equal().
(partial_sort): Forward execution policy.
(inplace_merge): Forward execution policy.

>From ce0ae4e065692da6d0dcdb0f7ba5d2f3db4d3ec7 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Fri, 19 Apr 2019 11:16:44 -0700
Subject: [PATCH] Cleanup algorithm implementations

	* include/pstl/glue_algorithm_impl.h (stable_sort): Forward
execution policy.
	(mismatch): Forward execution policy.
	(equal): Qualify call to std::equal().
	(partial_sort): Forward execution policy.
	(inplace_merge): Forward execution policy.
---
 libstdc++-v3/include/pstl/glue_algorithm_impl.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libstdc++-v3/include/pstl/glue_algorithm_impl.h b/libstdc++-v3/include/pstl/glue_algorithm_impl.h
index db5ef2b76f5..1c4a3511a48 100644
--- a/libstdc++-v3/include/pstl/glue_algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/glue_algorithm_impl.h
@@ -674,7 +674,7 @@ __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
 stable_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last)
 {
 typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _InputType;
-std::stable_sort(__exec, __first, __last, std::less<_InputType>());
+std::stable_sort(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
 }
 
 // [mismatch]
@@ -696,8 +696,8 @@ __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_Fo
 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
  _BinaryPredicate __pred)
 {
-return std::mismatch(__exec, __first1, __last1, __first2, std::next(__first2, std::distance(__first1, __last1)),
- __pred);
+return std::mismatch(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
+			 std::next(__first2, std::distance(__first1, __last1)), __pred);
 }
 
 template 
@@ -757,8 +757,8 @@ __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
   _ForwardIterator2 __last2)
 {
-return equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
- __pstl::__internal::__pstl_equal());
+return std::equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
+  __pstl::__internal::__pstl_equal());
 }
 
 // [alg.move]
@@ -798,7 +798,7 @@ partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAc
  _RandomAccessIterator __last)
 {
 typedef typename iterator_traits<_RandomAccessIterator>::value_type _InputType;
-std::partial_sort(__exec, __first, __middle, __last, std::less<_InputType>());
+std::partial_sort(std::forward<_ExecutionPolicy>(__exec), __first, __middle, __last, std::less<_InputType>());
 }
 
 // [partial.sort.copy]
@@ -908,7 +908,7 @@ inplace_merge(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _Bidire
   _BidirectionalIterator __last)
 {
 typedef typename std::iterator_traits<_BidirectionalIterator>::value_type _InputType;
-std::inplace_merge(__exec, __first, __middle, __last, std::less<_InputType>());
+std::inplace_merge(std::forward<_ExecutionPolicy>(__exec), __first, __middle, __last, std::less<_InputType>());
 }
 
 // [includes]
-- 
2.20.1



[PATCH] Delegate PSTL configuration to pstl/pstl_config.h

2019-04-18 Thread Thomas Rodgers

 * include/bits/c++config: Remove explicit PSTL configuration
 macros and use definitions from .

>From 198662c6e2ee6b1a6b363c2a515c05ef1ca949bd Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Thu, 18 Apr 2019 16:55:40 -0700
Subject: [PATCH] Delegate PSTL configuration to pstl/pstl_config.h

	 * include/bits/c++config: Remove explicit PSTL configuration
	 macros and use definitions from .
---
 libstdc++-v3/include/bits/c++config | 82 +
 1 file changed, 1 insertion(+), 81 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index ef8ba96737b..5016f4853de 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -682,90 +682,10 @@ namespace std
 #  define __PSTL_USE_PAR_POLICIES 1
 # endif
 
-# if __PSTL_USE_PAR_POLICIES
-#  if !defined(__PSTL_PAR_BACKEND_TBB)
-#   define __PSTL_PAR_BACKEND_TBB 1
-#  endif
-# else
-#  undef __PSTL_PAR_BACKEND_TBB
-# endif
-
 # define __PSTL_ASSERT(_Condition) __glibcxx_assert(_Condition)
 # define __PSTL_ASSERT_MSG(_Condition, _Message) __glibcxx_assert(_Condition)
 
-
-# define __PSTL_PRAGMA(x) _Pragma (#x)
-
-# define __PSTL_STRING_AUX(x) #x
-# define __PSTL_STRING(x) __PSTL_STRING_AUX(x)
-# define __PSTL_STRING_CONCAT(x, y) x#y
-
-# define __PSTL_GCC_VERSION (__GNUC__ * 1 + __GNUC_MINOR__ * 100 + \
-			 __GNUC_PATCHLEVEL__)
-
-// Enable SIMD for compilers that support OpenMP 4.0
-# if (__PSTL_GCC_VERSION >= 40900)
-#  define __PSTL_PRAGMA_SIMD __PSTL_PRAGMA(omp simd)
-#define __PSTL_PRAGMA_DECLARE_SIMD __PSTL_PRAGMA(omp declare simd)
-#  define __PSTL_PRAGMA_SIMD_REDUCTION(PRM) __PSTL_PRAGMA(omp simd reduction(PRM))
-# else //no simd
-#  define __PSTL_PRAGMA_SIMD
-#  define __PSTL_PRAGMA_SIMD_REDUCTION(PRM)
-# endif //Enable SIMD
-
-#define __PSTL_PRAGMA_SIMD_SCAN(PRM)
-#define __PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
-#define __PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
-
-#define __PSTL_PRAGMA_FORCEINLINE
-
-// Should be defined to 1 for environments with a vendor implementation
-// of C++17 execution policies
-// #define __PSTL_CPP17_EXECUTION_POLICIES_PRESENT (_MSC_VER >= 1912)
-// TODO define libstdc++ policies
-
-# define __PSTL_CPP14_2RANGE_MISMATCH_EQUAL_PRESENT \
-  (__cplusplus >= 201300L || __cpp_lib_robust_nonmodifying_seq_ops == 201304)
-# define __PSTL_CPP14_MAKE_REVERSE_ITERATOR_PRESENT \
-  (__cplusplus >= 201402L || __cpp_lib_make_reverse_iterator == 201402)
-# define __PSTL_CPP14_INTEGER_SEQUENCE_PRESENT (__cplusplus >= 201402L)
-# define __PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT (__cplusplus >= 201402L)
-
-# if __PSTL_MONOTONIC_PRESENT
-#  define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM) \
-  __PSTL_PRAGMA(omp ordered simd monotonic(PRM))
-#  define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2) \
-  __PSTL_PRAGMA(omp ordered simd monotonic(PRM1, PRM2))
-# else
-#  define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM)
-#  define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2)
-# endif
-
-// Declaration of reduction functor, where
-// NAME - the name of the functor
-// OP - type of the callable object with the reduction operation
-// omp_in - refers to the local partial result
-// omp_out - refers to the final value of the combiner operator
-// omp_priv - refers to the private copy of the initial value
-// omp_orig - refers to the original variable to be reduced
-#define __PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)  \
-__PSTL_PRAGMA(omp declare reduction(NAME : OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
-
-# define __PSTL_PRAGMA_VECTOR_UNALIGNED
-# define __PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
-# define __PSTL_PRAGMA_LOCATION
-
-# define __PSTL_PRAGMA_MESSAGE_IMPL(x) \
-  __PSTL_PRAGMA(message(__PSTL_STRING_CONCAT(__PSTL_PRAGMA_LOCATION, x)))
-# define __PSTL_PRAGMA_MESSAGE_POLICIES(x) __PSTL_PRAGMA_MESSAGE_IMPL(x)
-
-//Too many warnings in output, switched off
-# define __PSTL_PRAGMA_MESSAGE(x)
-
-# if defined(__GLIBCXX__)
-#  define __PSTL_CPP11_STD_ROTATE_BROKEN \
-  (__PSTL_GCC_VERSION < 50100) //GCC 5.1 release
-# endif
+#include 
 
 #endif
 // End of prewritten config; the settings discovered at configure time follow.
-- 
2.20.1



[PATCH] Improve implementation of parallel equal()

2019-04-16 Thread Thomas Rodgers

* include/pstl/algorithm_impl.h
(__internal::__brick_equal): use "4 iterator" version of
std::equal().
(__internal::__brick_equal): use simd for random access
iterators on unsequenced execution policies.
(__internal::__pattern_equal): add "4 iterator" version
(__internal::__pattern_equal): dispatch to simd __brick_equal
for vector-only execution policies.
(__internal::__pattern_equal): disptach to __parallel_or for
parallel execution policies.
* include/pstl/glue_algorithm_impl.h
(std::equal): dispatch to "4 iterator" version of
__internal::__pattern_equal().

>From 7a927774dfac3fef6d736cf29671c7d7df38aaed Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Tue, 16 Apr 2019 12:26:52 -0700
Subject: [PATCH] Improve implementation of parallel equal()

	* include/pstl/algorithm_impl.h
	(__internal::__brick_equal): use "4 iterator" version of
	std::equal().
	(__internal::__brick_equal): use simd for random access
	iterators on unsequenced execution policies.
	(__internal::__pattern_equal): add "4 iterator" version
	(__internal::__pattern_equal): dispatch to simd __brick_equal
	for vector-only execution policies.
	(__internal::__pattern_equal): disptach to __parallel_or for
	parallel execution policies.
	* include/pstl/glue_algorithm_impl.h
	(std::equal): dispatch to "4 iterator" version of
	__internal::__pattern_equal().
---
 libstdc++-v3/include/pstl/algorithm_impl.h| 57 +++
 .../include/pstl/glue_algorithm_impl.h|  2 +-
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index d39e99add05..511e688c3f6 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -404,6 +404,63 @@ __pattern_walk3(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1, _Ran
 // equal
 //
 
+template 
+bool
+__brick_equal(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
+  _ForwardIterator2 __last2, _BinaryPredicate __p, /* IsVector = */ std::false_type) noexcept
+{
+return std::equal(__first1, __last1, __first2, __last2, __p);
+}
+
+template 
+bool
+__brick_equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
+  _RandomAccessIterator2 __last2, _BinaryPredicate __p, /* is_vector = */ std::true_type) noexcept
+{
+if (__last1 - __first1 != __last2 - __first2)
+return false;
+
+return __unseq_backend::__simd_first(__first1, __last1 - __first1, __first2,
+ __internal::__not_pred<_BinaryPredicate>(__p))
+   .first == __last1;
+}
+
+template 
+bool
+__pattern_equal(_ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
+_ForwardIterator2 __last2, _BinaryPredicate __p, _IsVector __is_vector, /* is_parallel = */
+std::false_type) noexcept
+{
+return __internal::__brick_equal(__first1, __last1, __first2, __last2, __p, __is_vector);
+}
+
+#if _PSTL_USE_PAR_POLICIES
+template 
+bool
+__pattern_equal(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
+_RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __p,
+_IsVector __is_vector, /*is_parallel=*/std::true_type)
+{
+if (__last1 - __first1 != __last2 - __first2)
+return false;
+
+return __internal::__except_handler([&]() {
+return !__internal::__parallel_or(
+std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+[__first1, __first2, __p, __is_vector](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+return !__internal::__brick_equal(__i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1),
+  __p, __is_vector);
+});
+});
+}
+#endif
+
+//
+// equal version for sequences with equal length
+//
+
 template 
 bool
 __brick_equal(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __p,
diff --git a/libstdc++-v3/include/pstl/glue_algorithm_impl.h b/libstdc++-v3/include/pstl/glue_algorithm_impl.h
index 88ce93fca41..db5ef2b76f5 100644
--- a/libstdc++-v3/include/pstl/glue_algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/glue_algorithm_impl.h
@@ -757,7 +757,7 @@ __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal

Re: [PATCH] Uglify identifiers missed in previous commit(s)

2019-04-12 Thread Thomas Rodgers


Tested x86_64-linux, committed to trunk.

Jonathan Wakely writes:

> On 11/04/19 21:15 -0700, Thomas Rodgers wrote:
>>
>>   * include/pstl/algorithm_impl.h: Uglify identfiers.
>>   * include/pstl/numeric_impl.h:  Uglify identfiers.
>>   * include/pstl/parallel_backend_tbb.h: Uglify identfiers.
>
> OK for trunk, thanks.



[PATCH] Uglify identifiers missed in previous commit(s)

2019-04-11 Thread Thomas Rodgers

   * include/pstl/algorithm_impl.h: Uglify identfiers.
   * include/pstl/numeric_impl.h:  Uglify identfiers.
   * include/pstl/parallel_backend_tbb.h: Uglify identfiers.
   
>From b75813e885c50e667a1474c1d0e1fc47ee893d6e Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Thu, 11 Apr 2019 19:42:50 -0700
Subject: [PATCH] Uglify identifiers missed in previous commit(s)

   * include/pstl/algorithm_impl.h: Uglify identfiers.
   * include/pstl/numeric_impl.h:  Uglify identfiers.
   * include/pstl/parallel_backend_tbb.h: Uglify identfiers.
---
 libstdc++-v3/include/pstl/algorithm_impl.h| 22 +--
 libstdc++-v3/include/pstl/numeric_impl.h  |  2 +-
 .../include/pstl/parallel_backend_tbb.h   |  5 +++--
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index b0d60baae14..d39e99add05 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -283,20 +283,20 @@ __pattern_walk2(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardI
 template 
 _ForwardIterator2
-__pattern_walk2_n(_ExecutionPolicy&&, _ForwardIterator1 __first1, _Size n, _ForwardIterator2 __first2, _Function f,
+__pattern_walk2_n(_ExecutionPolicy&&, _ForwardIterator1 __first1, _Size __n, _ForwardIterator2 __first2, _Function __f,
   _IsVector is_vector, /*parallel=*/std::false_type) noexcept
 {
-return __internal::__brick_walk2_n(__first1, n, __first2, f, is_vector);
+return __internal::__brick_walk2_n(__first1, __n, __first2, __f, is_vector);
 }
 
 template 
 _RandomAccessIterator2
-__pattern_walk2_n(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1, _Size n, _RandomAccessIterator2 __first2,
-  _Function f, _IsVector is_vector, /*parallel=*/std::true_type)
+__pattern_walk2_n(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1, _Size __n, _RandomAccessIterator2 __first2,
+  _Function __f, _IsVector __is_vector, /*parallel=*/std::true_type)
 {
-return __internal::__pattern_walk2(std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + n, __first2, f, is_vector,
-   std::true_type());
+return __internal::__pattern_walk2(std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n, __first2, __f,
+   __is_vector, std::true_type());
 }
 
 template 
@@ -1033,7 +1033,7 @@ __pattern_copy_if(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _Ran
 return __internal::__except_handler([&__exec, __n, __first, __result, __is_vector, __pred, &__mask_buf]() {
 bool* __mask = __mask_buf.get();
 _DifferenceType __m{};
-__par_backend::parallel_strict_scan(
+__par_backend::__parallel_strict_scan(
 std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
 [=](_DifferenceType __i, _DifferenceType __len) { // Reduce
 return __internal::__brick_calc_mask_1<_DifferenceType>(__first + __i, __first + (__i + __len), __mask + __i,
@@ -1182,7 +1182,7 @@ __remove_elements(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardI
 __mask += __min;
 _DifferenceType __m{};
 // 2. Elements that doesn't satisfy pred are moved to result
-__par_backend::parallel_strict_scan(
+__par_backend::__parallel_strict_scan(
 std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
 [__mask, __is_vector](_DifferenceType __i, _DifferenceType __len) {
 return __internal::__brick_count(__mask + __i, __mask + __i + __len, [](bool __val) { return __val; }, __is_vector);
@@ -1309,7 +1309,7 @@ __pattern_unique_copy(_ExecutionPolicy&& __exec, _RandomAccessIterator __first,
 return __internal::__except_handler([&__exec, __n, __first, __result, __pred, __is_vector, &__mask_buf]() {
 bool* __mask = __mask_buf.get();
 _DifferenceType __m{};
-__par_backend::parallel_strict_scan(
+__par_backend::__parallel_strict_scan(
 std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
 [=](_DifferenceType __i, _DifferenceType __len) -> _DifferenceType { // Reduce
 _DifferenceType __extra = 0;
@@ -2033,7 +2033,7 @@ __pattern_partition_copy(_ExecutionPolicy&& __exec, _RandomAccessIterator __firs
 return __internal::__except_handler([&__exec, __n, __first, __out_true, __out_false, __is_vector, __pred, &__mask_buf]() {
 bool* __mask = __mask_buf.get();
 _ReturnType __m{};
-__par_backend::parallel_strict_scan(
+   

Re: [PATCH] Replace direct PSTL uses of assert() with a macro

2019-04-11 Thread Thomas Rodgers
 removed (patch version applied attached).

Tested x86_64-linux, committed to trunk.

Jonathan Wakely writes:

> On 10/04/19 23:59 +0100, Jonathan Wakely wrote:
>>On 10/04/19 15:57 -0700, Thomas Rodgers wrote:
>>>Ok, lets try this again.
>>>
>>>>On 09/04/19 15:23 -0700, Thomas Rodgers wrote:
>>>>>This also replaces calls to __TBB_ASSERT so that there are two macro
>>>>>definitions provided by c++config -
>>>>>   __PSTL_ASSERT(_Condition)
>>>>>   __PSTL_ASSERT_MSG(_Condition, _Message)
>>>>>
>>>>>   * include/bits/c++config:
>>>>>   Add definition for __PSTL_ASSERT.
>>>>>   Add definition for __PSTL_ASSERT_MSG.
>>>>>   * include/pstl/algorithm_impl.h: Replace use of assert().
>>>>>   * include/pstl/numeric_impl.h: Replace use of assert().
>>>>>   * include/pstl/parallel_backend_tbb.h:
>>>>>   Replace use of assert().
>>>>>   Replace use of __TBB_ASSERT().
>>>>>
>>>>>   * include/pstl/parallel_backend_utils.h: Replace use of assert().
>>>
>>>Jonathan Wakely writes:
>>>>... you fix now ...
>>
>>Looks good, OK for trunk, thanks.
>
> Looks like parallel_backend_tbb.h still includes  after this
> patch. Assuming tests still pass with that removed, that tweak to the
> patch is pre-approved.

>From 87483056b4fecb08455443b34b9658f4d7289a74 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Fri, 5 Apr 2019 15:27:35 -0700
Subject: [PATCH] Replace direct PSTL uses of assert() with a macro

This also replaces calls to __TBB_ASSERT so that there are two macro
definitions provided by c++config -
	__PSTL_ASSERT(_Condition)
	__PSTL_ASSERT_MSG(_Condition, _Message)

	* include/bits/c++config:
	Add definition for __PSTL_ASSERT.
	Add definition for __PSTL_ASSERT_MSG.
	* include/pstl/algorithm_impl.h: Replace use of assert().
	* include/pstl/numeric_impl.h: Replace use of assert().
	* include/pstl/parallel_backend_tbb.h:
	Replace use of assert().
	Replace use of __TBB_ASSERT().

	* include/pstl/parallel_backend_utils.h: Replace use of assert().
---
 libstdc++-v3/include/bits/c++config   |  4 
 libstdc++-v3/include/pstl/algorithm_impl.h| 10 +-
 libstdc++-v3/include/pstl/numeric_impl.h  |  4 ++--
 libstdc++-v3/include/pstl/parallel_backend_tbb.h  |  9 -
 .../include/pstl/parallel_backend_utils.h | 15 +++
 5 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 66420a9a3f2..ef8ba96737b 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -690,6 +690,10 @@ namespace std
 #  undef __PSTL_PAR_BACKEND_TBB
 # endif
 
+# define __PSTL_ASSERT(_Condition) __glibcxx_assert(_Condition)
+# define __PSTL_ASSERT_MSG(_Condition, _Message) __glibcxx_assert(_Condition)
+
+
 # define __PSTL_PRAGMA(x) _Pragma (#x)
 
 # define __PSTL_STRING_AUX(x) #x
diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index e06bf60151e..b0d60baae14 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -2731,8 +2731,8 @@ __pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwa
  return !__internal::__parallel_or(
 std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
 [__first1, __last1, __first2, __last2, &__comp](_ForwardIterator2 __i, _ForwardIterator2 __j) {
-assert(__j > __i);
-//assert(__j - __i > 1);
+__PSTL_ASSERT(__j > __i);
+//__PSTL_ASSERT(__j - __i > 1);
 
 //1. moving boundaries to "consume" subsequence of equal elements
 auto __is_equal = [&__comp](_ForwardIterator2 __a, _ForwardIterator2 __b) -> bool {
@@ -2756,8 +2756,8 @@ __pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwa
 //2. testing is __a subsequence of the second range included into the first range
 auto __b = std::lower_bound(__first1, __last1, *__i, __comp);
 
-assert(!__comp(*(__last1 - 1), *__b));
-assert(!__comp(*(__j - 1), *__i));
+__PSTL_ASSERT(!__comp(*(__last1 - 1), *__b));
+__PSTL_ASSERT(!__comp(*(__j - 1), *__i));
 return !std::includes(__b, __last1, __i, __j, __comp);
 });
 });
@@ -2948,7 +2948,7 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _
 }
 
 const auto __m2 = _

Re: [PATCH] Replace direct PSTL uses of assert() with a macro

2019-04-10 Thread Thomas Rodgers
Ok, lets try this again.

> On 09/04/19 15:23 -0700, Thomas Rodgers wrote:
>>This also replaces calls to __TBB_ASSERT so that there are two macro
>>definitions provided by c++config -
>>  __PSTL_ASSERT(_Condition)
>>  __PSTL_ASSERT_MSG(_Condition, _Message)
>>
>>  * include/bits/c++config:
>>  Add definition for __PSTL_ASSERT.
>>  Add definition for __PSTL_ASSERT_MSG.
>>  * include/pstl/algorithm_impl.h: Replace use of assert().
>>  * include/pstl/numeric_impl.h: Replace use of assert().
>>  * include/pstl/parallel_backend_tbb.h:
>>  Replace use of assert().
>>  Replace use of __TBB_ASSERT().
>>
>>  * include/pstl/parallel_backend_utils.h: Replace use of assert().

Jonathan Wakely writes:
> ... you fix now ...

>From fdd06789266d7703c48f53c23a85a36144649334 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Fri, 5 Apr 2019 15:27:35 -0700
Subject: [PATCH] Replace direct PSTL uses of assert() with a macro

This also replaces calls to __TBB_ASSERT so that there are two macro
definitions provided by c++config -
	__PSTL_ASSERT(_Condition)
	__PSTL_ASSERT_MSG(_Condition, _Message)

	* include/bits/c++config:
	Add definition for __PSTL_ASSERT.
	Add definition for __PSTL_ASSERT_MSG.
	* include/pstl/algorithm_impl.h: Replace use of assert().
	* include/pstl/numeric_impl.h: Replace use of assert().
	* include/pstl/parallel_backend_tbb.h:
	Replace use of assert().
	Replace use of __TBB_ASSERT().

	* include/pstl/parallel_backend_utils.h: Replace use of assert().
---
 libstdc++-v3/include/bits/c++config   |  4 
 libstdc++-v3/include/pstl/algorithm_impl.h| 10 +-
 libstdc++-v3/include/pstl/numeric_impl.h  |  4 ++--
 libstdc++-v3/include/pstl/parallel_backend_tbb.h  |  8 
 .../include/pstl/parallel_backend_utils.h | 15 +++
 5 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 66420a9a3f2..ef8ba96737b 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -690,6 +690,10 @@ namespace std
 #  undef __PSTL_PAR_BACKEND_TBB
 # endif
 
+# define __PSTL_ASSERT(_Condition) __glibcxx_assert(_Condition)
+# define __PSTL_ASSERT_MSG(_Condition, _Message) __glibcxx_assert(_Condition)
+
+
 # define __PSTL_PRAGMA(x) _Pragma (#x)
 
 # define __PSTL_STRING_AUX(x) #x
diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index e06bf60151e..b0d60baae14 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -2731,8 +2731,8 @@ __pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwa
  return !__internal::__parallel_or(
 std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
 [__first1, __last1, __first2, __last2, &__comp](_ForwardIterator2 __i, _ForwardIterator2 __j) {
-assert(__j > __i);
-//assert(__j - __i > 1);
+__PSTL_ASSERT(__j > __i);
+//__PSTL_ASSERT(__j - __i > 1);
 
 //1. moving boundaries to "consume" subsequence of equal elements
 auto __is_equal = [&__comp](_ForwardIterator2 __a, _ForwardIterator2 __b) -> bool {
@@ -2756,8 +2756,8 @@ __pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwa
 //2. testing is __a subsequence of the second range included into the first range
 auto __b = std::lower_bound(__first1, __last1, *__i, __comp);
 
-assert(!__comp(*(__last1 - 1), *__b));
-assert(!__comp(*(__j - 1), *__i));
+__PSTL_ASSERT(!__comp(*(__last1 - 1), *__b));
+__PSTL_ASSERT(!__comp(*(__j - 1), *__i));
 return !std::includes(__b, __last1, __i, __j, __comp);
 });
 });
@@ -2948,7 +2948,7 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _
 }
 
 const auto __m2 = __left_bound_seq_2 - __first2;
-assert(__m1 == 0 || __m2 == 0);
+__PSTL_ASSERT(__m1 == 0 || __m2 == 0);
 if (__m2 > __set_algo_cut_off)
 {
 auto __res_or = __result;
diff --git a/libstdc++-v3/include/pstl/numeric_impl.h b/libstdc++-v3/include/pstl/numeric_impl.h
index 49a4abf5a95..738a61d92f6 100644
--- a/libstdc++-v3/include/pstl/numeric_impl.h
+++ b/libstdc++-v3/include/pstl/numeric_impl.h
@@ -314,7 +314,7 @@ _ForwardIterator2
 __brick_adjacent_difference(_ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first,
 BinaryOperation __op, /*is_vector=*/std::true_type) noexcept

[PATCH] Replace direct PSTL uses of assert() with a macro

2019-04-09 Thread Thomas Rodgers
This also replaces calls to __TBB_ASSERT so that there are two macro
definitions provided by c++config -
__PSTL_ASSERT(_Condition)
__PSTL_ASSERT_MSG(_Condition, _Message)

* include/bits/c++config:
Add definition for __PSTL_ASSERT.
Add definition for __PSTL_ASSERT_MSG.
* include/pstl/algorithm_impl.h: Replace use of assert().
* include/pstl/numeric_impl.h: Replace use of assert().
* include/pstl/parallel_backend_tbb.h:
Replace use of assert().
Replace use of __TBB_ASSERT().

* include/pstl/parallel_backend_utils.h: Replace use of assert().

>From d95934a0f325e0934ada829378c3c0dfd6b3628c Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Fri, 5 Apr 2019 15:27:35 -0700
Subject: [PATCH] Replace direct PSTL uses of assert() with a macro

This also replaces calls to __TBB_ASSERT so that there are two macro
definitions provided by c++config -
	__PSTL_ASSERT(_Condition)
	__PSTL_ASSERT_MSG(_Condition, _Message)

	* include/bits/c++config:
	Add definition for __PSTL_ASSERT.
	Add definition for __PSTL_ASSERT_MSG.
	* include/pstl/algorithm_impl.h: Replace use of assert().
	* include/pstl/numeric_impl.h: Replace use of assert().
	* include/pstl/parallel_backend_tbb.h:
	Replace use of assert().
	Replace use of __TBB_ASSERT().

	* include/pstl/parallel_backend_utils.h: Replace use of assert().
---
 libstdc++-v3/include/bits/c++config   |  4 
 libstdc++-v3/include/pstl/algorithm_impl.h| 14 +++---
 libstdc++-v3/include/pstl/numeric_impl.h  |  8 
 libstdc++-v3/include/pstl/parallel_backend_tbb.h  | 11 ++-
 .../include/pstl/parallel_backend_utils.h | 15 +++
 5 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 66420a9a3f2..8dd04f218b4 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -690,6 +690,10 @@ namespace std
 #  undef __PSTL_PAR_BACKEND_TBB
 # endif
 
+# define __PSTL_ASSERT(_Condition) (__glibcxx_assert(_Condition))
+# define __PSTL_ASSERT_MSG(_Condition, _Message) (__glibcxx_assert(_Condition))
+
+
 # define __PSTL_PRAGMA(x) _Pragma (#x)
 
 # define __PSTL_STRING_AUX(x) #x
diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index e06bf60151e..a42d3993d1b 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -1309,7 +1309,7 @@ __pattern_unique_copy(_ExecutionPolicy&& __exec, _RandomAccessIterator __first,
 return __internal::__except_handler([&__exec, __n, __first, __result, __pred, __is_vector, &__mask_buf]() {
 bool* __mask = __mask_buf.get();
 _DifferenceType __m{};
-__par_backend::parallel_strict_scan(
+__par_backend::__parallel_strict_scan(
 std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
 [=](_DifferenceType __i, _DifferenceType __len) -> _DifferenceType { // Reduce
 _DifferenceType __extra = 0;
@@ -2731,8 +2731,8 @@ __pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwa
  return !__internal::__parallel_or(
 std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
 [__first1, __last1, __first2, __last2, &__comp](_ForwardIterator2 __i, _ForwardIterator2 __j) {
-assert(__j > __i);
-//assert(__j - __i > 1);
+__PSTL_ASSERT(__j > __i);
+//__PSTL_ASSERT(__j - __i > 1);
 
 //1. moving boundaries to "consume" subsequence of equal elements
 auto __is_equal = [&__comp](_ForwardIterator2 __a, _ForwardIterator2 __b) -> bool {
@@ -2756,8 +2756,8 @@ __pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwa
 //2. testing is __a subsequence of the second range included into the first range
 auto __b = std::lower_bound(__first1, __last1, *__i, __comp);
 
-assert(!__comp(*(__last1 - 1), *__b));
-assert(!__comp(*(__j - 1), *__i));
+__PSTL_ASSERT(!__comp(*(__last1 - 1), *__b));
+__PSTL_ASSERT(!__comp(*(__j - 1), *__i));
 return !std::includes(__b, __last1, __i, __j, __comp);
 });
 });
@@ -2801,7 +2801,7 @@ __parallel_set_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwar
 __internal::__brick_move(__buffer + __s.__buf_pos, __buffer + (__s.__buf_pos + __s.__len), __result + __s.__pos,
  __is_vector);
 };
-__par_backend::para

Re: [PATCH] Add PSTL internal namespace qualifications

2019-04-09 Thread Thomas Rodgers


Committed to trunk.

Thomas Rodgers writes:

> This patch adds additional internal namespace qualifications to the pstl
> implementation.
>
> From 35dba02035ebb5fd44ac0f06e25a81dfef05898f Mon Sep 17 00:00:00 2001
> From: Thomas Rodgers 
> Date: Thu, 28 Mar 2019 17:23:49 -0700
> Subject: [PATCH] Add namespace qualification for pstl-internal symbols
>
> Prevent ADL related weirdness.
>
>   * include/pstl/algorithm_impl.h: Add namespace qualification.
>   * include/pstl/execution_defs.h: Add namespace qualification.
>   * include/pstl/execution_impl.h: Add namespace qualification.
>   * include/pstl/numeric_impl.h: Add namespace qualification.
>   * include/pstl/parallel_backend_tbb.h: Add namespace qualification.
>   * include/pstl/unseq_backend_simd.h: Add namespace qualification.
>   * include/pstl/parallel_backend_utils.h: Include .
> ---
>  libstdc++-v3/include/pstl/algorithm_impl.h| 427 +-
>  libstdc++-v3/include/pstl/execution_defs.h|  10 +-
>  libstdc++-v3/include/pstl/execution_impl.h|  22 +-
>  libstdc++-v3/include/pstl/numeric_impl.h  |  30 +-
>  .../include/pstl/parallel_backend_tbb.h   |  49 +-
>  .../include/pstl/parallel_backend_utils.h |   1 +
>  .../include/pstl/unseq_backend_simd.h |   8 +-
>  7 files changed, 275 insertions(+), 272 deletions(-)
>
> diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h 
> b/libstdc++-v3/include/pstl/algorithm_impl.h
> index 9d8242873ab..e06bf60151e 100644
> --- a/libstdc++-v3/include/pstl/algorithm_impl.h
> +++ b/libstdc++-v3/include/pstl/algorithm_impl.h
> @@ -18,6 +18,7 @@
>  
>  #include "execution_impl.h"
>  #include "memory_impl.h"
> +#include "parallel_backend_utils.h"
>  #include "unseq_backend_simd.h"
>  
>  #if __PSTL_USE_PAR_POLICIES
> @@ -55,7 +56,7 @@ bool
>  __pattern_any_of(_ExecutionPolicy&&, _ForwardIterator __first, 
> _ForwardIterator __last, _Pred __pred,
>   _IsVector __is_vector, /*parallel=*/std::false_type) 
> noexcept
>  {
> -return __brick_any_of(__first, __last, __pred, __is_vector);
> +return __internal::__brick_any_of(__first, __last, __pred, __is_vector);
>  }
>  
>  #if __PSTL_USE_PAR_POLICIES
> @@ -64,10 +65,10 @@ bool
>  __pattern_any_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, 
> _ForwardIterator __last, _Pred __pred,
>   _IsVector __is_vector, /*parallel=*/std::true_type)
>  {
> -return __except_handler([&]() {
> -return __parallel_or(std::forward<_ExecutionPolicy>(__exec), 
> __first, __last,
> +return __internal::__except_handler([&]() {
> +   return 
> __internal::__parallel_or(std::forward<_ExecutionPolicy>(__exec), __first, 
> __last,
>   [__pred, __is_vector](_ForwardIterator __i, 
> _ForwardIterator __j) {
> - return __brick_any_of(__i, __j, __pred, 
> __is_vector);
> + return __internal::__brick_any_of(__i, __j, 
> __pred, __is_vector);
>   });
>  });
>  }
> @@ -111,7 +112,7 @@ __pattern_walk1(_ExecutionPolicy&&, _ForwardIterator 
> __first, _ForwardIterator _
>  _IsVector __is_vector,
>  /*parallel=*/std::false_type) noexcept
>  {
> -__brick_walk1(__first, __last, __f, __is_vector);
> +__internal::__brick_walk1(__first, __last, __f, __is_vector);
>  }
>  
>  #if __PSTL_USE_PAR_POLICIES
> @@ -121,10 +122,10 @@ __pattern_walk1(_ExecutionPolicy&& __exec, 
> _ForwardIterator __first, _ForwardIte
>  _IsVector __is_vector,
>  /*parallel=*/std::true_type)
>  {
> -__except_handler([&]() {
> +__internal::__except_handler([&]() {
>  
> __par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), 
> __first, __last,
>[__f, __is_vector](_ForwardIterator 
> __i, _ForwardIterator __j) {
> -  __brick_walk1(__i, __j, __f, 
> __is_vector);
> +  __internal::__brick_walk1(__i, 
> __j, __f, __is_vector);
>});
>  });
>  }
> @@ -144,7 +145,7 @@ void
>  __pattern_walk_brick(_ExecutionPolicy&& __exec, _ForwardIterator __first, 
> _ForwardIterator __last, _Brick __brick,
>   /*parallel=*/std::true_type)
>  {
> -__except_handler([&]() {
> +__internal::__except_handler([&]() {
>  
> __par_backend::__parallel_for(std::forward<_

Re: [PATCH] Add PSTL internal namespace qualifications

2019-04-05 Thread Thomas Rodgers
>From d95934a0f325e0934ada829378c3c0dfd6b3628c Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Fri, 5 Apr 2019 15:27:35 -0700
Subject: [PATCH] Replace direct PSTL uses of assert() with a macro

This also replaces calls to __TBB_ASSERT so that there are two macro
definitions provided by c++config -
	__PSTL_ASSERT(_Condition)
	__PSTL_ASSERT_MSG(_Condition, _Message)

	* include/bits/c++config:
	Add definition for __PSTL_ASSERT.
	Add definition for __PSTL_ASSERT_MSG.
	* include/pstl/algorithm_impl.h: Replace use of assert().
	* include/pstl/numeric_impl.h: Replace use of assert().
	* include/pstl/parallel_backend_tbb.h:
	Replace use of assert().
	Replace use of __TBB_ASSERT().

	* include/pstl/parallel_backend_utils.h: Replace use of assert().
---
 libstdc++-v3/include/bits/c++config   |  4 
 libstdc++-v3/include/pstl/algorithm_impl.h| 14 +++---
 libstdc++-v3/include/pstl/numeric_impl.h  |  8 
 libstdc++-v3/include/pstl/parallel_backend_tbb.h  | 11 ++-
 .../include/pstl/parallel_backend_utils.h | 15 +++
 5 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 66420a9a3f2..8dd04f218b4 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -690,6 +690,10 @@ namespace std
 #  undef __PSTL_PAR_BACKEND_TBB
 # endif
 
+# define __PSTL_ASSERT(_Condition) (__glibcxx_assert(_Condition))
+# define __PSTL_ASSERT_MSG(_Condition, _Message) (__glibcxx_assert(_Condition))
+
+
 # define __PSTL_PRAGMA(x) _Pragma (#x)
 
 # define __PSTL_STRING_AUX(x) #x
diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index e06bf60151e..a42d3993d1b 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -1309,7 +1309,7 @@ __pattern_unique_copy(_ExecutionPolicy&& __exec, _RandomAccessIterator __first,
 return __internal::__except_handler([&__exec, __n, __first, __result, __pred, __is_vector, &__mask_buf]() {
 bool* __mask = __mask_buf.get();
 _DifferenceType __m{};
-__par_backend::parallel_strict_scan(
+__par_backend::__parallel_strict_scan(
 std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
 [=](_DifferenceType __i, _DifferenceType __len) -> _DifferenceType { // Reduce
 _DifferenceType __extra = 0;
@@ -2731,8 +2731,8 @@ __pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwa
  return !__internal::__parallel_or(
 std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
 [__first1, __last1, __first2, __last2, &__comp](_ForwardIterator2 __i, _ForwardIterator2 __j) {
-assert(__j > __i);
-//assert(__j - __i > 1);
+__PSTL_ASSERT(__j > __i);
+//__PSTL_ASSERT(__j - __i > 1);
 
 //1. moving boundaries to "consume" subsequence of equal elements
 auto __is_equal = [&__comp](_ForwardIterator2 __a, _ForwardIterator2 __b) -> bool {
@@ -2756,8 +2756,8 @@ __pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwa
 //2. testing is __a subsequence of the second range included into the first range
 auto __b = std::lower_bound(__first1, __last1, *__i, __comp);
 
-assert(!__comp(*(__last1 - 1), *__b));
-assert(!__comp(*(__j - 1), *__i));
+__PSTL_ASSERT(!__comp(*(__last1 - 1), *__b));
+__PSTL_ASSERT(!__comp(*(__j - 1), *__i));
 return !std::includes(__b, __last1, __i, __j, __comp);
 });
 });
@@ -2801,7 +2801,7 @@ __parallel_set_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forwar
 __internal::__brick_move(__buffer + __s.__buf_pos, __buffer + (__s.__buf_pos + __s.__len), __result + __s.__pos,
  __is_vector);
 };
-__par_backend::parallel_strict_scan(
+__par_backend::__parallel_strict_scan(
 std::forward<_ExecutionPolicy>(__exec), __n1, _SetRange{0, 0, 0}, //-1, 0},
 [=](_DifferenceType __i, _DifferenceType __len) { // Reduce
 //[__b; __e) - a subrange of the first sequence, to reduce
@@ -2948,7 +2948,7 @@ __parallel_set_union_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _
 }
 
 const auto __m2 = __left_bound_seq_2 - __first2;
-assert(__m1 == 0 || __m2 == 0);
+__PSTL_ASSERT(__m1 == 0 || __m2 == 0);
 if (__m2 > __set_algo_cut_off)
 {
 auto __res_or = __result;
diff --git a/libstd

Re: [PATCH] Add PSTL internal namespace qualifications

2019-04-01 Thread Thomas Rodgers
>> We shouldn't include  in the std::lib, the uses of assert
>> should be changed to __glibcxx_assert instead (which is enabled by
>> defining _GLIBCXX_ASSERTIONS).
>>
>
> This has to come through one of the PSTL library configuration
> macros because the "right assert" upstream won't be __glibcxx_assert.

There are a number of locations in the upstream PSTL sources where
 is included and assert() is used. Additionally, the TBB
backend uses __TBB_ASSERT(). I'm going to follow up with a separate
patch that introduces __PSTL_ASSERT() and makes everything consistent,
with __PSTL_ASSERT expanding to __glibcxx_assert in libstdc++.

Tom.

Thomas Rodgers writes:

> Jonathan Wakely writes:
>
>> On 29/03/19 12:12 -0700, Thomas Rodgers wrote:
>>>Prevent ADL related weirdness.
>>>
>>> * include/pstl/algorithm_impl.h: Add namespace qualification.
>>> * include/pstl/execution_defs.h: Add namespace qualification.
>>> * include/pstl/execution_impl.h: Add namespace qualification.
>>> * include/pstl/numeric_impl.h: Add namespace qualification.
>>> * include/pstl/parallel_backend_tbb.h: Add namespace qualification.
>>> * include/pstl/unseq_backend_simd.h: Add namespace qualification.
>>> * include/pstl/parallel_backend_utils.h: Include .
>>
>> We shouldn't include  in the std::lib, the uses of assert
>> should be changed to __glibcxx_assert instead (which is enabled by
>> defining _GLIBCXX_ASSERTIONS).
>>
>
> This has to come through one of the PSTL library configuration
> macros because the "right assert" upstream won't be __glibcxx_assert.
>
>>>@@ -285,7 +286,7 @@ _ForwardIterator2
>>> __pattern_walk2_n(_ExecutionPolicy&&, _ForwardIterator1 __first1, _Size n, 
>>> _ForwardIterator2 __first2, _Function f,
>>>   _IsVector is_vector, /*parallel=*/std::false_type) 
>>> noexcept
>>
>> I missed these before, but we have non-uglified 'n' and 'f' and
>> 'is_vector' here. Almost all uses of "is_vector" are inside a comment
>> like /*is_vector=*/ but here it's a real parameter name.
>>
>> In practice if users do something stupid like
>> #define n 123
>> #define f 456
>> then they won't be able to include these headers anyway, because
>> TBB uses those as parameter names (so users that are using these
>> headers with TBB can't defines such dumb macros). But when we get a
>> non-TBB backend that won't be the case, and we should be uglifying all
>> names declared in our own headers on principle.
>>
>>> {
>>>-return __brick_walk2_n(__first1, n, __first2, f, is_vector);
>>>+return __internal::__brick_walk2_n(__first1, n, __first2, f, is_vector);
>>> }
>>>
>>> template >> _Size, class _RandomAccessIterator2,
>>>@@ -294,7 +295,7 @@ _RandomAccessIterator2
>>> __pattern_walk2_n(_ExecutionPolicy&& __exec, _RandomAccessIterator1 
>>> __first1, _Size n, _RandomAccessIterator2 __first2,
>>>   _Function f, _IsVector is_vector, 
>>> /*parallel=*/std::true_type)
>>
>> And 'n' and 'f' here.
>>
>>> {
>>>-return __pattern_walk2(std::forward<_ExecutionPolicy>(__exec), 
>>>__first1, __first1 + n, __first2, f, is_vector,
>>>+return 
>>>__internal::__pattern_walk2(std::forward<_ExecutionPolicy>(__exec), 
>>>__first1, __first1 + n, __first2, f, is_vector,
>>>std::true_type());
>>> }
>>>
>>
>> We can fix the 'n' and 'f' and 'is_vector' names in another patch, for
>> this one please just remove  again and change assert(...) to
>> __glibcxx_assert(...).



Re: [PATCH] Add PSTL internal namespace qualifications

2019-04-01 Thread Thomas Rodgers


Jonathan Wakely writes:

> On 29/03/19 12:12 -0700, Thomas Rodgers wrote:
>>Prevent ADL related weirdness.
>>
>>  * include/pstl/algorithm_impl.h: Add namespace qualification.
>>  * include/pstl/execution_defs.h: Add namespace qualification.
>>  * include/pstl/execution_impl.h: Add namespace qualification.
>>  * include/pstl/numeric_impl.h: Add namespace qualification.
>>  * include/pstl/parallel_backend_tbb.h: Add namespace qualification.
>>  * include/pstl/unseq_backend_simd.h: Add namespace qualification.
>>  * include/pstl/parallel_backend_utils.h: Include .
>
> We shouldn't include  in the std::lib, the uses of assert
> should be changed to __glibcxx_assert instead (which is enabled by
> defining _GLIBCXX_ASSERTIONS).
>

This has to come through one of the PSTL library configuration
macros because the "right assert" upstream won't be __glibcxx_assert.

>>@@ -285,7 +286,7 @@ _ForwardIterator2
>> __pattern_walk2_n(_ExecutionPolicy&&, _ForwardIterator1 __first1, _Size n, 
>> _ForwardIterator2 __first2, _Function f,
>>   _IsVector is_vector, /*parallel=*/std::false_type) noexcept
>
> I missed these before, but we have non-uglified 'n' and 'f' and
> 'is_vector' here. Almost all uses of "is_vector" are inside a comment
> like /*is_vector=*/ but here it's a real parameter name.
>
> In practice if users do something stupid like
> #define n 123
> #define f 456
> then they won't be able to include these headers anyway, because
> TBB uses those as parameter names (so users that are using these
> headers with TBB can't defines such dumb macros). But when we get a
> non-TBB backend that won't be the case, and we should be uglifying all
> names declared in our own headers on principle.
>
>> {
>>-return __brick_walk2_n(__first1, n, __first2, f, is_vector);
>>+return __internal::__brick_walk2_n(__first1, n, __first2, f, is_vector);
>> }
>>
>> template > class _RandomAccessIterator2,
>>@@ -294,7 +295,7 @@ _RandomAccessIterator2
>> __pattern_walk2_n(_ExecutionPolicy&& __exec, _RandomAccessIterator1 
>> __first1, _Size n, _RandomAccessIterator2 __first2,
>>   _Function f, _IsVector is_vector, 
>> /*parallel=*/std::true_type)
>
> And 'n' and 'f' here.
>
>> {
>>-return __pattern_walk2(std::forward<_ExecutionPolicy>(__exec), __first1, 
>>__first1 + n, __first2, f, is_vector,
>>+return 
>>__internal::__pattern_walk2(std::forward<_ExecutionPolicy>(__exec), __first1, 
>>__first1 + n, __first2, f, is_vector,
>>std::true_type());
>> }
>>
>
> We can fix the 'n' and 'f' and 'is_vector' names in another patch, for
> this one please just remove  again and change assert(...) to
> __glibcxx_assert(...).



[PATCH] Add PSTL internal namespace qualifications

2019-03-29 Thread Thomas Rodgers
This patch adds additional internal namespace qualifications to the pstl
implementation.

>From 35dba02035ebb5fd44ac0f06e25a81dfef05898f Mon Sep 17 00:00:00 2001
From: Thomas Rodgers 
Date: Thu, 28 Mar 2019 17:23:49 -0700
Subject: [PATCH] Add namespace qualification for pstl-internal symbols

Prevent ADL related weirdness.

	* include/pstl/algorithm_impl.h: Add namespace qualification.
	* include/pstl/execution_defs.h: Add namespace qualification.
	* include/pstl/execution_impl.h: Add namespace qualification.
	* include/pstl/numeric_impl.h: Add namespace qualification.
	* include/pstl/parallel_backend_tbb.h: Add namespace qualification.
	* include/pstl/unseq_backend_simd.h: Add namespace qualification.
	* include/pstl/parallel_backend_utils.h: Include .
---
 libstdc++-v3/include/pstl/algorithm_impl.h| 427 +-
 libstdc++-v3/include/pstl/execution_defs.h|  10 +-
 libstdc++-v3/include/pstl/execution_impl.h|  22 +-
 libstdc++-v3/include/pstl/numeric_impl.h  |  30 +-
 .../include/pstl/parallel_backend_tbb.h   |  49 +-
 .../include/pstl/parallel_backend_utils.h |   1 +
 .../include/pstl/unseq_backend_simd.h |   8 +-
 7 files changed, 275 insertions(+), 272 deletions(-)

diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index 9d8242873ab..e06bf60151e 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -18,6 +18,7 @@
 
 #include "execution_impl.h"
 #include "memory_impl.h"
+#include "parallel_backend_utils.h"
 #include "unseq_backend_simd.h"
 
 #if __PSTL_USE_PAR_POLICIES
@@ -55,7 +56,7 @@ bool
 __pattern_any_of(_ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred,
  _IsVector __is_vector, /*parallel=*/std::false_type) noexcept
 {
-return __brick_any_of(__first, __last, __pred, __is_vector);
+return __internal::__brick_any_of(__first, __last, __pred, __is_vector);
 }
 
 #if __PSTL_USE_PAR_POLICIES
@@ -64,10 +65,10 @@ bool
 __pattern_any_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred,
  _IsVector __is_vector, /*parallel=*/std::true_type)
 {
-return __except_handler([&]() {
-return __parallel_or(std::forward<_ExecutionPolicy>(__exec), __first, __last,
+return __internal::__except_handler([&]() {
+   return __internal::__parallel_or(std::forward<_ExecutionPolicy>(__exec), __first, __last,
  [__pred, __is_vector](_ForwardIterator __i, _ForwardIterator __j) {
- return __brick_any_of(__i, __j, __pred, __is_vector);
+ return __internal::__brick_any_of(__i, __j, __pred, __is_vector);
  });
 });
 }
@@ -111,7 +112,7 @@ __pattern_walk1(_ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator _
 _IsVector __is_vector,
 /*parallel=*/std::false_type) noexcept
 {
-__brick_walk1(__first, __last, __f, __is_vector);
+__internal::__brick_walk1(__first, __last, __f, __is_vector);
 }
 
 #if __PSTL_USE_PAR_POLICIES
@@ -121,10 +122,10 @@ __pattern_walk1(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIte
 _IsVector __is_vector,
 /*parallel=*/std::true_type)
 {
-__except_handler([&]() {
+__internal::__except_handler([&]() {
 __par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), __first, __last,
   [__f, __is_vector](_ForwardIterator __i, _ForwardIterator __j) {
-  __brick_walk1(__i, __j, __f, __is_vector);
+  __internal::__brick_walk1(__i, __j, __f, __is_vector);
   });
 });
 }
@@ -144,7 +145,7 @@ void
 __pattern_walk_brick(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Brick __brick,
  /*parallel=*/std::true_type)
 {
-__except_handler([&]() {
+__internal::__except_handler([&]() {
 __par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), __first, __last,
   [__brick](_ForwardIterator __i, _ForwardIterator __j) { __brick(__i, __j); });
 });
@@ -158,7 +159,7 @@ template 
 _ForwardIterator
 __brick_walk1_n(_ForwardIterator __first, _Size __n, _Function __f, /*_IsVectorTag=*/std::false_type)
 {
-return __for_each_n_it_serial(__first, __n,
+return __internal::__for_each_n_it_serial(__first, __n,
   [&__f](_ForwardIterator __it) { __f(*__it); }); // calling serial version
 }
 
@@ -175,7 +176,7 @@ _ForwardIterator
 __pattern_walk1_n(_ExecutionPolicy&&, _Forwar

Re: [PATCH] Integration of parallel standard algorithms for c++17

2019-03-27 Thread Thomas Rodgers


Jonathan Wakely writes:

> On 27/03/19 15:51 +0100, Thomas Schwinge wrote:
>>Hi!
>>
>>If that's of any help to document the version dependencies:
>
> Thanks for t his.
>
>>On Fri, 22 Mar 2019 00:04:30 +, Jonathan Wakely  
>>wrote:
>>> I keep forgetting to add that docs for this stuff will be coming some
>>> time next week, describing the TBB dependency that's needed to use
>>> these parallel algos.
>>
>>On an Ubuntu 12.10 x86_64 GNU/Linux system (yes, a bit old by now), I saw
>>all these test UNSUPPORTED.
>>
>>I then installed 'libtbb-dev' (and the implied 'libtbb2'; both version
>>4.0+r233-1), and then saw all? tests FAIL because of:
>>
>>[...]/libstdc++-v3/include/pstl/parallel_backend_tbb.h:25: fatal error: 
>> tbb/task_arena.h: No such file or directory
>>
>>I then manually installed the Ubuntu trusty (14.04LTS) version
>>4.2~20130725-1.1ubuntu1 packages, and then saw all? tests FAIL because
>>of:
>>
>>[...]/libstdc++-v3/include/pstl/parallel_backend_tbb.h:29: error: #error 
>> Intel(R) Threading Building Blocks 2018 is required; older versions are not 
>> supported.
>
> Yes, that's a known dependency.
>
> Tom, I think check_effective_target_tbb-backend should probably check
> the TBB_VERSION_MAJOR macro  in  and fail if an
> older version is detected.
>

Ok, I'll look at adding that check.

> That will only help when running our tests though, not when users try
> to use the algos, so we probably need to fail more gracefully if the
> user has an odler TBB installed. If there's a header which is present
> in TBB-2018 but not older versions then  could check
> for that instead of (or as well as) .
>

Yes the TBB-2018 is a hard dependency in the Intel backend, but I can
likely make this more graceful. There is also a serial 'fallback' backend
currently in the works in the upstream, which would at least give
something to fallback to here.

>
>>So I suppose I need the most recent Ubuntu disco version 2018~U6-4
>>packages.  Because of:
>>
>>dpkg-deb: error: archive 'libtbb-dev_2018~U6-4_amd64.deb' contains not 
>> understood data member control.tar.xz, giving up
>>
>>..., I manually had to convert to '*.gz' files the'.xz' files inside of
>>these '*.deb' archives, which yet still failed to install:
>>
>>dpkg: dependency problems prevent configuration of libtbb2:amd64:
>> libtbb2:amd64 depends on libstdc++6 (>= 7); however:
>>  Version of libstdc++6:amd64 on system is 4.7.2-2ubuntu1.
>>
>>..., which isn't really a problem as I'll obviously be testing against a
>>new-enough GCC/libstdc++ ;-) -- so, installed these packages with
>>'--force-depends-version'.
>>
>>With that, the tests then all PASS for the default multilib, but all?
>>FAIL for '-m32' testing:
>>
>>[...]/ld: cannot find -ltbb
>>
>>There is no 32-bit 'libtbb' available.  I suppose the problem is that
>>'check_effective_target_tbb-backend' just does a 'preprocess' test
>>checking for existence of '', but doesn't actually try to
>>link, whereas all? the test cases specify '-ltbb' via 'dg-options'.
>
> Right. Jakub noticed the same issue.
>
>>That said, instead of specifying:
>>
>>// { dg-options "-std=gnu++17 -ltbb" }
>>// { dg-do run { target c++17 } }
>>// { dg-require-effective-target tbb-backend }
>>
>>... in all? these test case files, isn't there some DejaGnu directive
>>that checks whether support is available (else UNSUPPORTED), while also
>>adding the necessary compiler options (here: '-ltbb')?
>
> I don't think we can do that in one go, can we?
>
> We can add something so { dg-add-options tbb } adds the required
> options, but I don't think it will make it UNSUPPORTED when necessary.
> Maybe I'm missing something.
>
>>Also, shouldn't 'check_effective_target_tbb-backend' (and also some of
>>the other checks in 'libstdc++-v3/testsuite/lib/libstdc++.exp'?) be using
>>'check_v3_target_prop_cached' to avoid checking the same things again and
>>again?
>
> Yes. I think it was probably written before that caching helper was
> added.



<    1   2   3   >