Skip to content

Commit 7d106fd

Browse files
jensmaurertkoeppe
authored andcommitted
P0943R6 Support C atomics in C++
- Rename stable label to fit pattern for synopses.
1 parent 04c217b commit 7d106fd

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

source/atomics.tex

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3702,3 +3702,140 @@
37023702
that \tcode{atomic_thread_fence} would have inserted are not emitted.
37033703
\end{note}
37043704
\end{itemdescr}
3705+
3706+
\rSec1[stdatomic.h.syn]{C compatibility}
3707+
3708+
The header \libheaderdef{stdatomic.h} provides the following definitions:
3709+
3710+
\begin{codeblock}
3711+
template<class T>
3712+
using @\exposid{std-atomic}@ = std::atomic<T>; // exposition only
3713+
3714+
#define _Atomic(T) @\exposid{std-atomic}@<T>
3715+
3716+
#define ATOMIC_BOOL_LOCK_FREE @\seebelow@
3717+
#define ATOMIC_CHAR_LOCK_FREE @\seebelow@
3718+
#define ATOMIC_CHAR16_T_LOCK_FREE @\seebelow@
3719+
#define ATOMIC_CHAR32_T_LOCK_FREE @\seebelow@
3720+
#define ATOMIC_WCHAR_T_LOCK_FREE @\seebelow@
3721+
#define ATOMIC_SHORT_LOCK_FREE @\seebelow@
3722+
#define ATOMIC_INT_LOCK_FREE @\seebelow@
3723+
#define ATOMIC_LONG_LOCK_FREE @\seebelow@
3724+
#define ATOMIC_LLONG_LOCK_FREE @\seebelow@
3725+
#define ATOMIC_POINTER_LOCK_FREE @\seebelow@
3726+
3727+
using std::@\libglobal{memory_order}@ // \seebelow
3728+
using std::@\libglobal{memory_order_relaxed}@ // \seebelow
3729+
using std::@\libglobal{memory_order_consume}@ // \seebelow
3730+
using std::@\libglobal{memory_order_acquire}@ // \seebelow
3731+
using std::@\libglobal{memory_order_release}@ // \seebelow
3732+
using std::@\libglobal{memory_order_acq_rel}@ // \seebelow
3733+
using std::@\libglobal{memory_order_seq_cst}@ // \seebelow
3734+
3735+
using std::@\libglobal{atomic_flag}@ // \seebelow
3736+
3737+
using std::@\libglobal{atomic_bool}@ // \seebelow
3738+
using std::@\libglobal{atomic_char}@ // \seebelow
3739+
using std::@\libglobal{atomic_schar}@ // \seebelow
3740+
using std::@\libglobal{atomic_uchar}@ // \seebelow
3741+
using std::@\libglobal{atomic_short}@ // \seebelow
3742+
using std::@\libglobal{atomic_ushort}@ // \seebelow
3743+
using std::@\libglobal{atomic_int}@ // \seebelow
3744+
using std::@\libglobal{atomic_uint}@ // \seebelow
3745+
using std::@\libglobal{atomic_long}@ // \seebelow
3746+
using std::@\libglobal{atomic_ulong}@ // \seebelow
3747+
using std::@\libglobal{atomic_llong}@ // \seebelow
3748+
using std::@\libglobal{atomic_ullong}@ // \seebelow
3749+
using std::@\libglobal{atomic_char8_t}@ // \seebelow
3750+
using std::@\libglobal{atomic_char16_t}@ // \seebelow
3751+
using std::@\libglobal{atomic_char32_t}@ // \seebelow
3752+
using std::@\libglobal{atomic_wchar_t}@ // \seebelow
3753+
using std::@\libglobal{atomic_int8_t}@ // \seebelow
3754+
using std::@\libglobal{atomic_uint8_t}@ // \seebelow
3755+
using std::@\libglobal{atomic_int16_t}@ // \seebelow
3756+
using std::@\libglobal{atomic_uint16_t}@ // \seebelow
3757+
using std::@\libglobal{atomic_int32_t}@ // \seebelow
3758+
using std::@\libglobal{atomic_uint32_t}@ // \seebelow
3759+
using std::@\libglobal{atomic_int64_t}@ // \seebelow
3760+
using std::@\libglobal{atomic_uint64_t}@ // \seebelow
3761+
using std::@\libglobal{atomic_int_least8_t}@ // \seebelow
3762+
using std::@\libglobal{atomic_uint_least8_t}@ // \seebelow
3763+
using std::@\libglobal{atomic_int_least16_t}@ // \seebelow
3764+
using std::@\libglobal{atomic_uint_least16_t}@ // \seebelow
3765+
using std::@\libglobal{atomic_int_least32_t}@ // \seebelow
3766+
using std::@\libglobal{atomic_uint_least32_t}@ // \seebelow
3767+
using std::@\libglobal{atomic_int_least64_t}@ // \seebelow
3768+
using std::@\libglobal{atomic_uint_least64_t}@ // \seebelow
3769+
using std::@\libglobal{atomic_int_fast8_t}@ // \seebelow
3770+
using std::@\libglobal{atomic_uint_fast8_t}@ // \seebelow
3771+
using std::@\libglobal{atomic_int_fast16_t}@ // \seebelow
3772+
using std::@\libglobal{atomic_uint_fast16_t}@ // \seebelow
3773+
using std::@\libglobal{atomic_int_fast32_t}@ // \seebelow
3774+
using std::@\libglobal{atomic_uint_fast32_t}@ // \seebelow
3775+
using std::@\libglobal{atomic_int_fast64_t}@ // \seebelow
3776+
using std::@\libglobal{atomic_uint_fast64_t}@ // \seebelow
3777+
using std::@\libglobal{atomic_intptr_t}@ // \seebelow
3778+
using std::@\libglobal{atomic_uintptr_t}@ // \seebelow
3779+
using std::@\libglobal{atomic_size_t}@ // \seebelow
3780+
using std::@\libglobal{atomic_ptrdiff_t}@ // \seebelow
3781+
using std::@\libglobal{atomic_intmax_t}@ // \seebelow
3782+
using std::@\libglobal{atomic_uintmax_t}@ // \seebelow
3783+
3784+
using std::@\libglobal{atomic_is_lock_free}@ // \seebelow
3785+
using std::@\libglobal{atomic_load}@ // \seebelow
3786+
using std::@\libglobal{atomic_load_explicit}@ // \seebelow
3787+
using std::@\libglobal{atomic_store}@ // \seebelow
3788+
using std::@\libglobal{atomic_store_explicit}@ // \seebelow
3789+
using std::@\libglobal{atomic_exchange}@ // \seebelow
3790+
using std::@\libglobal{atomic_exchange_explicit}@ // \seebelow
3791+
using std::@\libglobal{atomic_compare_exchange_strong}@ // \seebelow
3792+
using std::@\libglobal{atomic_compare_exchange_strong_explicit}@ // \seebelow
3793+
using std::@\libglobal{atomic_compare_exchange_weak}@ // \seebelow
3794+
using std::@\libglobal{atomic_compare_exchange_weak_explicit}@ // \seebelow
3795+
using std::@\libglobal{atomic_fetch_add}@ // \seebelow
3796+
using std::@\libglobal{atomic_fetch_add_explicit}@ // \seebelow
3797+
using std::@\libglobal{atomic_fetch_sub}@ // \seebelow
3798+
using std::@\libglobal{atomic_fetch_sub_explicit}@ // \seebelow
3799+
using std::@\libglobal{atomic_fetch_or}@ // \seebelow
3800+
using std::@\libglobal{atomic_fetch_or_explicit}@ // \seebelow
3801+
using std::@\libglobal{atomic_fetch_and}@ // \seebelow
3802+
using std::@\libglobal{atomic_fetch_and_explicit}@ // \seebelow
3803+
using std::@\libglobal{atomic_flag_test_and_set}@ // \seebelow
3804+
using std::@\libglobal{atomic_flag_test_and_set_explicit}@ // \seebelow
3805+
using std::@\libglobal{atomic_flag_clear}@ // \seebelow
3806+
using std::@\libglobal{atomic_flag_clear_explicit}@ // \seebelow
3807+
3808+
using std::@\libglobal{atomic_thread_fence}@ // \seebelow
3809+
using std::@\libglobal{atomic_signal_fence}@ // \seebelow
3810+
\end{codeblock}
3811+
3812+
\pnum
3813+
Each \grammarterm{using-declaration} for some name $A$ in the synopsis above
3814+
makes available the same entity as \tcode{std::$A$}
3815+
declared in \libheaderrefx{atomic}{atomics.syn}.
3816+
Each macro listed above other than \tcode{_Atomic(T)}
3817+
is defined as in \libheader{atomic}.
3818+
It is unspecified whether \libheader{stdatomic.h} makes available
3819+
any declarations in namespace \tcode{std}.
3820+
3821+
\pnum
3822+
Each of the \grammarterm{using-declaration}s for
3823+
\tcode{int$N$_t}, \tcode{uint$N$_t}, \tcode{intptr_t}, and \tcode{uintptr_t}
3824+
listed above is defined if and only if the implementation defines
3825+
the corresponding typedef name in \ref{atomics.syn}.
3826+
3827+
\pnum
3828+
Neither the \tcode{_Atomic} macro,
3829+
nor any of the non-macro global namespace declarations,
3830+
are provided by any \Cpp{} standard library header
3831+
other than \libheader{stdatomic.h}.
3832+
3833+
\pnum
3834+
\recommended
3835+
Implementations should ensure
3836+
that C and \Cpp{} representations of atomic objects are compatible,
3837+
so that the same object can be accessed as both an \tcode{_Atomic(T)}
3838+
from C code and an \tcode{atomic<T>} from \Cpp{} code.
3839+
The representations should be the same, and
3840+
the mechanisms used to ensure atomicity and memory ordering
3841+
should be compatible.

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@
675675
#define @\defnlibxname{cpp_lib_ssize}@ 201902L // also in \libheader{iterator}
676676
#define @\defnlibxname{cpp_lib_stacktrace}@ 202011L // also in \libheader{stacktrace}
677677
#define @\defnlibxname{cpp_lib_starts_ends_with}@ 201711L // also in \libheader{string}, \libheader{string_view}
678+
#define @\defnlibxname{cpp_lib_stdatomic_h}@ 202011L // also in \libheader{stdatomic.h}
678679
#define @\defnlibxname{cpp_lib_string_contains}@ 202011L // also in \libheader{string}, \libheader{string_view}
679680
#define @\defnlibxname{cpp_lib_string_udls}@ 201304L // also in \libheader{string}
680681
#define @\defnlibxname{cpp_lib_string_view}@ 201803L // also in \libheader{string}, \libheader{string_view}

0 commit comments

Comments
 (0)