@@ -460,51 +460,48 @@ Error OnDiskOutputFile::keep() {
460
460
while (1 ) {
461
461
// Attempt to lock the output file.
462
462
// 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)) {
466
466
// If we error acquiring a lock, we cannot ensure appends
467
467
// to the trace file are atomic - cannot ensure output correctness.
468
- Locked .unsafeRemoveLockFile ();
468
+ Lock .unsafeRemoveLockFile ();
469
469
return convertToOutputError (
470
470
OutputPath, std::make_error_code (std::errc::no_lock_available));
471
471
}
472
- case llvm::LockFileManager::LFS_Owned: {
472
+ if (Owned) {
473
473
// Lock acquired, perform the write and release the lock.
474
474
std::error_code EC;
475
475
llvm::raw_fd_ostream Out (OutputPath, EC, llvm::sys::fs::OF_Append);
476
476
if (EC)
477
477
return convertToOutputError (OutputPath, EC);
478
478
Out << (*Content)->getBuffer ();
479
479
Out.close ();
480
- Locked .unsafeRemoveLockFile ();
480
+ Lock .unsafeRemoveLockFile ();
481
481
if (Out.has_error ())
482
482
return convertToOutputError (OutputPath, Out.error ());
483
483
// Remove temp file and done.
484
484
(void )sys::fs::remove (*TempPath);
485
485
return Error::success ();
486
486
}
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.
506
493
}
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 ;
507
502
}
503
+ }
504
+ break ;
508
505
}
509
506
}
510
507
0 commit comments