[libcxx-commits] [libcxx] [libc++] Make atomic contention tables constinit (PR #207456)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 3 12:35:36 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/207456.diff


1 Files Affected:

- (modified) libcxx/src/atomic.cpp (+2-2) 


``````````diff
diff --git a/libcxx/src/atomic.cpp b/libcxx/src/atomic.cpp
index ae79ac7f87965..53aec09dfc2a0 100644
--- a/libcxx/src/atomic.cpp
+++ b/libcxx/src/atomic.cpp
@@ -422,7 +422,7 @@ struct alignas(
   constexpr __contention_state_native() : __waiter_count(0) {}
 };
 
-static __contention_state_native __contention_table_native[__contention_table_size];
+static constinit __contention_state_native __contention_table_native[__contention_table_size];
 
 static __cxx_atomic_contention_t* __get_native_waiter_count(void const* p) {
   return &__contention_table_native[__contention_hasher(p) & (__contention_table_size - 1)].__waiter_count;
@@ -438,7 +438,7 @@ struct alignas(
   constexpr __contention_state_global() : __waiter_count(0), __platform_state(0) {}
 };
 
-static __contention_state_global __contention_table_global[__contention_table_size];
+static constinit __contention_state_global __contention_table_global[__contention_table_size];
 
 static __contention_state_global* __get_global_contention_state(void const* p) {
   return &__contention_table_global[__contention_hasher(p) & (__contention_table_size - 1)];

``````````

</details>


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


More information about the libcxx-commits mailing list