27 Oct 2007 19:46:10 UTC
- Development release
- Distribution: KinoSearch
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (5)
- Testers (21 / 5 / 2)
- KwaliteeBus factor: 0
- License: perl_5
- Activity24 month
- Download (460.82KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionCREAMYG Marvin Humphreyand 1 contributors
- Marvin Humphrey <marvin at rectangular dot com>
- LICENSE, DISCLAIMER, BUGS, etc.
KinoSearch::Store::Lock - Interprocess mutex lock.
my $lock = $lock_factory->make_lock( lock_name => 'commit', timeout => 5000, ); $lock->obtain or die "can't get lock on " . $lock->get_filename; do_stuff(); $lock->release;
The Lock class produces an interprocess mutex lock, using a lock "file". What exactly constitutes that "file" depends on the Folder implementation.
Each lock must have a name which is unique per resource to be locked. The filename for the lockfile will be derived from it, e.g. "write" will generate the file "write.lock".
Each lock also has an "agent id", a string which should be unique per-host; it is used to help clear away stale lockfiles.
my $lock = KinoSearch::Store::Lock->new( lock_name => 'commit', # required timeout => 5000, # default: 0 folder => $folder, # required agent_id => $hostname, # required );
Create a Lock. Takes named parameters.
lock_name - String identifying the resource to be locked.
timeout - Time in milliseconds to keep retrying before abandoning the attempt to obtain() a lock.
folder - An object which isa KinoSearch::Store::Folder.
agent_id - An identifying string, usually the host name.
$lock->obtain or die "Couldn't get lock";
Attempt to aquire lock once per second until the timeout has been reached. Returns true upon success, false otherwise.
Release the lock.
do_stuff() if $lock->is_locked;
Returns a boolean indicating whether the resource identified by this lock's lock_name string is currently locked.
$lock->clear_stale; $lock->obtain or die "Can't get lock";
Release all locks that meet the following criteria:
The process id that the lock was created under no longer identifies an active process.
Copyright 2005-2007 Marvin Humphrey
See KinoSearch version 0.20.