[llvm-commits] [llvm] r172033 - in /llvm/trunk: include/llvm/Support/LockFileManager.h lib/Support/LockFileManager.cpp
Douglas Gregor
dgregor at apple.com
Wed Jan 9 18:01:35 PST 2013
Author: dgregor
Date: Wed Jan 9 20:01:35 2013
New Revision: 172033
URL: http://llvm.org/viewvc/llvm-project?rev=172033&view=rev
Log:
Fix a race condition in the lock-file manager: once the lock file is
gone, check for the actual file we care about.
Modified:
llvm/trunk/include/llvm/Support/LockFileManager.h
llvm/trunk/lib/Support/LockFileManager.cpp
Modified: llvm/trunk/include/llvm/Support/LockFileManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/LockFileManager.h?rev=172033&r1=172032&r2=172033&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/LockFileManager.h (original)
+++ llvm/trunk/include/llvm/Support/LockFileManager.h Wed Jan 9 20:01:35 2013
@@ -41,6 +41,7 @@
};
private:
+ SmallString<128> FileName;
SmallString<128> LockFileName;
SmallString<128> UniqueLockFileName;
Modified: llvm/trunk/lib/Support/LockFileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/LockFileManager.cpp?rev=172033&r1=172032&r2=172033&view=diff
==============================================================================
--- llvm/trunk/lib/Support/LockFileManager.cpp (original)
+++ llvm/trunk/lib/Support/LockFileManager.cpp Wed Jan 9 20:01:35 2013
@@ -64,6 +64,7 @@
LockFileManager::LockFileManager(StringRef FileName)
{
+ this->FileName = FileName;
LockFileName = FileName;
LockFileName += ".lock";
@@ -175,6 +176,7 @@
#endif
// Don't wait more than an hour for the file to appear.
const unsigned MaxSeconds = 3600;
+ bool LockFileGone = false;
do {
// Sleep for the designated interval, to allow the owning process time to
// finish up and remove the lock file.
@@ -185,10 +187,18 @@
#else
nanosleep(&Interval, NULL);
#endif
- // If the file no longer exists, we're done.
+ // If the lock file no longer exists, wait for the actual file.
bool Exists = false;
- if (!sys::fs::exists(LockFileName.str(), Exists) && !Exists)
- return;
+ if (!LockFileGone) {
+ if (!sys::fs::exists(LockFileName.str(), Exists) && !Exists) {
+ LockFileGone = true;
+ Exists = false;
+ }
+ }
+ if (LockFileGone) {
+ if (!sys::fs::exists(FileName.str(), Exists) && Exists)
+ return;
+ }
if (!processStillExecuting((*Owner).first, (*Owner).second))
return;
More information about the llvm-commits
mailing list