[scudo] Use getMonotonicTimeFast for tryLock.
authorChristopher Ferris <cferris@google.com>
Thu, 29 Jun 2023 02:36:29 +0000 (19:36 -0700)
committerChristopher Ferris <cferris@google.com>
Thu, 29 Jun 2023 20:07:08 +0000 (13:07 -0700)
In tryLock, the Precedence value is set using the fast time function
now. This should speed up tryLock calls slightly.

This should be okay even though the value is used as a kind of random
value in getTSDAndLockSlow. The fast time call still sets enough bits
to avoid getting the same TSD on every call.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D154039

compiler-rt/lib/scudo/standalone/tsd.h

index c5ed6dd..f4fa545 100644 (file)
@@ -41,9 +41,9 @@ template <class Allocator> struct alignas(SCUDO_CACHE_LINE_SIZE) TSD {
       return true;
     }
     if (atomic_load_relaxed(&Precedence) == 0)
-      atomic_store_relaxed(
-          &Precedence,
-          static_cast<uptr>(getMonotonicTime() >> FIRST_32_SECOND_64(16, 0)));
+      atomic_store_relaxed(&Precedence,
+                           static_cast<uptr>(getMonotonicTimeFast() >>
+                                             FIRST_32_SECOND_64(16, 0)));
     return false;
   }
   inline void lock() NO_THREAD_SAFETY_ANALYSIS {