NAME

cs::Lock - cross host NFS-safe locking


SYNOPSIS

use cs::Lock;


DESCRIPTION

This module obtains a lock on a resource via an agreed name and lock directory.

The current implementation uses directories for the lock objects. The Put method, if used, then makes files in these directories.


GENERAL FUNCTIONS

keypath(key)

Return the pathname of the lock object to be obtained from the key supplied.

check(key)

Check if the lock specified by key is taken.


OBJECT CREATION

new cs::Lock (key,maxtries,silent)

Obtain a lock on the resource specified by key. If maxtries is greater than zero, try to take the lock that many times before failure (returning undef). Successive attempts are separated by an increasing delay, up to a maximum. If maxtries equals zero, try forever. If maxtries is less than zero, return a lock object anyway (so that the current lock parameters may be queried). If not supplied, maxtries defaults to zero. If supplied and true, silent specifies that locks delayed for a noticable amount of time are not reported to STDERR.


OBJECT METHODS

Taken()

Return whether the lock was successfully obtained. This can only return false if the object was acquired with maxtries less than zero and the lock already taken by someone else.

Path()

Return the pathname of the lock object.

Put(info,base)

Write the text info to the record base in the lock object, followed by a newline. If not specified, base defaults to ``info''.

Get(base)

Retrieve the text stored in the record base in the lock object. If not specified, base defaults to ``info''.


FILES

The lock directory is chosen as follows: the directory named in the environment variable $LOCKDIR, or the subdirectory locks of the directory returned by cs::Misc::tmpDir(3) if it exists, or the directory $HOME/.locks.


ENVIRONMENT

LOCKDIR - the preferred directory for locks.


AUTHOR

Cameron Simpson <cs@zip.com.au>