LLVM  8.0.1
Public Types | Public Member Functions | List of all members
llvm::LockFileManager Class Reference

Class that manages the creation of a lock file to aid implicit coordination between different processes. More...

#include "llvm/Support/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...
 
std::string getErrorMessage () const
 Get error message, or "" if there is no error. More...
 
void setError (const std::error_code &EC, StringRef ErrorMsg="")
 Set error and error message. More...
 

Detailed Description

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 28 of file LockFileManager.h.

Member Enumeration Documentation

◆ LockFileState

Describes the state of a lock file.

Enumerator
LFS_Owned 

The lock file has been created and is owned by this instance of the object.

LFS_Shared 

The lock file already exists and is owned by some other instance.

LFS_Error 

An error occurred while trying to create or find the lock file.

Definition at line 31 of file LockFileManager.h.

◆ WaitForUnlockResult

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 44 of file LockFileManager.h.

Constructor & Destructor Documentation

◆ LockFileManager()

LockFileManager::LockFileManager ( StringRef  FileName)

◆ ~LockFileManager()

LockFileManager::~LockFileManager ( )

Member Function Documentation

◆ getErrorMessage()

std::string LockFileManager::getErrorMessage ( ) const

Get error message, or "" if there is no error.

Definition at line 270 of file LockFileManager.cpp.

References llvm::raw_string_ostream::str().

Referenced by operator LockFileState().

◆ getState()

LockFileManager::LockFileState LockFileManager::getState ( ) const

Determine the state of the lock file.

Definition at line 260 of file LockFileManager.cpp.

References LFS_Error, LFS_Owned, and LFS_Shared.

Referenced by operator LockFileState(), waitForUnlock(), and ~LockFileManager().

◆ operator LockFileState()

llvm::LockFileManager::operator LockFileState ( ) const
inline

◆ setError()

void llvm::LockFileManager::setError ( const std::error_code &  EC,
StringRef  ErrorMsg = "" 
)
inline

Set error and error message.

Definition at line 91 of file LockFileManager.h.

Referenced by LockFileManager().

◆ unsafeRemoveLockFile()

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 354 of file LockFileManager.cpp.

References llvm::sys::fs::remove().

Referenced by operator LockFileState().

◆ waitForUnlock()

LockFileManager::WaitForUnlockResult LockFileManager::waitForUnlock ( )

For a shared lock, wait until the owner releases the lock.

Definition at line 294 of file LockFileManager.cpp.

References llvm::sys::fs::access(), llvm::sys::fs::Exist, llvm::sys::fs::exists(), getState(), LFS_Shared, llvm::no_such_file_or_directory, Res_OwnerDied, Res_Success, and Res_Timeout.

Referenced by operator LockFileState().


The documentation for this class was generated from the following files: