Skip to content

Commit 325cd27

Browse files
committed
[Support] Adopt new LockFileManager API in VirtualOutputBackends.cpp
(cherry picked from commit 1836b41)
1 parent 52690c0 commit 325cd27

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

llvm/lib/Support/VirtualOutputBackends.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -460,51 +460,48 @@ Error OnDiskOutputFile::keep() {
460460
while (1) {
461461
// Attempt to lock the output file.
462462
// Only one process is allowed to append to this file at a time.
463-
llvm::LockFileManager Locked(OutputPath);
464-
switch (Locked) {
465-
case llvm::LockFileManager::LFS_Error: {
463+
llvm::LockFileManager Lock(OutputPath);
464+
bool Owned;
465+
if (Error Err = Lock.tryLock().moveInto(Owned)) {
466466
// If we error acquiring a lock, we cannot ensure appends
467467
// to the trace file are atomic - cannot ensure output correctness.
468-
Locked.unsafeRemoveLockFile();
468+
Lock.unsafeRemoveLockFile();
469469
return convertToOutputError(
470470
OutputPath, std::make_error_code(std::errc::no_lock_available));
471471
}
472-
case llvm::LockFileManager::LFS_Owned: {
472+
if (Owned) {
473473
// Lock acquired, perform the write and release the lock.
474474
std::error_code EC;
475475
llvm::raw_fd_ostream Out(OutputPath, EC, llvm::sys::fs::OF_Append);
476476
if (EC)
477477
return convertToOutputError(OutputPath, EC);
478478
Out << (*Content)->getBuffer();
479479
Out.close();
480-
Locked.unsafeRemoveLockFile();
480+
Lock.unsafeRemoveLockFile();
481481
if (Out.has_error())
482482
return convertToOutputError(OutputPath, Out.error());
483483
// Remove temp file and done.
484484
(void)sys::fs::remove(*TempPath);
485485
return Error::success();
486486
}
487-
case llvm::LockFileManager::LFS_Shared: {
488-
// Someone else owns the lock on this file, wait.
489-
switch (Locked.waitForUnlock(256)) {
490-
case llvm::LockFileManager::Res_Success:
491-
LLVM_FALLTHROUGH;
492-
case llvm::LockFileManager::Res_OwnerDied: {
493-
continue; // try again to get the lock.
494-
}
495-
case llvm::LockFileManager::Res_Timeout: {
496-
// We could error on timeout to avoid potentially hanging forever, but
497-
// it may be more likely that an interrupted process failed to clear
498-
// the lock, causing other waiting processes to time-out. Let's clear
499-
// the lock and try again right away. If we do start seeing compiler
500-
// hangs in this location, we will need to re-consider.
501-
Locked.unsafeRemoveLockFile();
502-
continue;
503-
}
504-
}
505-
break;
487+
// Someone else owns the lock on this file, wait.
488+
switch (Lock.waitForUnlock(256)) {
489+
case llvm::LockFileManager::Res_Success:
490+
LLVM_FALLTHROUGH;
491+
case llvm::LockFileManager::Res_OwnerDied: {
492+
continue; // try again to get the lock.
506493
}
494+
case llvm::LockFileManager::Res_Timeout: {
495+
// We could error on timeout to avoid potentially hanging forever, but
496+
// it may be more likely that an interrupted process failed to clear
497+
// the lock, causing other waiting processes to time-out. Let's clear
498+
// the lock and try again right away. If we do start seeing compiler
499+
// hangs in this location, we will need to re-consider.
500+
Lock.unsafeRemoveLockFile();
501+
continue;
507502
}
503+
}
504+
break;
508505
}
509506
}
510507

0 commit comments

Comments
 (0)