summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/Support/LockFileManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/Support/LockFileManager.cpp')
-rw-r--r--contrib/llvm/lib/Support/LockFileManager.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/contrib/llvm/lib/Support/LockFileManager.cpp b/contrib/llvm/lib/Support/LockFileManager.cpp
index 611f94a..444aaa3 100644
--- a/contrib/llvm/lib/Support/LockFileManager.cpp
+++ b/contrib/llvm/lib/Support/LockFileManager.cpp
@@ -6,13 +6,22 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
+
#include "llvm/Support/LockFileManager.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Errc.h"
+#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Signals.h"
+#include <cerrno>
+#include <ctime>
+#include <memory>
+#include <tuple>
+#include <system_error>
#include <sys/stat.h>
#include <sys/types.h>
#if LLVM_ON_WIN32
@@ -31,6 +40,7 @@
#if USE_OSX_GETHOSTUUID
#include <uuid/uuid.h>
#endif
+
using namespace llvm;
/// \brief Attempt to read the lock file with the given name, if it exists.
@@ -112,6 +122,7 @@ bool LockFileManager::processStillExecuting(StringRef HostID, int PID) {
}
namespace {
+
/// An RAII helper object ensure that the unique lock file is removed.
///
/// Ensures that if there is an error or a signal before we finish acquiring the
@@ -127,6 +138,7 @@ public:
: Filename(Name), RemoveImmediately(true) {
sys::RemoveFileOnSignal(Filename, nullptr);
}
+
~RemoveUniqueLockFileOnSignal() {
if (!RemoveImmediately) {
// Leave the signal handler enabled. It will be removed when the lock is
@@ -136,8 +148,10 @@ public:
sys::fs::remove(Filename);
sys::DontRemoveFileOnSignal(Filename);
}
+
void lockAcquired() { RemoveImmediately = false; }
};
+
} // end anonymous namespace
LockFileManager::LockFileManager(StringRef FileName)
@@ -202,7 +216,7 @@ LockFileManager::LockFileManager(StringRef FileName)
// held since the .lock symlink will point to a nonexistent file.
RemoveUniqueLockFileOnSignal RemoveUniqueFile(UniqueLockFileName);
- while (1) {
+ while (true) {
// Create a link from the lock file name. If this succeeds, we're done.
std::error_code EC =
sys::fs::create_link(UniqueLockFileName, LockFileName);
OpenPOWER on IntegriCloud