Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

This patch uses std::scoped_lock to ensure the mutex is released via
RAII, improving robustness.

This patch uses std::scoped_lock to ensure the mutex is released via RAII, improving robustness.
@llvmbot
Copy link
Member

llvmbot commented Oct 25, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

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 --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}; } } 
@kazutakahirata kazutakahirata merged commit e510797 into llvm:main Oct 25, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20251025_ADT_ConcurrentHashtable_scoped_lock branch October 25, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants