The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PApp::Lock - manage locks using sql

SYNOPSIS

 use PApp::Lock;
 # not auto-imported into .papp-files

 locked {
    ... locked code section
 } "my_app_lock", 60, 60*10;

DESCRIPTION

This module manages locking (semaphores) using the papp state database (i.e. it works without filesystem and across hosts).

locked BLOCK name, [timeout, [holdtime]]

Execute the given BLOCK while holding the lock NAME. The lock will be given up as soon as the block is left. See the new method for the meaning of the arguments.

$lock = new PApp::Lock name, [timeout, [holdtime]]

Create a new lock object (but do not lock it) of name name. The name might be used case-sensitive or -insensitive, so always use the same spel[l]ing but don't expect that lock names are case-sensitive. timeout specifies the maximum time that the program waits until the lock becomes available (default: 5 minutes). holdtime specifies the maximum age the lock can have (default: 12 hours). A lock older than holdtime is broken.

$ok = $lock->lock([timeout])

Tries to aquire the lock until the timeout is reached. Returns true when the lock was aquired and false when the lock couldn't be aquired.

See new for the meaning of timeout.

$lock->breaktime

Returns the time when the lock can be broken (by another application). This can be called even when the process does not hold the lock. If the lock is not used it will return nothing.

SEE ALSO

PApp.

AUTHOR

 Marc Lehmann <schmorp@schmorp.de>
 http://home.schmorp.de/