X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=lib%2FSupport%2FLockFileManager.cpp;h=2b7fc812d51972700ee0fcceb989609b03384a5c;hb=7acd886ecfa0adc8a14476eafe8cf1fa981cfe18;hp=55858473f598bf22d6197f1002f0aa2b83c41246;hpb=fb307be5afa79bc65b75885ee6c3ced3b450b037;p=oota-llvm.git diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp index 55858473f59..2b7fc812d51 100644 --- a/lib/Support/LockFileManager.cpp +++ b/lib/Support/LockFileManager.cpp @@ -43,8 +43,11 @@ LockFileManager::readLockFile(StringRef LockFileName) { std::tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " "); PIDStr = PIDStr.substr(PIDStr.find_first_not_of(" ")); int PID; - if (!PIDStr.getAsInteger(10, PID)) - return std::make_pair(std::string(Hostname), PID); + if (!PIDStr.getAsInteger(10, PID)) { + auto Owner = std::make_pair(std::string(Hostname), PID); + if (processStillExecuting(Owner.first, Owner.second)) + return Owner; + } // Delete the lock file. It's invalid anyway. sys::fs::remove(LockFileName); @@ -68,7 +71,11 @@ bool LockFileManager::processStillExecuting(StringRef Hostname, int PID) { LockFileManager::LockFileManager(StringRef FileName) { this->FileName = FileName; - LockFileName = FileName; + if (error_code EC = sys::fs::make_absolute(this->FileName)) { + Error = EC; + return; + } + LockFileName = this->FileName; LockFileName += ".lock"; // If the lock file already exists, don't bother to try to create our own @@ -107,7 +114,7 @@ LockFileManager::LockFileManager(StringRef FileName) if (Out.has_error()) { // We failed to write out PID, so make up an excuse, remove the // unique lock file, and fail. - Error = make_error_code(errc::no_space_on_device); + Error = make_error_code(std::errc::no_space_on_device); sys::fs::remove(UniqueLockFileName.c_str()); return; } @@ -116,12 +123,11 @@ LockFileManager::LockFileManager(StringRef FileName) while (1) { // Create a link from the lock file name. If this succeeds, we're done. error_code EC = - sys::fs::create_link(sys::path::filename(UniqueLockFileName.str()), - LockFileName.str()); - if (EC == errc::success) + sys::fs::create_link(UniqueLockFileName.str(), LockFileName.str()); + if (!EC) return; - if (EC != errc::file_exists) { + if (EC != std::errc::file_exists) { Error = EC; return; } @@ -168,9 +174,9 @@ LockFileManager::~LockFileManager() { sys::fs::remove(UniqueLockFileName.str()); } -void LockFileManager::waitForUnlock() { +LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() { if (getState() != LFS_Shared) - return; + return Res_Success; #if LLVM_ON_WIN32 unsigned long Interval = 1; @@ -190,7 +196,7 @@ void LockFileManager::waitForUnlock() { #if LLVM_ON_WIN32 Sleep(Interval); #else - nanosleep(&Interval, NULL); + nanosleep(&Interval, nullptr); #endif bool LockFileJustDisappeared = false; @@ -208,7 +214,7 @@ void LockFileManager::waitForUnlock() { // available now. if (LockFileGone) { if (sys::fs::exists(FileName.str())) { - return; + return Res_Success; } // The lock file is gone, so now we're waiting for the original file to @@ -231,7 +237,7 @@ void LockFileManager::waitForUnlock() { // owning the lock died without cleaning up, just bail out. if (!LockFileGone && !processStillExecuting((*Owner).first, (*Owner).second)) { - return; + return Res_OwnerDied; } // Exponentially increase the time we wait for the lock to be removed. @@ -254,4 +260,5 @@ void LockFileManager::waitForUnlock() { ); // Give up. + return Res_Timeout; }