[libcxx-commits] [libcxx] [libc++] Implement C++20 atomic_ref (PR #76647)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Feb 9 09:56:41 PST 2024


https://github.com/ldionne commented:

I just met with @huixie90 and @dalg24 to chat about this patch. We had three key take-aways:

1. It seems fine to use the GCC atomics unconditionally to implement `atomic_ref`. There is no question of potentially using `_Atomic(T)` anyway, since we don't control the storage of the `T`.
2. We agreed that `_LIBCPP_ATOMIC_ONLY_USE_BUILTINS` seemed undesirable, as brought up by @jyknight. Indeed, the goal of that setting was to decouple libc++ from libraries like compiler-rt and libatomic in Freestanding mode. We didn't have a clear understanding of goals and non-goals of Freestanding back then, but nowadays we do have a better understanding that removing all dependencies of libc++ in Freestanding is a non-goal. We should still be able to depend on builtins like those defined in compiler-rt for implementing our atomic operations under Freestanding. Hence, it makes sense to remove this setting (which should not have wide usage anyway). I'll get started on a patch to remove it.
3. The current implementation of `__cxx_atomic_wait` is tightly coupled with `__cxx_atomic_impl`, which makes it impossible to use cleanly from `atomic_ref`. @huixie90 made the observation that "load" is a "customization point" for that operation, IOW it should be able to work with anything that can be loaded. @huixie90 will refactor that function to make it more generic, so that we can pass an `atomic_ref` to it out of the box.


https://github.com/llvm/llvm-project/pull/76647


More information about the libcxx-commits mailing list