IPC::SRLock - Set/reset locking semantics to single thread processes
0.7.$Revision: 190 $
use IPC::SRLock; my $config = { tempdir => q(path_to_tmp_directory), type => q(fcntl) }; my $lock_obj = IPC::SRLock->new( $config ); $lock_obj->set( k => q(some_resource_identfier) ); # This critical region of code is guaranteed to be single threaded $lock_obj->reset( k => q(some_resource_identfier) );
Provides set/reset locking methods which will force a critical region of code to run single threaded
This class defines accessors and mutators for these attributes:
Turns on debug output. Defaults to 0
If set to a log object, it's debug method is called if debugging is turned on. Defaults to Class::Null
debug
Used as the lock file names. Defaults to ipc_srlock
How long to wait between polls of the lock table. Defaults to 0.5 seconds
Time in seconds to wait for a lock before giving up. If set to 0 waits forever. Defaults to 0
The process id doing the locking. Defaults to this processes id
Time in seconds before a lock is deemed to have expired. Defaults to 300
Determines which factory subclass is loaded. Defaults to fcntl
This constructor implements the singleton pattern, ensures that the factory subclass is loaded in initialises it
Expose the catch method in IPC::SRLock::ExceptionClass
catch
my $data = $lock_obj->get_table;
Returns a hash ref that contains the current lock table contents. The keys/values in the hash are suitable for passing to HTML::FormWidgets
my $array_ref = $lock_obj->list;
Returns an array of hash refs that represent the current lock table
$lock_obj->reset( k => q(some_resource_key) );
Resets the lock referenced by the k attribute.
$lock_obj->set( k => q(some_resource_key) );
Sets the specified lock. Attributes are:
Unique key to identify the lock. Mandatory no default
Explicitly set the process id associated with the lock. Defaults to the current process id
Set the time to live for this lock. Defaults to five minutes. Setting it to zero makes the lock last indefinitely
Expose the throw method in IPC::SRLock::ExceptionClass
throw
IPC::SRLock::ExceptionClass
Return the text of the the timeout message
my $args = $self->_arg_list( @rest );
Returns a hash ref containing the passed parameter list. Enables methods to be called with either a list or a hash ref as it's input parameters
$self->_ensure_class_loaded( $some_class );
Require the requested class, throw an error if it doesn't load
my $hash = __hash_merge( { key1 => val1 }, { key2 => val2 } );
Simplistic merging of two hashes
Called by the constructor. Optionally overridden in the factory subclass. This allows subclass specific initialisation
Should be overridden in the factory subclass
Setting debug to true will cause the set methods to log the lock record at the debug level
set
The sysv subclass will not work on MSWin32 and cygwin platforms
Testing of the memcached subclass is skipped on all platforms as it requires memcached to be listening on the localhost's default memcached port localhost:11211
memcached
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Peter Flanigan, <Support at RoxSoft.co.uk>
<Support at RoxSoft.co.uk>
Copyright (c) 2008-2012 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
To install IPC::SRLock, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IPC::SRLock
CPAN shell
perl -MCPAN -e shell install IPC::SRLock
For more information on module installation, please visit the detailed CPAN module installation guide.