I volunteered to write a first patch to make use of a Freestanding configuration in libcxx. The goal of this patch is to decouple non-lock-free atomic<T> from platform libraries, like libatomic.a, when a Freestanding implementation is selected. This plays a big role in the accelerator-integrated library that we are working on.
This patch is based on the GitHub monorepo as of today.
Copy/pasting how this works from my email thread to -dev:
- Creates a single cxx_atomic_* layer which is an adaptation of either c11_atomic_*, preferentially, or else atomic_*. (For atomic_*, it’s a rename of the layer that’s there now. For __c11_atomic_*, it’s a new but boring wrapper that just forwards calls.)
- Creates a __cxx_atomic_type<> template that is an alias to what should wrap the _Tp inside of an atomic<T> / atomic_flag. Defaults to the same _Atomic(_Tp) as today, either from C11 or from the adaptation layer.
- Under #ifdef LIBCXX_FREESTANDING, introduce cxx_locked_atomic_type<> with an implementation of cxx_atomic_*, and redirect cxx_atomic_type<> based on always-lock-freedom. a. In C++17 mode, it uses atomic_is_always_lock_free. b. Otherwise, it uses the C lock-free macros as shown in wg21.link/p0152.
Thanks for looking this over,