Open
Description
While discussing with @huixie90 and Apple folks about #109290, it was noticed that __libcpp_contention_table_entry
defined here contained two atomics when in reality we could merge both into a single atomic:
struct alignas(64) /* aim to avoid false sharing */ __libcpp_contention_table_entry {
__cxx_atomic_contention_t __contention_state;
__cxx_atomic_contention_t __platform_state;
inline constexpr __libcpp_contention_table_entry() : __contention_state(0), __platform_state(0) {}
};
On Linux, __cxx_atomic_contention_t
is 32 bits, so we could merge both into a single 64 bits value and perform atomic operations on that directly.
On Apple arm64, __cxx_atomic_contention_t
is 64 bits, so we could merge both into a single 128 bits value and perform 128-bit atomic operations on that. On Apple x86_64, I don't think we can use this trick (?).
This can potentially simplify the implementation of the contention table algorithm and might be faster.