diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:17:04 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:17:04 +0000 |
| commit | b915e9e0fc85ba6f398b3fab0db6a81a8913af94 (patch) | |
| tree | 98b8f811c7aff2547cab8642daf372d6c59502fb /lib/Support/LockFileManager.cpp | |
| parent | 6421cca32f69ac849537a3cff78c352195e99f1b (diff) | |
Notes
Diffstat (limited to 'lib/Support/LockFileManager.cpp')
| -rw-r--r-- | lib/Support/LockFileManager.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
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 <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); |
