mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Frontend] Use new LockFileManager APIs (#80123)
This commit is contained in:
@@ -392,53 +392,48 @@ bool ImplicitModuleInterfaceBuilder::buildSwiftModule(StringRef OutPath,
|
||||
// processes are doing the same.
|
||||
// FIXME: We should surface the module building step to the build system so
|
||||
// we don't need to synchronize here.
|
||||
llvm::LockFileManager Locked(OutPath);
|
||||
switch (Locked) {
|
||||
case llvm::LockFileManager::LFS_Error:{
|
||||
llvm::LockFileManager Lock(OutPath);
|
||||
bool Owned;
|
||||
if (llvm::Error Err = Lock.tryLock().moveInto(Owned)) {
|
||||
llvm::consumeError(std::move(Err));
|
||||
// ModuleInterfaceBuilder takes care of correctness and locks are only
|
||||
// necessary for performance. Fallback to building the module in case of any lock
|
||||
// related errors.
|
||||
if (RemarkRebuild) {
|
||||
diagnose(diag::interface_file_lock_failure);
|
||||
}
|
||||
// Clear out any potential leftover.
|
||||
Locked.unsafeRemoveLockFile();
|
||||
LLVM_FALLTHROUGH;
|
||||
}
|
||||
case llvm::LockFileManager::LFS_Owned: {
|
||||
return build();
|
||||
}
|
||||
case llvm::LockFileManager::LFS_Shared: {
|
||||
// Someone else is responsible for building the module. Wait for them to
|
||||
// finish.
|
||||
switch (Locked.waitForUnlock(256)) {
|
||||
case llvm::LockFileManager::Res_Success: {
|
||||
// This process may have a different module output path. If the other
|
||||
// process doesn't build the interface to this output path, we should try
|
||||
// building ourselves.
|
||||
auto bufferOrError = llvm::MemoryBuffer::getFile(OutPath);
|
||||
if (!bufferOrError)
|
||||
continue;
|
||||
if (ModuleBuffer)
|
||||
*ModuleBuffer = std::move(bufferOrError.get());
|
||||
return false;
|
||||
}
|
||||
case llvm::LockFileManager::Res_OwnerDied: {
|
||||
continue; // try again to get the lock.
|
||||
}
|
||||
case llvm::LockFileManager::Res_Timeout: {
|
||||
// Since ModuleInterfaceBuilder takes care of correctness, we try waiting for
|
||||
// another process to complete the build so swift does not do it done
|
||||
// twice. If case of timeout, build it ourselves.
|
||||
if (RemarkRebuild) {
|
||||
diagnose(diag::interface_file_lock_timed_out, interfacePath);
|
||||
}
|
||||
// Clear the lock file so that future invocations can make progress.
|
||||
Locked.unsafeRemoveLockFile();
|
||||
if (Owned) {
|
||||
return build();
|
||||
}
|
||||
// Someone else is responsible for building the module. Wait for them to
|
||||
// finish.
|
||||
switch (Lock.waitForUnlockFor(std::chrono::seconds(256))) {
|
||||
case llvm::WaitForUnlockResult::Success: {
|
||||
// This process may have a different module output path. If the other
|
||||
// process doesn't build the interface to this output path, we should try
|
||||
// building ourselves.
|
||||
auto bufferOrError = llvm::MemoryBuffer::getFile(OutPath);
|
||||
if (!bufferOrError)
|
||||
continue;
|
||||
if (ModuleBuffer)
|
||||
*ModuleBuffer = std::move(bufferOrError.get());
|
||||
return false;
|
||||
}
|
||||
case llvm::WaitForUnlockResult::OwnerDied: {
|
||||
continue; // try again to get the lock.
|
||||
}
|
||||
case llvm::WaitForUnlockResult::Timeout: {
|
||||
// Since ModuleInterfaceBuilder takes care of correctness, we try waiting for
|
||||
// another process to complete the build so swift does not do it done
|
||||
// twice. If case of timeout, build it ourselves.
|
||||
if (RemarkRebuild) {
|
||||
diagnose(diag::interface_file_lock_timed_out, interfacePath);
|
||||
}
|
||||
}
|
||||
break;
|
||||
// Clear the lock file so that future invocations can make progress.
|
||||
Lock.unsafeMaybeUnlock();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user