LLVM 22.0.0git
llvm::AdvisoryLock Class Referenceabstract

A synchronization primitive with weak mutual exclusion guarantees. More...

#include "llvm/Support/AdvisoryLock.h"

Inheritance diagram for llvm::AdvisoryLock:
[legend]

Public Member Functions

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

A synchronization primitive with weak mutual exclusion guarantees.

Implementations of this interface may allow multiple threads/processes to acquire the ownership of the lock simultaneously. Typically, threads/processes waiting for the lock to be unlocked will validate that the computation was performed by the expected thread/process and re-run the computation if not.

Definition at line 33 of file AdvisoryLock.h.

Constructor & Destructor Documentation

◆ ~AdvisoryLock()

virtual llvm::AdvisoryLock::~AdvisoryLock ( )
virtualdefault

Unlocks the lock if its ownership was previously acquired by tryLock().

Member Function Documentation

◆ tryLock()

virtual Expected< bool > llvm::AdvisoryLock::tryLock ( )
pure virtual

Tries to acquire ownership of the lock without blocking.

Returns
true if ownership of the lock was acquired successfully, false if the lock is already owned by someone else, or Error in case of an unexpected failure.

Implemented in llvm::LockFileManager.

◆ unsafeMaybeUnlock()

virtual std::error_code llvm::AdvisoryLock::unsafeMaybeUnlock ( )
pure virtual

For a lock owned by someone else, unlock it.

A permitted side-effect is that another thread/process may acquire ownership of the lock before the existing owner unlocks it. This is an unsafe operation.

Implemented in llvm::LockFileManager.

◆ waitForUnlockFor()

virtual WaitForUnlockResult llvm::AdvisoryLock::waitForUnlockFor ( std::chrono::seconds MaxSeconds)
pure virtual

For a lock owned by someone else, wait until it is unlocked.

Parameters
MaxSecondsthe maximum total wait time in seconds.

Implemented in llvm::LockFileManager.


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