aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization/GlobalModuleIndex.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2025-03-11 13:49:44 -0700
committerGitHub <noreply@github.com>2025-03-11 13:49:44 -0700
commitdafb566710cd03b7fbb4b187a91f32be9452fd8c (patch)
treef9172bdc54446b2880444d5b0d0dbd69d2533e61 /clang/lib/Serialization/GlobalModuleIndex.cpp
parent7573ee17813b266fdca4dc3041d07bbe616df458 (diff)
downloadllvm-dafb566710cd03b7fbb4b187a91f32be9452fd8c.zip
llvm-dafb566710cd03b7fbb4b187a91f32be9452fd8c.tar.gz
llvm-dafb566710cd03b7fbb4b187a91f32be9452fd8c.tar.bz2
[Support] Return `LockFileManager` errors right away (#130627)
This patch removes some internal state out of `LockFileManager` by moving the locking code from the constructor into new member function `tryLock()` which returns the errors right away. This simplifies and modernizes the interface.
Diffstat (limited to 'clang/lib/Serialization/GlobalModuleIndex.cpp')
-rw-r--r--clang/lib/Serialization/GlobalModuleIndex.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp
index 4b920fc..1e2272c 100644
--- a/clang/lib/Serialization/GlobalModuleIndex.cpp
+++ b/clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -849,22 +849,21 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr,
// Coordinate building the global index file with other processes that might
// try to do the same.
- llvm::LockFileManager Locked(IndexPath);
- switch (Locked) {
- case llvm::LockFileManager::LFS_Error:
+ llvm::LockFileManager Lock(IndexPath);
+ bool Owned;
+ if (llvm::Error Err = Lock.tryLock().moveInto(Owned)) {
+ llvm::consumeError(std::move(Err));
return llvm::createStringError(std::errc::io_error, "LFS error");
-
- case llvm::LockFileManager::LFS_Owned:
- // We're responsible for building the index ourselves. Do so below.
- break;
-
- case llvm::LockFileManager::LFS_Shared:
+ }
+ if (!Owned) {
// Someone else is responsible for building the index. We don't care
// when they finish, so we're done.
return llvm::createStringError(std::errc::device_or_resource_busy,
"someone else is building the index");
}
+ // We're responsible for building the index ourselves.
+
// The module index builder.
GlobalModuleIndexBuilder Builder(FileMgr, PCHContainerRdr);