Skip to content

Commit 6d91852

Browse files
kazutakahiratagithub-actions[bot]
authored andcommitted
Automerge: [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.
2 parents 462fc20 + e510797 commit 6d91852

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

llvm/include/llvm/ADT/ConcurrentHashtable.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class ConcurrentHashTableByPtr {
177177

178178
#if LLVM_ENABLE_THREADS
179179
// Lock bucket.
180-
CurBucket.Guard.lock();
180+
std::scoped_lock<std::mutex> Lock(CurBucket.Guard);
181181
#endif
182182

183183
HashesPtr BucketHashes = CurBucket.Hashes;
@@ -195,11 +195,6 @@ class ConcurrentHashTableByPtr {
195195

196196
CurBucket.NumberOfEntries++;
197197
RehashBucket(CurBucket);
198-
199-
#if LLVM_ENABLE_THREADS
200-
CurBucket.Guard.unlock();
201-
#endif
202-
203198
return {NewData, true};
204199
}
205200

@@ -208,10 +203,6 @@ class ConcurrentHashTableByPtr {
208203
KeyDataTy *EntryData = BucketEntries[CurEntryIdx];
209204
if (Info::isEqual(Info::getKey(*EntryData), NewValue)) {
210205
// Already existed entry matched with inserted data is found.
211-
#if LLVM_ENABLE_THREADS
212-
CurBucket.Guard.unlock();
213-
#endif
214-
215206
return {EntryData, false};
216207
}
217208
}

0 commit comments

Comments
 (0)