[libcxx-commits] [libcxxabi] 16779f8 - [libc++] Add static_assert to make sure rate limiter doesn't use locks

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 22 11:50:04 PDT 2020


Author: Louis Dionne
Date: 2020-07-22T14:49:50-04:00
New Revision: 16779f8084541b626578a4bda2f51ee741dcd7bf

URL: https://github.com/llvm/llvm-project/commit/16779f8084541b626578a4bda2f51ee741dcd7bf
DIFF: https://github.com/llvm/llvm-project/commit/16779f8084541b626578a4bda2f51ee741dcd7bf.diff

LOG: [libc++] Add static_assert to make sure rate limiter doesn't use locks

We want to be sure that atomic<size_t> 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).

Added: 
    

Modified: 
    libcxxabi/src/private_typeinfo.cpp

Removed: 
    


################################################################################
diff  --git a/libcxxabi/src/private_typeinfo.cpp b/libcxxabi/src/private_typeinfo.cpp
index 55a90b3ae1d4..3e8bdae32e41 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<size_t>::is_always_lock_free, "");
             static std::atomic<size_t> 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<size_t>::is_always_lock_free, "");
             static std::atomic<size_t> 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)


        


More information about the libcxx-commits mailing list