KaliVeda
1.13/01
Heavy-Ion Analysis Toolkit
|
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:
Then set the values you want for the number of retries, the sleeptime etc. Default values are as for Linux 'lockfile':
There is no timeout by default. If you want one, use SetTimeout() with timeout>0 seconds.
To lock the file:
To unlock the file:
Note that Release() is called automatically in the destructor in case e.g. the KVLockfile goes out of scope.
Definition at line 69 of file 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) |
Private Member Functions | |
Bool_t | FindExecutable (TString &exec, const Char_t *path="$(PATH)") |
copied from KVBase to avoid circular dependency More... | |
void | init () |
int | testlock () |
void | writecmd () |
Writes lockfile command with current values of parameters. More... | |
Private Attributes | |
KVString | cmd |
command to execute More... | |
KVString | fFile |
name of file More... | |
KVString | fLockfile |
full path to lockfile executable (if defined) More... | |
bool | have_exec |
kTRUE if lockfile found on system More... | |
bool | locked |
kTRUE when Lock() has been called successfully More... | |
int | locktimeout |
time after which lock automatically opens More... | |
int | retries |
number of times to retry More... | |
int | sleeptime |
time to wait before retrying lock More... | |
int | suspend |
suspend time after timeout More... | |
#include <KVLockfile.h>
KVLockfile::KVLockfile | ( | const Char_t * | filename = "" | ) |
Default constructor.
Definition at line 25 of file KVLockfile.cpp.
|
virtual |
Destructor If file is still locked, we call Release
Definition at line 39 of file KVLockfile.cpp.
copied from KVBase to avoid circular dependency
Definition at line 75 of file KVLockfile.cpp.
Initialisation Look for 'lockfile' executable and store path if found Set value of have_exec accordingly
Definition at line 55 of file KVLockfile.cpp.
|
inline |
Definition at line 109 of file KVLockfile.h.
Definition at line 165 of file KVLockfile.cpp.
Bool_t KVLockfile::Release | ( | ) |
Definition at line 195 of file KVLockfile.cpp.
|
inline |
Definition at line 93 of file KVLockfile.h.
|
inline |
Definition at line 89 of file KVLockfile.h.
|
inline |
Definition at line 101 of file KVLockfile.h.
|
inline |
Definition at line 97 of file KVLockfile.h.
|
private |
Executes lockfile command with current values of parameters (call KVLockfile::writecmd() before)
Definition at line 152 of file KVLockfile.cpp.
|
private |
Writes lockfile command with current values of parameters.
Definition at line 122 of file KVLockfile.cpp.
|
private |
command to execute
Definition at line 77 of file KVLockfile.h.
|
private |
name of file
Definition at line 70 of file KVLockfile.h.
|
private |
full path to lockfile executable (if defined)
Definition at line 71 of file KVLockfile.h.
|
private |
kTRUE if lockfile found on system
Definition at line 72 of file KVLockfile.h.
|
private |
kTRUE when Lock() has been called successfully
Definition at line 78 of file KVLockfile.h.
|
private |
time after which lock automatically opens
Definition at line 75 of file KVLockfile.h.
|
private |
number of times to retry
Definition at line 74 of file KVLockfile.h.
|
private |
time to wait before retrying lock
Definition at line 73 of file KVLockfile.h.
|
private |
suspend time after timeout
Definition at line 76 of file KVLockfile.h.