CatapultServer  v0.5.0.1 (Elephant)
catapult::io::FileLock Class Reference

Lock based on an underlying lock file. More...

Inheritance diagram for catapult::io::FileLock:
Collaboration diagram for catapult::io::FileLock:

Public Types

using FdType = int
 

Public Member Functions

 FileLock (const std::string &lockFilePath)
 Creates a lock file with path lockFilePath. More...
 
 ~FileLock ()
 Releases the lock file. More...
 
void lock ()
 Blocks until a lock can be obtained for the current execution agent. More...
 
bool try_lock ()
 Attempts to acquire the lock for the current execution agent without blocking. More...
 
void unlock () noexcept
 Releases the lock held by the execution agent. Throws no exceptions. More...
 
- Public Member Functions inherited from catapult::utils::NonCopyable
constexpr NonCopyable ()=default
 Default constructor. More...
 
 ~NonCopyable ()=default
 Default destructor. More...
 
 NonCopyable (const NonCopyable &)=delete
 Disabled copy constructor. More...
 
NonCopyableoperator= (const NonCopyable &)=delete
 Disabled assignment operator. More...
 

Private Attributes

std::string m_lockFilePath
 
utils::SpinLock m_spinLock
 
FdType m_fd
 

Detailed Description

Lock based on an underlying lock file.

Member Typedef Documentation

◆ FdType

Implementation dependent type of file descriptor.

Note
Windows version is using void* instead of HANDLE to avoid including windows.h

Constructor & Destructor Documentation

◆ FileLock()

catapult::io::FileLock::FileLock ( const std::string &  lockFilePath)
explicit

Creates a lock file with path lockFilePath.

◆ ~FileLock()

catapult::io::FileLock::~FileLock ( )

Releases the lock file.

Here is the call graph for this function:

Member Function Documentation

◆ lock()

void catapult::io::FileLock::lock ( )

Blocks until a lock can be obtained for the current execution agent.

Here is the call graph for this function:

◆ try_lock()

bool catapult::io::FileLock::try_lock ( )

Attempts to acquire the lock for the current execution agent without blocking.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unlock()

void catapult::io::FileLock::unlock ( )
noexcept

Releases the lock held by the execution agent. Throws no exceptions.

Here is the caller graph for this function:

Member Data Documentation

◆ m_fd

FdType catapult::io::FileLock::m_fd
private

◆ m_lockFilePath

std::string catapult::io::FileLock::m_lockFilePath
private

◆ m_spinLock

utils::SpinLock catapult::io::FileLock::m_spinLock
private

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