From 7d106fda3c438b344e2167c8a30858b8f90e5bd9 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Sat, 14 Nov 2020 10:43:14 +0100 Subject: [PATCH 1/3] P0943R6 Support C atomics in C++ - Rename stable label to fit pattern for synopses. --- source/atomics.tex | 137 +++++++++++++++++++++++++++++++++++++++++++++ source/support.tex | 1 + 2 files changed, 138 insertions(+) diff --git a/source/atomics.tex b/source/atomics.tex index 348accc2a3..d11cae6f42 100644 --- a/source/atomics.tex +++ b/source/atomics.tex @@ -3702,3 +3702,140 @@ that \tcode{atomic_thread_fence} would have inserted are not emitted. \end{note} \end{itemdescr} + +\rSec1[stdatomic.h.syn]{C compatibility} + +The header \libheaderdef{stdatomic.h} provides the following definitions: + +\begin{codeblock} +template + using @\exposid{std-atomic}@ = std::atomic; // exposition only + +#define _Atomic(T) @\exposid{std-atomic}@ + +#define ATOMIC_BOOL_LOCK_FREE @\seebelow@ +#define ATOMIC_CHAR_LOCK_FREE @\seebelow@ +#define ATOMIC_CHAR16_T_LOCK_FREE @\seebelow@ +#define ATOMIC_CHAR32_T_LOCK_FREE @\seebelow@ +#define ATOMIC_WCHAR_T_LOCK_FREE @\seebelow@ +#define ATOMIC_SHORT_LOCK_FREE @\seebelow@ +#define ATOMIC_INT_LOCK_FREE @\seebelow@ +#define ATOMIC_LONG_LOCK_FREE @\seebelow@ +#define ATOMIC_LLONG_LOCK_FREE @\seebelow@ +#define ATOMIC_POINTER_LOCK_FREE @\seebelow@ + +using std::@\libglobal{memory_order}@ // \seebelow +using std::@\libglobal{memory_order_relaxed}@ // \seebelow +using std::@\libglobal{memory_order_consume}@ // \seebelow +using std::@\libglobal{memory_order_acquire}@ // \seebelow +using std::@\libglobal{memory_order_release}@ // \seebelow +using std::@\libglobal{memory_order_acq_rel}@ // \seebelow +using std::@\libglobal{memory_order_seq_cst}@ // \seebelow + +using std::@\libglobal{atomic_flag}@ // \seebelow + +using std::@\libglobal{atomic_bool}@ // \seebelow +using std::@\libglobal{atomic_char}@ // \seebelow +using std::@\libglobal{atomic_schar}@ // \seebelow +using std::@\libglobal{atomic_uchar}@ // \seebelow +using std::@\libglobal{atomic_short}@ // \seebelow +using std::@\libglobal{atomic_ushort}@ // \seebelow +using std::@\libglobal{atomic_int}@ // \seebelow +using std::@\libglobal{atomic_uint}@ // \seebelow +using std::@\libglobal{atomic_long}@ // \seebelow +using std::@\libglobal{atomic_ulong}@ // \seebelow +using std::@\libglobal{atomic_llong}@ // \seebelow +using std::@\libglobal{atomic_ullong}@ // \seebelow +using std::@\libglobal{atomic_char8_t}@ // \seebelow +using std::@\libglobal{atomic_char16_t}@ // \seebelow +using std::@\libglobal{atomic_char32_t}@ // \seebelow +using std::@\libglobal{atomic_wchar_t}@ // \seebelow +using std::@\libglobal{atomic_int8_t}@ // \seebelow +using std::@\libglobal{atomic_uint8_t}@ // \seebelow +using std::@\libglobal{atomic_int16_t}@ // \seebelow +using std::@\libglobal{atomic_uint16_t}@ // \seebelow +using std::@\libglobal{atomic_int32_t}@ // \seebelow +using std::@\libglobal{atomic_uint32_t}@ // \seebelow +using std::@\libglobal{atomic_int64_t}@ // \seebelow +using std::@\libglobal{atomic_uint64_t}@ // \seebelow +using std::@\libglobal{atomic_int_least8_t}@ // \seebelow +using std::@\libglobal{atomic_uint_least8_t}@ // \seebelow +using std::@\libglobal{atomic_int_least16_t}@ // \seebelow +using std::@\libglobal{atomic_uint_least16_t}@ // \seebelow +using std::@\libglobal{atomic_int_least32_t}@ // \seebelow +using std::@\libglobal{atomic_uint_least32_t}@ // \seebelow +using std::@\libglobal{atomic_int_least64_t}@ // \seebelow +using std::@\libglobal{atomic_uint_least64_t}@ // \seebelow +using std::@\libglobal{atomic_int_fast8_t}@ // \seebelow +using std::@\libglobal{atomic_uint_fast8_t}@ // \seebelow +using std::@\libglobal{atomic_int_fast16_t}@ // \seebelow +using std::@\libglobal{atomic_uint_fast16_t}@ // \seebelow +using std::@\libglobal{atomic_int_fast32_t}@ // \seebelow +using std::@\libglobal{atomic_uint_fast32_t}@ // \seebelow +using std::@\libglobal{atomic_int_fast64_t}@ // \seebelow +using std::@\libglobal{atomic_uint_fast64_t}@ // \seebelow +using std::@\libglobal{atomic_intptr_t}@ // \seebelow +using std::@\libglobal{atomic_uintptr_t}@ // \seebelow +using std::@\libglobal{atomic_size_t}@ // \seebelow +using std::@\libglobal{atomic_ptrdiff_t}@ // \seebelow +using std::@\libglobal{atomic_intmax_t}@ // \seebelow +using std::@\libglobal{atomic_uintmax_t}@ // \seebelow + +using std::@\libglobal{atomic_is_lock_free}@ // \seebelow +using std::@\libglobal{atomic_load}@ // \seebelow +using std::@\libglobal{atomic_load_explicit}@ // \seebelow +using std::@\libglobal{atomic_store}@ // \seebelow +using std::@\libglobal{atomic_store_explicit}@ // \seebelow +using std::@\libglobal{atomic_exchange}@ // \seebelow +using std::@\libglobal{atomic_exchange_explicit}@ // \seebelow +using std::@\libglobal{atomic_compare_exchange_strong}@ // \seebelow +using std::@\libglobal{atomic_compare_exchange_strong_explicit}@ // \seebelow +using std::@\libglobal{atomic_compare_exchange_weak}@ // \seebelow +using std::@\libglobal{atomic_compare_exchange_weak_explicit}@ // \seebelow +using std::@\libglobal{atomic_fetch_add}@ // \seebelow +using std::@\libglobal{atomic_fetch_add_explicit}@ // \seebelow +using std::@\libglobal{atomic_fetch_sub}@ // \seebelow +using std::@\libglobal{atomic_fetch_sub_explicit}@ // \seebelow +using std::@\libglobal{atomic_fetch_or}@ // \seebelow +using std::@\libglobal{atomic_fetch_or_explicit}@ // \seebelow +using std::@\libglobal{atomic_fetch_and}@ // \seebelow +using std::@\libglobal{atomic_fetch_and_explicit}@ // \seebelow +using std::@\libglobal{atomic_flag_test_and_set}@ // \seebelow +using std::@\libglobal{atomic_flag_test_and_set_explicit}@ // \seebelow +using std::@\libglobal{atomic_flag_clear}@ // \seebelow +using std::@\libglobal{atomic_flag_clear_explicit}@ // \seebelow + +using std::@\libglobal{atomic_thread_fence}@ // \seebelow +using std::@\libglobal{atomic_signal_fence}@ // \seebelow +\end{codeblock} + +\pnum +Each \grammarterm{using-declaration} for some name $A$ in the synopsis above +makes available the same entity as \tcode{std::$A$} +declared in \libheaderrefx{atomic}{atomics.syn}. +Each macro listed above other than \tcode{_Atomic(T)} +is defined as in \libheader{atomic}. +It is unspecified whether \libheader{stdatomic.h} makes available +any declarations in namespace \tcode{std}. + +\pnum +Each of the \grammarterm{using-declaration}s for +\tcode{int$N$_t}, \tcode{uint$N$_t}, \tcode{intptr_t}, and \tcode{uintptr_t} +listed above is defined if and only if the implementation defines +the corresponding typedef name in \ref{atomics.syn}. + +\pnum +Neither the \tcode{_Atomic} macro, +nor any of the non-macro global namespace declarations, +are provided by any \Cpp{} standard library header +other than \libheader{stdatomic.h}. + +\pnum +\recommended +Implementations should ensure +that C and \Cpp{} representations of atomic objects are compatible, +so that the same object can be accessed as both an \tcode{_Atomic(T)} +from C code and an \tcode{atomic} from \Cpp{} code. +The representations should be the same, and +the mechanisms used to ensure atomicity and memory ordering +should be compatible. diff --git a/source/support.tex b/source/support.tex index afc5ae8e48..fe94d54f9a 100644 --- a/source/support.tex +++ b/source/support.tex @@ -675,6 +675,7 @@ #define @\defnlibxname{cpp_lib_ssize}@ 201902L // also in \libheader{iterator} #define @\defnlibxname{cpp_lib_stacktrace}@ 202011L // also in \libheader{stacktrace} #define @\defnlibxname{cpp_lib_starts_ends_with}@ 201711L // also in \libheader{string}, \libheader{string_view} +#define @\defnlibxname{cpp_lib_stdatomic_h}@ 202011L // also in \libheader{stdatomic.h} #define @\defnlibxname{cpp_lib_string_contains}@ 202011L // also in \libheader{string}, \libheader{string_view} #define @\defnlibxname{cpp_lib_string_udls}@ 201304L // also in \libheader{string} #define @\defnlibxname{cpp_lib_string_view}@ 201803L // also in \libheader{string}, \libheader{string_view} From bc4d7c8548407fbfd25142b6dbe86e45be9e0b91 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Sat, 14 Nov 2020 10:51:06 +0100 Subject: [PATCH 2/3] [diff.mods.to.headers,depr.c.headers.other] Reflect new status of . --- source/compatibility.tex | 4 +--- source/future.tex | 6 ++++-- source/lib-intro.tex | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/source/compatibility.tex b/source/compatibility.tex index c0cb35933a..b8512fb15b 100644 --- a/source/compatibility.tex +++ b/source/compatibility.tex @@ -2674,9 +2674,7 @@ \pnum There are no \Cpp{} headers for the C standard library's headers -\libnoheader{stdatomic.h}, -\libnoheader{stdnoreturn.h}, -and \libnoheader{threads.h}, +\libnoheader{stdnoreturn.h} and \libnoheader{threads.h}, nor are these headers from the C standard library headers themselves part of \Cpp{}. \pnum diff --git a/source/future.tex b/source/future.tex index 5f974c95f0..e1afbe7c0d 100644 --- a/source/future.tex +++ b/source/future.tex @@ -243,17 +243,18 @@ \libheaderdef{signal.h} \\ \libheader{stdalign.h} \\ \libheaderdef{stdarg.h} \\ +\libheader{stdatomic.h} \\ \libheader{stdbool.h} \\ \libheaderdef{stddef.h} \\ -\libheaderdef{stdint.h} \\ \columnbreak +\libheaderdef{stdint.h} \\ \libheaderdef{stdio.h} \\ \libheaderdef{stdlib.h} \\ \libheaderdef{string.h} \\ \libheader{tgmath.h} \\ \libheaderdef{time.h} \\ -\libheaderdef{uchar.h} \\ \columnbreak +\libheaderdef{uchar.h} \\ \libheaderdef{wchar.h} \\ \libheaderdef{wctype.h} \\ \end{multicolfloattable} @@ -365,6 +366,7 @@ \libdeprheaderref{complex.h}, \libdeprheaderref{iso646.h}, \libdeprheaderref{stdalign.h},\newline +\libheaderref{stdatomic.h}, \libdeprheaderref{stdbool.h}, and \libdeprheaderref{tgmath.h}, each of diff --git a/source/lib-intro.tex b/source/lib-intro.tex index 030b461297..8d589a4790 100644 --- a/source/lib-intro.tex +++ b/source/lib-intro.tex @@ -1013,7 +1013,6 @@ \begin{footnote} It is intentional that there is no \Cpp{} header for any of these C headers: -\libnoheader{stdatomic.h}, \libnoheader{stdnoreturn.h}, \libnoheader{threads.h}. \end{footnote} From a99ab80f00c58eab2bfe4f3b460caea86df21a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= Date: Mon, 14 Dec 2020 12:25:04 +0000 Subject: [PATCH 3/3] [atomics.general] Add contents entry for "C compatibility" subclause --- source/atomics.tex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/atomics.tex b/source/atomics.tex index d11cae6f42..ab32173ab8 100644 --- a/source/atomics.tex +++ b/source/atomics.tex @@ -20,7 +20,8 @@ \ref{atomics.types.generic} & Class template \tcode{atomic} & \\ \ref{atomics.nonmembers} & Non-member functions & \\ \ref{atomics.flag} & Flag type and operations & \\ -\ref{atomics.fences} & Fences & \\ +\ref{atomics.fences} & Fences & \\ \rowsep +\ref{stdatomic.h.syn} & C compatibility & \tcode{} \\ \end{libsumtab} \rSec1[atomics.syn]{Header \tcode{} synopsis}