From b915e9e0fc85ba6f398b3fab0db6a81a8913af94 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Mon, 2 Jan 2017 19:17:04 +0000 Subject: Vendor import of llvm trunk r290819: https://llvm.org/svn/llvm-project/llvm/trunk@290819 --- lib/Support/LockFileManager.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/Support/LockFileManager.cpp') diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp index 611f94a9709b..444aaa37c8c8 100644 --- a/lib/Support/LockFileManager.cpp +++ b/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 +#include +#include +#include +#include #include #include #if LLVM_ON_WIN32 @@ -31,6 +40,7 @@ #if USE_OSX_GETHOSTUUID #include #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); -- cgit v1.3