KaliVeda
Toolkit for HIC analysis
KVLockfile Class Reference

Detailed Description

Interface to (Linux) system lockfile command.

Created by KVClassFactory on Wed Feb 6 12:39:42 2008 Author: franklan

lockfile can be used to create one or more semaphore files, used to make sure that only one process can write to a given file at any one time.

If lockfile can't create all the specified files (in the specified order), because another process has already 'locked' the file, it waits sleeptime (defaults to 8) seconds and retries the last file that didn't succeed.

You can specify the number of retries to do until failure is returned. If the number of retries is -1 (default) lockfile will retry forever.

If the number of retries expires before all files have been created, lockfile returns failure and removes all the files it created up till that point.

If you specify a locktimeout then a lockfile will be removed by force after locktimeout seconds have passed since the lockfile was last modified/created (most likely by some other program that unexpectedly died a long time ago, and hence could not clean up any leftover lockfiles).

lockfile is clock skew immune. After a lockfile has been removed by force, a suspension of suspend seconds (defaults to 16) is taken into account, in order to prevent the inadvertent immediate removal of any newly created lockfile by another program (compare SUSPEND in procmail(1)).

To use a lockfile, create a KVLockfile object either using the constructor without arguments or by giving the name of the file to lock:

KVLockfile lox2("important.dat");
Interface to (Linux) system lockfile command.
Definition: KVLockfile.h:70

Then set the values you want for the number of retries, the sleeptime etc. Default values are as for Linux 'lockfile':

sleeptime = 8 sec.
retries = -1 (keep trying for ever)
suspend = 16 sec. (in case of timeout)

There is no timeout by default. If you want one, use SetTimeout() with timeout>0 seconds.

To lock the file:

lox.Lock("important.dat"); // filename not given to ctor
lox2.Lock(); // filename given to ctor
Bool_t Lock(const Char_t *filename="")
Definition: KVLockfile.cpp:165

To unlock the file:

lox.Release();
lox2.Release();
Bool_t Release()
Definition: KVLockfile.cpp:195

Note that Release() is called automatically in the destructor in case e.g. the KVLockfile goes out of scope.

Definition at line 70 of file KVLockfile.h.

#include <KVLockfile.h>

Public Member Functions

 KVLockfile (const Char_t *filename="")
 Default constructor. More...
 
virtual ~KVLockfile ()
 
Bool_t IsLocked () const
 
Bool_t Lock (const Char_t *filename="")
 
Bool_t Release ()
 
void SetRetries (int r)
 
void SetSleeptime (int s)
 
void SetSuspend (int s)
 
void SetTimeout (int t)
 

Constructor & Destructor Documentation

◆ KVLockfile()

KVLockfile::KVLockfile ( const Char_t filename = "")

Default constructor.

Definition at line 25 of file KVLockfile.cpp.

◆ ~KVLockfile()

KVLockfile::~KVLockfile ( )
virtual

Destructor If file is still locked, we call Release

Definition at line 39 of file KVLockfile.cpp.

Member Function Documentation

◆ IsLocked()

Bool_t KVLockfile::IsLocked ( ) const
inline

Definition at line 110 of file KVLockfile.h.

◆ Lock()

Bool_t KVLockfile::Lock ( const Char_t filename = "")

Definition at line 165 of file KVLockfile.cpp.

◆ Release()

Bool_t KVLockfile::Release ( )

Definition at line 195 of file KVLockfile.cpp.

◆ SetRetries()

void KVLockfile::SetRetries ( int  r)
inline

Definition at line 94 of file KVLockfile.h.

◆ SetSleeptime()

void KVLockfile::SetSleeptime ( int  s)
inline

Definition at line 90 of file KVLockfile.h.

◆ SetSuspend()

void KVLockfile::SetSuspend ( int  s)
inline

Definition at line 102 of file KVLockfile.h.

◆ SetTimeout()

void KVLockfile::SetTimeout ( int  t)
inline

Definition at line 98 of file KVLockfile.h.