|
LLVM
3.7.0
|
Class that manages the creation of a lock file to aid implicit coordination between different processes. More...
#include <LockFileManager.h>
Public Types | |
| enum | LockFileState { LFS_Owned, LFS_Shared, LFS_Error } |
| Describes the state of a lock file. More... | |
| enum | WaitForUnlockResult { Res_Success, Res_OwnerDied, Res_Timeout } |
| Describes the result of waiting for the owner to release the lock. More... | |
Public Member Functions | |
| LockFileManager (StringRef FileName) | |
| ~LockFileManager () | |
| LockFileState | getState () const |
| Determine the state of the lock file. More... | |
| operator LockFileState () const | |
| WaitForUnlockResult | waitForUnlock () |
| For a shared lock, wait until the owner releases the lock. More... | |
| std::error_code | unsafeRemoveLockFile () |
| Remove the lock file. More... | |
Class that manages the creation of a lock file to aid implicit coordination between different processes.
The implicit coordination works by creating a ".lock" file alongside the file that we're coordinating for, using the atomicity of the file system to ensure that only a single process can create that ".lock" file. When the lock file is removed, the owning process has finished the operation.
Definition at line 27 of file LockFileManager.h.
Describes the state of a lock file.
Definition at line 30 of file LockFileManager.h.
Describes the result of waiting for the owner to release the lock.
| Enumerator | |
|---|---|
| Res_Success |
The lock was released successfully. |
| Res_OwnerDied |
Owner died while holding the lock. |
| Res_Timeout |
Reached timeout while waiting for the owner to release the lock. |
Definition at line 43 of file LockFileManager.h.
| LockFileManager::LockFileManager | ( | StringRef | FileName | ) |
Definition at line 143 of file LockFileManager.cpp.
References llvm::raw_fd_ostream::close(), llvm::sys::fs::create_link(), llvm::sys::fs::createUniqueFile(), llvm::sys::fs::exists(), llvm::file_exists, getHostID(), llvm::raw_fd_ostream::has_error(), llvm::sys::fs::make_absolute(), llvm::make_error_code(), llvm::no_space_on_device, and llvm::sys::fs::remove().
| LockFileManager::~LockFileManager | ( | ) |
Definition at line 245 of file LockFileManager.cpp.
References llvm::sys::DontRemoveFileOnSignal(), getState(), LFS_Owned, and llvm::sys::fs::remove().
| LockFileManager::LockFileState LockFileManager::getState | ( | ) | const |
Determine the state of the lock file.
Definition at line 235 of file LockFileManager.cpp.
References LFS_Error, LFS_Owned, and LFS_Shared.
Referenced by operator LockFileState(), waitForUnlock(), and ~LockFileManager().
|
inline |
Definition at line 76 of file LockFileManager.h.
References getState().
| std::error_code LockFileManager::unsafeRemoveLockFile | ( | ) |
Remove the lock file.
This may delete a different lock file than the one previously read if there is a race.
Definition at line 317 of file LockFileManager.cpp.
References llvm::sys::fs::remove().
| LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock | ( | ) |
For a shared lock, wait until the owner releases the lock.
Definition at line 257 of file LockFileManager.cpp.
References llvm::sys::fs::access(), llvm::SmallString< InternalLen >::c_str(), llvm::sys::fs::Exist, llvm::sys::fs::exists(), getState(), LFS_Shared, llvm::no_such_file_or_directory, Res_OwnerDied, Res_Success, and Res_Timeout.
1.8.6