diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-08-19 15:42:27 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-08-19 15:42:27 +0000 |
commit | 58aa72c3c3338ead0407b495dee40e54ad1f8884 (patch) | |
tree | 77661da71b0527cb4fbcc5d090681c3470ada6c5 | |
parent | dee8cef0c1c1ebf85fceb5c37996ed12a2bec352 (diff) | |
download | gcc-58aa72c3c3338ead0407b495dee40e54ad1f8884.tar.gz |
Define std::atomic<T>::is_always_lock_free for C++17
* include/std/atomic (atomic::is_always_lock_free): Define.
* testsuite/29_atomics/atomic/60695.cc: Adjust dg-error lineno.
* testsuite/29_atomics/atomic/is_always_lock_free.cc: New.
* testsuite/29_atomics/atomic_integral/is_always_lock_free.cc: New.
* doc/xml/manual/status_cxx2017.xml: Update status.
* doc/html/*: Regenerate.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239622 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libstdc++-v3/ChangeLog | 7 | ||||
-rw-r--r-- | libstdc++-v3/doc/html/manual/status.html | 4 | ||||
-rw-r--r-- | libstdc++-v3/doc/xml/manual/status_cxx2017.xml | 3 | ||||
-rw-r--r-- | libstdc++-v3/include/std/atomic | 73 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/29_atomics/atomic/60695.cc | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/29_atomics/atomic/is_always_lock_free.cc | 32 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/29_atomics/atomic_integral/is_always_lock_free.cc | 43 |
7 files changed, 159 insertions, 5 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2a3e6947304..727285a8043 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,12 @@ 2016-08-19 Jonathan Wakely <jwakely@redhat.com> + * include/std/atomic (atomic::is_always_lock_free): Define. + * testsuite/29_atomics/atomic/60695.cc: Adjust dg-error lineno. + * testsuite/29_atomics/atomic/is_always_lock_free.cc: New. + * testsuite/29_atomics/atomic_integral/is_always_lock_free.cc: New. + * doc/xml/manual/status_cxx2017.xml: Update status. + * doc/html/*: Regenerate. + * include/experimental/tuple (apply): Qualify call to __apply_impl. * include/std/tuple (apply): Likewise. * testsuite/experimental/system_error/value.cc: Fix ambiguities in diff --git a/libstdc++-v3/doc/html/manual/status.html b/libstdc++-v3/doc/html/manual/status.html index ba2fa905fd9..64606393711 100644 --- a/libstdc++-v3/doc/html/manual/status.html +++ b/libstdc++-v3/doc/html/manual/status.html @@ -718,11 +718,11 @@ Feature-testing recommendations for C++</a>. <a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0392r0.pdf" target="_top"> P0392R0 </a> - </td><td align="center"> No </td><td align="left"> </td></tr><tr bgcolor="#C8B0B0"><td align="left"> constexpr <code class="code">atomic<T>::is_always_lock_free</code> </td><td align="left"> + </td><td align="center"> No </td><td align="left"> </td></tr><tr><td align="left"> constexpr <code class="code">atomic<T>::is_always_lock_free</code> </td><td align="left"> <a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0152r1.html" target="_top"> P0152R1 </a> - </td><td align="center"> No </td><td align="left"><code class="code"> __cpp_lib_atomic_is_always_lock_free >= 201603 </code></td></tr><tr><td align="left">A proposal to add <code class="code">shared_mutex</code> (untimed) (Revision 4)</td><td align="left"> + </td><td align="center"> 7 </td><td align="left"><code class="code"> __cpp_lib_atomic_is_always_lock_free >= 201603 </code></td></tr><tr><td align="left">A proposal to add <code class="code">shared_mutex</code> (untimed) (Revision 4)</td><td align="left"> <a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4508.html" target="_top"> N4508 </a> diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml index 35d6b6b4f5f..331420ef3ce 100644 --- a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml +++ b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml @@ -699,14 +699,13 @@ Feature-testing recommendations for C++</link>. </row> <row> - <?dbhtml bgcolor="#C8B0B0" ?> <entry> constexpr <code>atomic<T>::is_always_lock_free</code> </entry> <entry> <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0152r1.html"> P0152R1 </link> </entry> - <entry align="center"> No </entry> + <entry align="center"> 7 </entry> <entry><code> __cpp_lib_atomic_is_always_lock_free >= 201603 </code></entry> </row> diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic index f8894bf7486..ad7a4f6a2a4 100644 --- a/libstdc++-v3/include/std/atomic +++ b/libstdc++-v3/include/std/atomic @@ -50,6 +50,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @{ */ +#if __cplusplus > 201402L +# define __cpp_lib_atomic_is_always_lock_free 201603 +#endif + template<typename _Tp> struct atomic; @@ -90,6 +94,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool is_lock_free() const volatile noexcept { return _M_base.is_lock_free(); } +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_BOOL_LOCK_FREE == 2; +#endif + void store(bool __i, memory_order __m = memory_order_seq_cst) noexcept { _M_base.store(__i, __m); } @@ -221,6 +229,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION reinterpret_cast<void *>(-__alignof(_M_i))); } +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free + = __atomic_always_lock_free(sizeof(_M_i), 0); +#endif + void store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept { __atomic_store(std::__addressof(_M_i), std::__addressof(__i), __m); } @@ -416,6 +429,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION is_lock_free() const volatile noexcept { return _M_b.is_lock_free(); } +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_POINTER_LOCK_FREE == 2; +#endif + void store(__pointer_type __p, memory_order __m = memory_order_seq_cst) noexcept @@ -537,6 +554,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2; +#endif }; /// Explicit specialization for signed char. @@ -556,6 +577,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2; +#endif }; /// Explicit specialization for unsigned char. @@ -575,6 +600,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_CHAR_LOCK_FREE == 2; +#endif }; /// Explicit specialization for short. @@ -594,6 +623,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2; +#endif }; /// Explicit specialization for unsigned short. @@ -613,6 +646,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_SHORT_LOCK_FREE == 2; +#endif }; /// Explicit specialization for int. @@ -632,6 +669,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2; +#endif }; /// Explicit specialization for unsigned int. @@ -651,6 +692,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_INT_LOCK_FREE == 2; +#endif }; /// Explicit specialization for long. @@ -670,6 +715,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2; +#endif }; /// Explicit specialization for unsigned long. @@ -689,6 +738,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_LONG_LOCK_FREE == 2; +#endif }; /// Explicit specialization for long long. @@ -708,6 +761,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2; +#endif }; /// Explicit specialization for unsigned long long. @@ -727,6 +784,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_LLONG_LOCK_FREE == 2; +#endif }; /// Explicit specialization for wchar_t. @@ -746,6 +807,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_WCHAR_T_LOCK_FREE == 2; +#endif }; /// Explicit specialization for char16_t. @@ -765,6 +830,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_CHAR16_T_LOCK_FREE == 2; +#endif }; /// Explicit specialization for char32_t. @@ -784,6 +853,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __base_type::operator __integral_type; using __base_type::operator=; + +#if __cplusplus > 201402L + static constexpr bool is_always_lock_free = ATOMIC_CHAR32_T_LOCK_FREE == 2; +#endif }; diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/60695.cc b/libstdc++-v3/testsuite/29_atomics/atomic/60695.cc index 5977d54760c..21ac7589a6e 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/60695.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/60695.cc @@ -27,4 +27,4 @@ struct X { char stuff[0]; // GNU extension, type has zero size }; -std::atomic<X> a; // { dg-error "not supported" "" { target *-*-* } 182 } +std::atomic<X> a; // { dg-error "not supported" "" { target *-*-* } 190 } diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/is_always_lock_free.cc b/libstdc++-v3/testsuite/29_atomics/atomic/is_always_lock_free.cc new file mode 100644 index 00000000000..9383cea3344 --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic/is_always_lock_free.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2016 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 +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17" } +// { dg-do compile } + +#include <atomic> + +struct S { int s[64]; }; + +constexpr bool b1 = std::atomic<S>::is_always_lock_free; +constexpr const bool* cktype1 = &std::atomic<S>::is_always_lock_free; + +constexpr bool b2 = std::atomic<int*>::is_always_lock_free; +constexpr const bool* cktype2 = &std::atomic<int*>::is_always_lock_free; + +static_assert( std::atomic<int*>::is_always_lock_free + == (ATOMIC_POINTER_LOCK_FREE == 2) ); diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_integral/is_always_lock_free.cc b/libstdc++-v3/testsuite/29_atomics/atomic_integral/is_always_lock_free.cc new file mode 100644 index 00000000000..defa673e9a2 --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic_integral/is_always_lock_free.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2016 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 +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++17" } +// { dg-do compile } + +#include <atomic> + +using std::atomic; + +template<typename T> +constexpr bool check(int macro) +{ + return std::atomic<T>::is_always_lock_free == (macro == 2); +} + +static_assert( check<bool>(ATOMIC_BOOL_LOCK_FREE) ); +static_assert( check<char>(ATOMIC_CHAR_LOCK_FREE) ); +static_assert( check<signed char>(ATOMIC_CHAR_LOCK_FREE) ); +static_assert( check<unsigned char>(ATOMIC_CHAR_LOCK_FREE) ); +static_assert( check<int>(ATOMIC_INT_LOCK_FREE) ); +static_assert( check<unsigned int>(ATOMIC_INT_LOCK_FREE) ); +static_assert( check<long>(ATOMIC_LONG_LOCK_FREE) ); +static_assert( check<unsigned long>(ATOMIC_LONG_LOCK_FREE) ); +static_assert( check<long long>(ATOMIC_LLONG_LOCK_FREE) ); +static_assert( check<unsigned long long>(ATOMIC_LLONG_LOCK_FREE) ); +static_assert( check<wchar_t>(ATOMIC_WCHAR_T_LOCK_FREE) ); +static_assert( check<char16_t>(ATOMIC_CHAR16_T_LOCK_FREE) ); +static_assert( check<char32_t>(ATOMIC_CHAR32_T_LOCK_FREE) ); |