LLVM 22.0.0git
Classes | 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"

Inheritance diagram for llvm::LockFileManager:
[legend]

Public Member Functions

 LockFileManager (StringRef FileName)
 Does not try to acquire the lock.
 
Expected< booltryLock () override
 Tries to acquire the lock without blocking.
 
WaitForUnlockResult waitForUnlockFor (std::chrono::seconds MaxSeconds) override
 For a shared lock, wait until the owner releases the lock.
 
std::error_code unsafeMaybeUnlock () override
 Remove the lock file.
 
 ~LockFileManager () override
 Unlocks the lock if previously acquired by tryLock().
 
- Public Member Functions inherited from llvm::AdvisoryLock
virtual Expected< booltryLock ()=0
 Tries to acquire ownership of the lock without blocking.
 
virtual WaitForUnlockResult waitForUnlockFor (std::chrono::seconds MaxSeconds)=0
 For a lock owned by someone else, wait until it is unlocked.
 
virtual std::error_code unsafeMaybeUnlock ()=0
 For a lock owned by someone else, unlock it.
 
virtual ~AdvisoryLock ()=default
 Unlocks the lock if its ownership was previously acquired by tryLock().
 

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, 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.

Constructor & Destructor Documentation

◆ LockFileManager()

LockFileManager::LockFileManager ( StringRef  FileName)

Does not try to acquire the lock.

Definition at line 160 of file LockFileManager.cpp.

◆ ~LockFileManager()

LockFileManager::~LockFileManager ( )
override

Unlocks the lock if previously acquired by tryLock().

Definition at line 248 of file LockFileManager.cpp.

References llvm::sys::DontRemoveFileOnSignal(), and llvm::sys::fs::remove().

Member Function Documentation

◆ tryLock()

Expected< bool > LockFileManager::tryLock ( )
overridevirtual

◆ unsafeMaybeUnlock()

std::error_code LockFileManager::unsafeMaybeUnlock ( )
overridevirtual

Remove the lock file.

This may delete a different lock file than the one previously read if there is a race.

Implements llvm::AdvisoryLock.

Definition at line 290 of file LockFileManager.cpp.

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

Referenced by llvm::AMDGPUSplitModulePass::run().

◆ waitForUnlockFor()

WaitForUnlockResult LockFileManager::waitForUnlockFor ( std::chrono::seconds  MaxSeconds)
overridevirtual

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

Parameters
MaxSecondsthe maximum total wait time in seconds.

Implements llvm::AdvisoryLock.

Definition at line 261 of file LockFileManager.cpp.

References llvm::sys::fs::access(), assert(), llvm::SmallString< InternalLen >::c_str(), llvm::sys::fs::Exist, llvm::no_such_file_or_directory, llvm::OwnerDied, llvm::Success, llvm::Timeout, and llvm::ExponentialBackoff::waitForNextAttempt().

Referenced by llvm::AMDGPUSplitModulePass::run().


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