IPC-Locker
view release on metacpan or search on metacpan
lib/IPC/Locker.pm view on Meta::CPAN
only argument is self. Defaults to print a message if verbose is set.
=item print_retry
A function to print a message when the lock server is unavailable, and is
about to be retried. The first argument is self. Defaults to a print
message.
=item print_waiting
A function to print a message when the lock is busy and needs to be waited
for. The first argument is self, second the name of the lock. Defaults to
print a message if verbose is set.
=item timeout
The maximum time in seconds that the lock may be held before being forced
open, passed to the server when the lock is created. Thus if the requester
dies, the lock will be released after that amount of time. Zero disables
the timeout. Defaults to 30 minutes.
lib/IPC/Locker/Server.pm view on Meta::CPAN
foreach my $lockname (@{$clientvar->{locks}}) {
_timelog("c$clientvar->{client_num}: new $lockname\n") if $Debug;
# Create new request. If it can be serviced, this will
# establish the lock and send status back.
my $locki = locki_new_request($lockname, $clientvar);
$first_locki ||= $locki;
# Done if found free lock
last if $clientvar->{locked};
}
# All locks busy?
if ($clientvar->{locked}) {
# Done, and we already sent client_status when the lock was made
return 0;
} elsif (!$clientvar->{block}) {
# All busy, and user wants non-blocking, just send status
client_status($clientvar);
return 0;
} else {
# All busy, we need to block the user's request and tell the user
if (!$clientvar->{told_locked} && $first_locki) {
$clientvar->{told_locked} = 1;
client_send ($clientvar, "print_waiting $first_locki->{owner}\n");
}
# Either need to wait for timeout, or someone else to return key
return 1; # Exit loop and check if can lock later
}
}
sub client_break {
( run in 0.438 second using v1.01-cache-2.11-cpan-87723dcf8b7 )