[compiler-rt] [scudo] Add ScopedTSD to avoid releasing TSD manually (PR #80061)

Christopher Ferris via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 11:03:56 PST 2024


================
@@ -27,6 +27,31 @@ struct ThreadState {
 template <class Allocator> void teardownThread(void *Ptr);
 
 template <class Allocator> struct TSDRegistryExT {
+  using ThisT = TSDRegistryExT<Allocator>;
+
+  struct ScopedTSD {
+    ScopedTSD(ThisT &TSDRegistry) {
+      CurrentTSD = TSDRegistry.getTSDAndLock(&IsFallback);
+      DCHECK_NE(CurrentTSD, nullptr);
+    }
+
+    ~ScopedTSD() {
+      if (UNLIKELY(IsFallback))
----------------
cferris1000 wrote:

The getTSDAndLock function uses UnlockRequired as the name of the parameter, but here you use IsFallback. It's a bit confusing to use a different name. Even though you are using a fallback when not locking, I think it's better to keep using UnlockRequired here.

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


More information about the llvm-commits mailing list