[clang] 5882283 - [clang][deps] Use lock_guard instead of unique_lock
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 9 01:43:34 PST 2021
Author: Jan Svoboda
Date: 2021-12-09T10:42:50+01:00
New Revision: 58822837cd53cdbe9c1b878c705b288f17a52f98
URL: https://github.com/llvm/llvm-project/commit/58822837cd53cdbe9c1b878c705b288f17a52f98
DIFF: https://github.com/llvm/llvm-project/commit/58822837cd53cdbe9c1b878c705b288f17a52f98.diff
LOG: [clang][deps] Use lock_guard instead of unique_lock
This patch changes uses of `std::unique_lock` to `std::lock_guard`.
The `std::unique_lock` template provides some advanced capabilities (deferred locking, time-constrained locking attempts, etc.) we don't use in the caching filesystem. Plain `std::lock_guard` will do here.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D115332
Added:
Modified:
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index f7c711690d7ea..8a85f5971f4b2 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -113,7 +113,7 @@ DependencyScanningFilesystemSharedCache::SingleCache::SingleCache() {
DependencyScanningFilesystemSharedCache::SharedFileSystemEntry &
DependencyScanningFilesystemSharedCache::SingleCache::get(StringRef Key) {
CacheShard &Shard = CacheShards[llvm::hash_value(Key) % NumShards];
- std::unique_lock<std::mutex> LockGuard(Shard.CacheLock);
+ std::lock_guard<std::mutex> LockGuard(Shard.CacheLock);
auto It = Shard.Cache.try_emplace(Key);
return It.first->getValue();
}
@@ -195,7 +195,7 @@ DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
&SharedCacheEntry = SharedCache.get(Filename, ShouldMinimize);
const CachedFileSystemEntry *Result;
{
- std::unique_lock<std::mutex> LockGuard(SharedCacheEntry.ValueLock);
+ std::lock_guard<std::mutex> LockGuard(SharedCacheEntry.ValueLock);
CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value;
if (!CacheEntry.isValid()) {
More information about the cfe-commits
mailing list