llvm.org GIT mirror llvm / 20384a5
[Support] Modify LockFileManager::waitForUnlock() to return info about how the lock was released. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205683 91177308-0d34-0410-b5e6-96231b3b80d8 Argyrios Kyrtzidis 6 years ago
2 changed file(s) with 22 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
3939 LFS_Error
4040 };
4141
42 /// \brief Describes the result of waiting for the owner to release the lock.
43 enum WaitForUnlockResult {
44 /// \brief The lock was released successfully.
45 Res_Success,
46 /// \brief Owner died while holding the lock.
47 Res_OwnerDied,
48 /// \brief Reached timeout while waiting for the owner to release the lock.
49 Res_Timeout
50 };
51
4252 private:
4353 SmallString<128> FileName;
4454 SmallString<128> LockFileName;
6676 operator LockFileState() const { return getState(); }
6777
6878 /// \brief For a shared lock, wait until the owner releases the lock.
69 void waitForUnlock();
79 WaitForUnlockResult waitForUnlock();
7080 };
7181
7282 } // end namespace llvm
4242 std::tie(Hostname, PIDStr) = getToken(MB->getBuffer(), " ");
4343 PIDStr = PIDStr.substr(PIDStr.find_first_not_of(" "));
4444 int PID;
45 if (!PIDStr.getAsInteger(10, PID))
46 return std::make_pair(std::string(Hostname), PID);
45 if (!PIDStr.getAsInteger(10, PID)) {
46 auto Owner = std::make_pair(std::string(Hostname), PID);
47 if (processStillExecuting(Owner.first, Owner.second))
48 return Owner;
49 }
4750
4851 // Delete the lock file. It's invalid anyway.
4952 sys::fs::remove(LockFileName);
170173 sys::fs::remove(UniqueLockFileName.str());
171174 }
172175
173 void LockFileManager::waitForUnlock() {
176 LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() {
174177 if (getState() != LFS_Shared)
175 return;
178 return Res_Success;
176179
177180 #if LLVM_ON_WIN32
178181 unsigned long Interval = 1;
210213 // available now.
211214 if (LockFileGone) {
212215 if (sys::fs::exists(FileName.str())) {
213 return;
216 return Res_Success;
214217 }
215218
216219 // The lock file is gone, so now we're waiting for the original file to
233236 // owning the lock died without cleaning up, just bail out.
234237 if (!LockFileGone &&
235238 !processStillExecuting((*Owner).first, (*Owner).second)) {
236 return;
239 return Res_OwnerDied;
237240 }
238241
239242 // Exponentially increase the time we wait for the lock to be removed.
256259 );
257260
258261 // Give up.
259 }
262 return Res_Timeout;
263 }