lock-file-0.5.0.2: Provide exclusive access to a resource using lock file.

Copyright(c) 2013-2015, Peter Trško
LicenseBSD3
Maintainerpeter.trsko@gmail.com
Stabilityexperimental
PortabilityCPP, DeriveDataTypeable, DeriveGeneric, NoImplicitPrelude
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.IO.LockFile.Internal

Contents

Description

Low-level API for providing exclusive access to a resource using lock file.

Synopsis

Locking primitives

lock :: (MonadMask m, MonadIO m) => LockingParameters -> FilePath -> Throws LockingException m Handle Source

Open lock file write PID of a current process in to it and return its handle.

If operation doesn't succeed, then LockingException is raised. See also LockingParameters and RetryStrategy for details.

unlock :: (MonadMask m, MonadIO m) => FilePath -> Handle -> Throws LockingException m () Source

Close lock file handle and then delete it.

Configuration

data LockingParameters Source

Locking algorithm parameters. When in doubt, use def, otherwise start with it. Example:

lockedDo
    :: (MonadMask m, MonadIO m)
    => FilePath
    -> m a
    -> Throws LockingException m a
lockedDo = withLockFile lockParams lockFile
  where
    lockParams = def
        { retryToAcquireLock = NumberOfTimes 3
        }

    lockFile = withLockExt "/var/lock/my-app"

Constructors

LockingParameters 

Fields

retryToAcquireLock :: !RetryStrategy

Strategy for handling situations when lock-file is already acquired.

sleepBetweenRetires :: !Word64

Sleep interval in microseconds.

Instances

Eq LockingParameters 
Data LockingParameters 
Read LockingParameters 
Show LockingParameters 
Generic LockingParameters 
Default LockingParameters

Defined as:

def = LockingParameters
    { retryToAcquireLock  = def
    , sleepBetweenRetires = 8000000  -- 8 seconds
    }

Sleep interval is inspired by lockfile command line utility that is part of Procmail.

Typeable * LockingParameters 
type Rep LockingParameters 

data RetryStrategy Source

Defines strategy for handling situations when lock-file is already acquired.

Constructors

No

Don't retry at all.

Indefinitely

Retry indefinitely.

NumberOfTimes !Word8

Retry only specified number of times. If equal to zero then it is interpreted same way as No.

Exceptions

data LockingException Source

Constructors

UnableToAcquireLockFile FilePath

Wasn't able to aquire lock file specified as an argument.

CaughtIOException IOException

IOException occurred while creating or removing lock file.