logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Paranoid::IO::Lockfile - Paranoid Lockfile support

Author

       Arthur Corliss (corliss@digitalmages.com)

Bugs And Limitations

Dependencies

       o   Fcntl

       o   Paranoid

       o   Paranoid::Debug

       o   Paranoid::IO

Description

       This module provides convenience functions for using a lockfile to coordinate multi-process activities.
       While basically just a thin wrapper for Paranoid::IO functions it removes the small tedium of having to
       perform the multiple opens required to ensure all processes are working off the same files while avoiding
       race conditions.

Import Lists

       This module exports the following symbols by default:

           plock pexclock pshlock punlock

       The following specialized import lists also exist:

           List        Members
           --------------------------------------------------------
           all         @defaults

Name

       Paranoid::IO::Lockfile - Paranoid Lockfile support

Subroutines/Methods

plock
         $rv = plock($filename);
         $rv = plock($filename, LOCK_EX);
         $rv = plock($filename, LOCK_EX, 0666);

       Creates or opens the requested file while applying the lock condition.  The lock type defaults to LOCK_EX
       if omitted, while the file permissions default to 0660.  As always, umask applies.

       There is one scenario in which one would want to use plock in lieu of pexclock, etc:  if you wish to
       perform non-blocking lock attempts.  All convenience functions are blocking.

   pexclock
         $rv = pexclock($filename);
         $rv = pexclock($filename, $mode);

       A wrapper for plock($filename,LOCK_EX).

   pshlock
         $rv = pshlock($filename);
         $rv = pshlock($filename, $mode);

       A wrapper for plock($filename,LOCK_SH).

   punlock
         $rv = punlock($filename);
         $rv = punlock($filename, $mode);

       A wrapper for plock($filename,LOCK_UN).  This does not close the open file handle to the lock file.  For
       that you need to call Paranoid::IO's pclose function.

Synopsis

         use Paranoid::IO::Lockfile;
         use Fcntl qw(:flock);  # only needed if you use plock in lieu
                                # of the other functions

         $rv = plock($lockfile);
         $rv = plock($lockfile, LOCK_SH | LOCK_NB);
         $rv = plock($lockfile, LOCK_SH | LOCK_NB, $mode);

         $rv = pexclock($lockfile);
         $rv = pshlock($lockfile);
         $rv = punlock($lockfile);

Version

       $Id: lib/Paranoid/IO/Lockfile.pm, 2.10 2022/03/08 00:01:04 acorliss Exp $

See Also