Copyright | (c) 2013, 2014 Peter Trsko |
---|---|
License | BSD3 |
Maintainer | peter.trsko@gmail.com |
Stability | experimental |
Portability | CPP, DeriveDataTypeable, DeriveGeneric, NoImplicitPrelude |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Low-level API for providing exclusive access to a resource using lock file.
- lock :: (MonadMask m, MonadIO m) => LockingParameters -> FilePath -> Throws LockingException m Handle
- unlock :: (MonadMask m, MonadIO m) => FilePath -> Handle -> Throws LockingException m ()
- data LockingParameters = LockingParameters {}
- data RetryStrategy
- = No
- | Indefinitely
- | NumberOfTimes !Word8
- data LockingException
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"
LockingParameters | |
|
Eq LockingParameters | |
Data LockingParameters | |
Read LockingParameters | |
Show LockingParameters | |
Generic LockingParameters | |
Default LockingParameters | Defined as:
Sleep interval is inspired by |
Typeable * LockingParameters | |
type Rep LockingParameters |
data RetryStrategy Source
Defines strategy for handling situations when lock-file is already acquired.
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 |
Exceptions
data LockingException Source
UnableToAcquireLockFile FilePath | Wasn't able to aquire lock file specified as an argument. |
CaughtIOException IOException |
|