From 16779f8084541b626578a4bda2f51ee741dcd7bf Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Wed, 22 Apr 2020 10:23:38 -0400 Subject: [PATCH] [libc++] Add static_assert to make sure rate limiter doesn't use locks We want to be sure that atomic is always lock-free, or the code will be much slower than expected (and could even conceivably fail if the lock implementation somehow calls back into libc++abi). --- libcxxabi/src/private_typeinfo.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libcxxabi/src/private_typeinfo.cpp b/libcxxabi/src/private_typeinfo.cpp index 55a90b3..3e8bdae 100644 --- a/libcxxabi/src/private_typeinfo.cpp +++ b/libcxxabi/src/private_typeinfo.cpp @@ -641,6 +641,7 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type, { // We get here only if there is some kind of visibility problem // in client code. + static_assert(std::atomic::is_always_lock_free, ""); static std::atomic error_count(0); size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed); if ((error_count_snapshot & (error_count_snapshot-1)) == 0) @@ -667,6 +668,7 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type, if (info.path_dst_ptr_to_static_ptr == unknown && info.path_dynamic_ptr_to_static_ptr == unknown) { + static_assert(std::atomic::is_always_lock_free, ""); static std::atomic error_count(0); size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed); if ((error_count_snapshot & (error_count_snapshot-1)) == 0) -- 2.7.4