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

Copyright(c) 2013-2016 2018 Peter Trško
LicenseBSD3
Maintainerpeter.trsko@gmail.com
Stabilityexperimental
PortabilityGHC specific language extensions; POSIX.
Safe HaskellSafe
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 -> 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 -> 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
    -> m a
lockedDo = withLockFile lockParams lockFile
  where
    lockParams = def
        { retryToAcquireLock = NumberOfTimes 3
        }

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

Constructors

LockingParameters 

Fields

Instances

Eq LockingParameters Source # 
Data LockingParameters Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LockingParameters -> c LockingParameters #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LockingParameters #

toConstr :: LockingParameters -> Constr #

dataTypeOf :: LockingParameters -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c LockingParameters) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LockingParameters) #

gmapT :: (forall b. Data b => b -> b) -> LockingParameters -> LockingParameters #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LockingParameters -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LockingParameters -> r #

gmapQ :: (forall d. Data d => d -> u) -> LockingParameters -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> LockingParameters -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> LockingParameters -> m LockingParameters #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LockingParameters -> m LockingParameters #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LockingParameters -> m LockingParameters #

Read LockingParameters Source # 
Show LockingParameters Source # 
Generic LockingParameters Source # 
Default LockingParameters Source #

Defined as:

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

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

type Rep LockingParameters Source # 
type Rep LockingParameters = D1 * (MetaData "LockingParameters" "System.IO.LockFile.Internal" "lock-file-0.7.0.0-HyF0nY0IvY2Cpy0LnOwds2" False) (C1 * (MetaCons "LockingParameters" PrefixI True) ((:*:) * (S1 * (MetaSel (Just Symbol "retryToAcquireLock") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 * RetryStrategy)) (S1 * (MetaSel (Just Symbol "sleepBetweenRetries") SourceUnpack SourceStrict DecidedStrict) (Rec0 * Word64))))

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.

Instances

Eq RetryStrategy Source # 
Data RetryStrategy Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> RetryStrategy -> c RetryStrategy #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c RetryStrategy #

toConstr :: RetryStrategy -> Constr #

dataTypeOf :: RetryStrategy -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c RetryStrategy) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c RetryStrategy) #

gmapT :: (forall b. Data b => b -> b) -> RetryStrategy -> RetryStrategy #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> RetryStrategy -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> RetryStrategy -> r #

gmapQ :: (forall d. Data d => d -> u) -> RetryStrategy -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> RetryStrategy -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> RetryStrategy -> m RetryStrategy #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> RetryStrategy -> m RetryStrategy #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> RetryStrategy -> m RetryStrategy #

Read RetryStrategy Source # 
Show RetryStrategy Source # 
Generic RetryStrategy Source # 

Associated Types

type Rep RetryStrategy :: * -> * #

Default RetryStrategy Source #

Defined as: def = Indefinitely

Methods

def :: RetryStrategy #

type Rep RetryStrategy Source # 
type Rep RetryStrategy = D1 * (MetaData "RetryStrategy" "System.IO.LockFile.Internal" "lock-file-0.7.0.0-HyF0nY0IvY2Cpy0LnOwds2" False) ((:+:) * (C1 * (MetaCons "No" PrefixI False) (U1 *)) ((:+:) * (C1 * (MetaCons "Indefinitely" PrefixI False) (U1 *)) (C1 * (MetaCons "NumberOfTimes" PrefixI False) (S1 * (MetaSel (Nothing Symbol) SourceUnpack SourceStrict DecidedStrict) (Rec0 * Word8)))))

Exceptions