Belle II Software  release-08-01-10
FileSystem::Lock Class Reference

Helper class for locking a file. More...

#include <FileSystem.h>

Public Member Functions

 Lock (const std::string &fileName, bool readonly=false)
 Construct a Lock object for the given file. More...
 
 ~Lock ()
 Destructor. More...
 
bool lock (int timeout=300, bool ignoreErrors=false)
 Try to lock the file. More...
 

Private Attributes

int m_file
 File descriptor of file to be locked.
 
bool m_readOnly
 if this is a read-only lock (multiple processes can hold one).
 

Detailed Description

Helper class for locking a file.

Definition at line 97 of file FileSystem.h.

Constructor & Destructor Documentation

◆ Lock()

Lock ( const std::string &  fileName,
bool  readonly = false 
)
explicit

Construct a Lock object for the given file.

Parameters
fileNameName of the file to be locked (if it does not exist, it will be created)
readonlycreate a read-only lock (multiple processes can hold one)

Definition at line 174 of file FileSystem.cc.

◆ ~Lock()

~Lock ( )

Destructor.

Releases the lock

Definition at line 181 of file FileSystem.cc.

Member Function Documentation

◆ lock()

bool lock ( int  timeout = 300,
bool  ignoreErrors = false 
)

Try to lock the file.

Note
Locks are not exclusive inside the same process, i.e. lock() will succeed even if a lock is already held by the current process.
Parameters
timeoutTime in seconds to wait for a lock (default is rather high to deal with slow FS at KEKCC)
ignoreErrorsif true just return if locking was unsuccessful but don't print an error
Returns
True if the lock could be obtained, false if file could not be opened or timeout is reached

Definition at line 186 of file FileSystem.cc.


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