[llvm] e510797 - [ADT] Use std::scoped_lock in ConcurrentHashtable (NFC) (#165100)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 25 10:04:58 PDT 2025
Author: Kazu Hirata
Date: 2025-10-25T10:04:54-07:00
New Revision: e510797700fb53d114371ad18084bce11fdfafc0
URL: https://github.com/llvm/llvm-project/commit/e510797700fb53d114371ad18084bce11fdfafc0
DIFF: https://github.com/llvm/llvm-project/commit/e510797700fb53d114371ad18084bce11fdfafc0.diff
LOG: [ADT] Use std::scoped_lock in ConcurrentHashtable (NFC) (#165100)
This patch uses std::scoped_lock to ensure the mutex is released via
RAII, improving robustness.
Added:
Modified:
llvm/include/llvm/ADT/ConcurrentHashtable.h
Removed:
################################################################################
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};
}
}
More information about the llvm-commits
mailing list