summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-04-06 03:19:31 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-04-06 03:19:31 +0000
commit44ec0a7d76ce04ed6b5f792a00c043e2ac09a86a (patch)
tree73c51fd2a47e70c42d49e3dd62998fc7e5719ec9 /llvm
parentb38ac1f7ee5bff721838ad41a633374d62bf66d5 (diff)
downloadbcm5719-llvm-44ec0a7d76ce04ed6b5f792a00c043e2ac09a86a.tar.gz
bcm5719-llvm-44ec0a7d76ce04ed6b5f792a00c043e2ac09a86a.zip
[Support] Modify LockFileManager::waitForUnlock() to return info about how the lock was released.
llvm-svn: 205683
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Support/LockFileManager.h12
-rw-r--r--llvm/lib/Support/LockFileManager.cpp16
2 files changed, 21 insertions, 7 deletions
diff --git a/llvm/include/llvm/Support/LockFileManager.h b/llvm/include/llvm/Support/LockFileManager.h
index 9df8675ef0a..523a781b87d 100644
--- a/llvm/include/llvm/Support/LockFileManager.h
+++ b/llvm/include/llvm/Support/LockFileManager.h
@@ -40,6 +40,16 @@ public:
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;
@@ -67,7 +77,7 @@ public:
operator LockFileState() const { return getState(); }
/// \brief For a shared lock, wait until the owner releases the lock.
- void waitForUnlock();
+ WaitForUnlockResult waitForUnlock();
};
} // end namespace llvm
diff --git a/llvm/lib/Support/LockFileManager.cpp b/llvm/lib/Support/LockFileManager.cpp
index cd1cbcb2c5b..fb07801a14b 100644
--- a/llvm/lib/Support/LockFileManager.cpp
+++ b/llvm/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);
@@ -171,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;
@@ -211,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
@@ -234,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.
@@ -257,4 +260,5 @@ void LockFileManager::waitForUnlock() {
);
// Give up.
+ return Res_Timeout;
}
OpenPOWER on IntegriCloud