Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

  1. Outdated egg!
  2. dot-locking
    1. Introduction
    2. Usage
    3. Documentation
      1. obtain-dot-lock
      2. release-dot-lock
      3. break-dot-lock
      4. with-dot-lock*
    4. Author
    5. License
    6. Version History

dot-locking

Introduction

To bypass the restrictions of POSIX's file locks other advisory locking mechanisms, based only on standard file operations, where invented. One of them is the so-called dot-locking scheme where the lock of file-name is represented by the file file-name.lock. Care is taken that only one process may generate the lock for a given file.

Usage

(require-extension dot-locking)

Documentation

obtain-dot-lock

[procedure] (obtain-dot-lock file-name [interval retry-number stale-time])

Tries to obtain the lock for file-name. If the file is already locked, the thread sleeps for interval seconds (default is 1) before it retries. If the lock cannot be obtained after retry-number attempts, the procedure returns #f, otherwise #t. The default value of retry-number is #f which corresponds to an infinite number of retries.

If stale-time is non-#f, it specifies the minimum age a lock may have (in seconds) before it is considered stale. Obtain-dot-lock attempts to delete stale locks. If it was successful obtaining a lock after breaking it, obtain-dot-lock returns 'broken. If stale-time is #f, obtain-dot-lock never considers a lock stale. The default for stale-time is 300.

Note that it is possible that obtain-dot-lock breaks a lock but nevertheless fails to obtain it otherwise. If it is necessary to handle this case specially, use break-dot-lock directly (see below) rather than specifying a non-#f stale-time

release-dot-lock

[procedure] (release-dot-lock file-name)

Releases the lock for file-name. On success, release-dot-lock returns #t, otherwise #f. Note that this procedure can also be used to break the lock for file-name.

break-dot-lock

[procedure] (break-dot-lock file-name)

Breaks the lock for file-name if one exists. Note that breaking a lock does not imply a subsequent obtain-dot-lock will succeed, as another party may have acquired the lock between break-dot-lock and obtain-dot-lock.

with-dot-lock*

[syntax] (with-dot-lock file-name body ...)
[procedure] (with-dot-lock* file-name thunk)

The procedure with-dot-lock* obtains the requested lock, and then calls (thunk). When thunk returns, the lock is released. A non-local exit (e.g., throwing to a saved continuation or raising an exception) also causes the lock to be released.

After a normal return from thunk, its return values are returned by with-dot-lock*. The with-dot-lock special form is equivalent syntactic sugar.

Author

Olin Shivers

(ported to CHICKEN by felix winkelmann)

License

 Copyright (c) Olin Shivers
 All rights reserved.
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 3. The name of the authors may not be used to endorse or promote products
    derived from this software without specific prior written permission.
 THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 

Version History

0.2
some bugfixes (contributed by Claude Marinier)
0.1
initial release