From: Jonathan Wakely Date: Fri, 19 Aug 2016 15:42:27 +0000 (+0100) Subject: Define std::atomic::is_always_lock_free for C++17 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=387edf83a033e1a534c7a2a076d5ae691ecbac07;p=gcc.git Define std::atomic::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. From-SVN: r239622 --- 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 + * 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++. P0392R0 - No   constexpr atomic<T>::is_always_lock_free + No   constexpr atomic<T>::is_always_lock_free P0152R1 - No __cpp_lib_atomic_is_always_lock_free >= 201603 A proposal to add shared_mutex (untimed) (Revision 4) + 7 __cpp_lib_atomic_is_always_lock_free >= 201603 A proposal to add shared_mutex (untimed) (Revision 4) N4508 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++. - constexpr atomic<T>::is_always_lock_free P0152R1 - No + 7 __cpp_lib_atomic_is_always_lock_free >= 201603 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 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(-__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 a; // { dg-error "not supported" "" { target *-*-* } 182 } +std::atomic 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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile } + +#include + +struct S { int s[64]; }; + +constexpr bool b1 = std::atomic::is_always_lock_free; +constexpr const bool* cktype1 = &std::atomic::is_always_lock_free; + +constexpr bool b2 = std::atomic::is_always_lock_free; +constexpr const bool* cktype2 = &std::atomic::is_always_lock_free; + +static_assert( std::atomic::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 +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile } + +#include + +using std::atomic; + +template +constexpr bool check(int macro) +{ + return std::atomic::is_always_lock_free == (macro == 2); +} + +static_assert( check(ATOMIC_BOOL_LOCK_FREE) ); +static_assert( check(ATOMIC_CHAR_LOCK_FREE) ); +static_assert( check(ATOMIC_CHAR_LOCK_FREE) ); +static_assert( check(ATOMIC_CHAR_LOCK_FREE) ); +static_assert( check(ATOMIC_INT_LOCK_FREE) ); +static_assert( check(ATOMIC_INT_LOCK_FREE) ); +static_assert( check(ATOMIC_LONG_LOCK_FREE) ); +static_assert( check(ATOMIC_LONG_LOCK_FREE) ); +static_assert( check(ATOMIC_LLONG_LOCK_FREE) ); +static_assert( check(ATOMIC_LLONG_LOCK_FREE) ); +static_assert( check(ATOMIC_WCHAR_T_LOCK_FREE) ); +static_assert( check(ATOMIC_CHAR16_T_LOCK_FREE) ); +static_assert( check(ATOMIC_CHAR32_T_LOCK_FREE) );