Another new C++17 feature. * 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.
Tested x86_64-linux and powerpc64le-linux, committed to trunk.
commit a79363ae83c16b1daf082d32effe727b887c9d95 Author: Jonathan Wakely <jwak...@redhat.com> Date: Fri Aug 19 10:54:26 2016 +0100 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. diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml index 35d6b6b..331420e 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 f8894bf..ad7a4f6 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 5977d54..21ac758 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 0000000..9383cea --- /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 0000000..defa673 --- /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) );