From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3D3F63864A1E for ; Mon, 12 Dec 2022 14:01:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3D3F63864A1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670853690; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Fgy0DwmxYtuhdq0ISfQ/3XBscwVU/bK+mh3kFIF3LJI=; b=bfnrOI29JAlTv5co6arHQdjwLZ7TPJtg4W82Mkk9ATdkgfNO+AZlWSrv+gD9gqZQwhNPrP EEHXk54a8GxexDDmqtDGURVngPRc1pLigj6au41QaS5DhqD5zF3FvRke52rLh+WLpnA8TS FfO27C3jHfIjExa+Rx4TQAoeAzYSMc4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-444-4t14srwWM3mVSsaIMkoHlw-1; Mon, 12 Dec 2022 09:01:27 -0500 X-MC-Unique: 4t14srwWM3mVSsaIMkoHlw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 62DF91C06ED0; Mon, 12 Dec 2022 14:01:27 +0000 (UTC) Received: from localhost (unknown [10.33.36.251]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C2E740ED76B; Mon, 12 Dec 2022 14:01:27 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Define atomic lock-free type aliases for C++20 [PR98034] Date: Mon, 12 Dec 2022 14:01:24 +0000 Message-Id: <20221212140124.716909-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux. Pushed to trunk. -- >8-- libstdc++-v3/ChangeLog: PR libstdc++/98034 * include/std/atomic (__cpp_lib_atomic_lock_free_type_aliases): Define macro. (atomic_signed_lock_free, atomic_unsigned_lock_free): Define aliases. * include/std/version (__cpp_lib_atomic_lock_free_type_aliases): Define macro. * testsuite/29_atomics/atomic/lock_free_aliases.cc: New test. --- libstdc++-v3/include/std/atomic | 17 ++++++++++ libstdc++-v3/include/std/version | 1 + .../29_atomics/atomic/lock_free_aliases.cc | 34 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic index 356f1458f44..857f9270049 100644 --- a/libstdc++-v3/include/std/atomic +++ b/libstdc++-v3/include/std/atomic @@ -1727,6 +1727,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __atomic_ref<_Tp>::operator=; }; +#define __cpp_lib_atomic_lock_free_type_aliases 201907L +#ifdef _GLIBCXX_HAVE_PLATFORM_WAIT + using atomic_signed_lock_free + = atomic>; + using atomic_unsigned_lock_free + = atomic>; +#elif ATOMIC_INT_LOCK_FREE || !(ATOMIC_LONG_LOCK_FREE || ATOMIC_CHAR_LOCK_FREE) + using atomic_signed_lock_free = atomic; + using atomic_unsigned_lock_free = atomic; +#elif ATOMIC_LONG_LOCK_FREE + using atomic_signed_lock_free = atomic; + using atomic_unsigned_lock_free = atomic; +#elif ATOMIC_CHAR_LOCK_FREE + using atomic_signed_lock_free = atomic; + using atomic_unsigned_lock_free = atomic; +#endif + #endif // C++2a /// @} group atomics diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index 3c7c440bd80..61718ebad74 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -187,6 +187,7 @@ #define __cpp_lib_assume_aligned 201811L #define __cpp_lib_atomic_flag_test 201907L #define __cpp_lib_atomic_float 201711L +#define __cpp_lib_atomic_lock_free_type_aliases 201907L #define __cpp_lib_atomic_ref 201806L #define __cpp_lib_atomic_value_initialization 201911L #define __cpp_lib_bind_front 201907L diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc b/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc new file mode 100644 index 00000000000..02c4ccc3aa3 --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc @@ -0,0 +1,34 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } + +#include + +#ifndef __cpp_lib_atomic_lock_free_type_aliases +# error "Feature test macro for lock-free type aliases is missing in " +#elif __cpp_lib_atomic_lock_free_type_aliases != 201907L +# error "Feature test macro for lock-free type aliases has wrong value in " +#endif + +template +constexpr bool is_atomic_specialization = false; +template +constexpr bool is_atomic_specialization> = true; + +// The type aliases atomic_signed_lock_free and atomic_unsigned_lock_free +// name specializations of atomic +static_assert( is_atomic_specialization ); +static_assert( is_atomic_specialization ); + +#include + +// ... whose template arguments are integral types, +static_assert( std::is_integral_v ); +static_assert( std::is_integral_v ); + +// ... respectively signed and unsigned, +static_assert( std::is_signed_v ); +static_assert( std::is_unsigned_v ); + +// and whose is_always_lock_free property is true. +static_assert( std::atomic_signed_lock_free::is_always_lock_free ); +static_assert( std::atomic_unsigned_lock_free::is_always_lock_free ); -- 2.38.1