[LockFileManager] Make default waitForUnlock timeout a parameter, NFC
authorVedant Kumar <vsk@apple.com>
Fri, 10 Jan 2020 23:24:30 +0000 (15:24 -0800)
committerVedant Kumar <vsk@apple.com>
Fri, 10 Jan 2020 23:24:32 +0000 (15:24 -0800)
Patch by Xi Ge!

llvm/include/llvm/Support/LockFileManager.h
llvm/lib/Support/LockFileManager.cpp

index 57e4fbd..2efeca3 100644 (file)
@@ -77,7 +77,9 @@ public:
   operator LockFileState() const { return getState(); }
 
   /// For a shared lock, wait until the owner releases the lock.
-  WaitForUnlockResult waitForUnlock();
+  /// Total timeout for the file to appear is ~1.5 minutes.
+  /// \param MaxSeconds the maximum wait time per iteration in seconds.
+  WaitForUnlockResult waitForUnlock(const unsigned MaxSeconds = 40);
 
   /// Remove the lock file.  This may delete a different lock file than
   /// the one previously read if there is a race.
index 1018119..5c6508c 100644 (file)
@@ -290,7 +290,8 @@ LockFileManager::~LockFileManager() {
   sys::DontRemoveFileOnSignal(UniqueLockFileName);
 }
 
-LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() {
+LockFileManager::WaitForUnlockResult
+LockFileManager::waitForUnlock(const unsigned MaxSeconds) {
   if (getState() != LFS_Shared)
     return Res_Success;
 
@@ -301,9 +302,6 @@ LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock() {
   Interval.tv_sec = 0;
   Interval.tv_nsec = 1000000;
 #endif
-  // Don't wait more than 40s per iteration. Total timeout for the file
-  // to appear is ~1.5 minutes.
-  const unsigned MaxSeconds = 40;
   do {
     // Sleep for the designated interval, to allow the owning process time to
     // finish up and remove the lock file.