@@ -392,53 +392,48 @@ bool ImplicitModuleInterfaceBuilder::buildSwiftModule(StringRef OutPath,
392392 // processes are doing the same.
393393 // FIXME: We should surface the module building step to the build system so
394394 // we don't need to synchronize here.
395- llvm::LockFileManager Locked (OutPath);
396- switch (Locked) {
397- case llvm::LockFileManager::LFS_Error:{
395+ llvm::LockFileManager Lock (OutPath);
396+ bool Owned;
397+ if (llvm::Error Err = Lock.tryLock ().moveInto (Owned)) {
398+ llvm::consumeError (std::move (Err));
398399 // ModuleInterfaceBuilder takes care of correctness and locks are only
399400 // necessary for performance. Fallback to building the module in case of any lock
400401 // related errors.
401402 if (RemarkRebuild) {
402403 diagnose (diag::interface_file_lock_failure);
403404 }
404- // Clear out any potential leftover.
405- Locked.unsafeRemoveLockFile ();
406- LLVM_FALLTHROUGH;
405+ return build ();
407406 }
408- case llvm::LockFileManager::LFS_Owned: {
407+ if (Owned) {
409408 return build ();
410409 }
411- case llvm::LockFileManager::LFS_Shared: {
412- // Someone else is responsible for building the module. Wait for them to
413- // finish.
414- switch (Locked.waitForUnlock (256 )) {
415- case llvm::LockFileManager::Res_Success: {
416- // This process may have a different module output path. If the other
417- // process doesn't build the interface to this output path, we should try
418- // building ourselves.
419- auto bufferOrError = llvm::MemoryBuffer::getFile (OutPath);
420- if (!bufferOrError)
421- continue ;
422- if (ModuleBuffer)
423- *ModuleBuffer = std::move (bufferOrError.get ());
424- return false ;
425- }
426- case llvm::LockFileManager::Res_OwnerDied: {
427- continue ; // try again to get the lock.
428- }
429- case llvm::LockFileManager::Res_Timeout: {
430- // Since ModuleInterfaceBuilder takes care of correctness, we try waiting for
431- // another process to complete the build so swift does not do it done
432- // twice. If case of timeout, build it ourselves.
433- if (RemarkRebuild) {
434- diagnose (diag::interface_file_lock_timed_out, interfacePath);
435- }
436- // Clear the lock file so that future invocations can make progress.
437- Locked.unsafeRemoveLockFile ();
410+ // Someone else is responsible for building the module. Wait for them to
411+ // finish.
412+ switch (Lock.waitForUnlockFor (std::chrono::seconds (256 ))) {
413+ case llvm::WaitForUnlockResult::Success: {
414+ // This process may have a different module output path. If the other
415+ // process doesn't build the interface to this output path, we should try
416+ // building ourselves.
417+ auto bufferOrError = llvm::MemoryBuffer::getFile (OutPath);
418+ if (!bufferOrError)
438419 continue ;
420+ if (ModuleBuffer)
421+ *ModuleBuffer = std::move (bufferOrError.get ());
422+ return false ;
423+ }
424+ case llvm::WaitForUnlockResult::OwnerDied: {
425+ continue ; // try again to get the lock.
426+ }
427+ case llvm::WaitForUnlockResult::Timeout: {
428+ // Since ModuleInterfaceBuilder takes care of correctness, we try waiting for
429+ // another process to complete the build so swift does not do it done
430+ // twice. If case of timeout, build it ourselves.
431+ if (RemarkRebuild) {
432+ diagnose (diag::interface_file_lock_timed_out, interfacePath);
439433 }
440- }
441- break ;
434+ // Clear the lock file so that future invocations can make progress.
435+ Lock.unsafeMaybeUnlock ();
436+ continue ;
442437 }
443438 }
444439 }
0 commit comments