[llvm] [ADT] Use std::scoped_lock in ConcurrentHashtable (NFC) (PR #165100)
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Sat Oct 25 07:53:32 PDT 2025
    
    
  
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
This patch uses std::scoped_lock to ensure the mutex is released via
RAII, improving robustness.
---
Full diff: https://github.com/llvm/llvm-project/pull/165100.diff
1 Files Affected:
- (modified) llvm/include/llvm/ADT/ConcurrentHashtable.h (+1-10) 
``````````diff
diff --git a/llvm/include/llvm/ADT/ConcurrentHashtable.h b/llvm/include/llvm/ADT/ConcurrentHashtable.h
index 6a943c5b062e7..0cc03cf7a692a 100644
--- a/llvm/include/llvm/ADT/ConcurrentHashtable.h
+++ b/llvm/include/llvm/ADT/ConcurrentHashtable.h
@@ -177,7 +177,7 @@ class ConcurrentHashTableByPtr {
 
 #if LLVM_ENABLE_THREADS
     // Lock bucket.
-    CurBucket.Guard.lock();
+    std::scoped_lock<std::mutex> Lock(CurBucket.Guard);
 #endif
 
     HashesPtr BucketHashes = CurBucket.Hashes;
@@ -195,11 +195,6 @@ class ConcurrentHashTableByPtr {
 
         CurBucket.NumberOfEntries++;
         RehashBucket(CurBucket);
-
-#if LLVM_ENABLE_THREADS
-        CurBucket.Guard.unlock();
-#endif
-
         return {NewData, true};
       }
 
@@ -208,10 +203,6 @@ class ConcurrentHashTableByPtr {
         KeyDataTy *EntryData = BucketEntries[CurEntryIdx];
         if (Info::isEqual(Info::getKey(*EntryData), NewValue)) {
           // Already existed entry matched with inserted data is found.
-#if LLVM_ENABLE_THREADS
-          CurBucket.Guard.unlock();
-#endif
-
           return {EntryData, false};
         }
       }
``````````
</details>
https://github.com/llvm/llvm-project/pull/165100
    
    
More information about the llvm-commits
mailing list