LFS_Error
};
+ /// \brief Describes the result of waiting for the owner to release the lock.
+ enum WaitForUnlockResult {
+ /// \brief The lock was released successfully.
+ Res_Success,
+ /// \brief Owner died while holding the lock.
+ Res_OwnerDied,
+ /// \brief Reached timeout while waiting for the owner to release the lock.
+ Res_Timeout
+ };
+
private:
SmallString<128> FileName;
SmallString<128> LockFileName;
operator LockFileState() const { return getState(); }
/// \brief For a shared lock, wait until the owner releases the lock.
- void waitForUnlock();
+ WaitForUnlockResult waitForUnlock();
};
} // end namespace llvm
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);
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;
// 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
// 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.
);
// Give up.
+ return Res_Timeout;
}