-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Portable interface to file locking (flock / LockFileEx)
--   
--   This package provides an interface to Windows and Unix file locking
--   functionalities.
@package filelock
@version 0.1.0.1


-- | This module provides a portable interface to file locks as a mechanism
--   for inter-process synchronization.
--   
--   Each file lock is associated with a file. When taking a lock, the
--   assiciated file is created if it's not present, then the file is
--   locked in an OS-dependent way. While the lock is being held, no other
--   process or thread can take it, unless the specified
--   <a>SharedExclusive</a> values allow it.
--   
--   All locks held by a process are released when the process exits. They
--   can also be explicitly released using <a>unlockFile</a>.
--   
--   It is not recommended to open or otherwise use lock files for other
--   purposes, because it tends to expose differences between operating
--   systems. For example, on Windows <a>openFile</a> for a lock file will
--   fail when the lock is held, but on Unix it won't.
--   
--   Note on the implementation: currently the module uses flock(2) on
--   non-Windows platforms, and LockFileEx on Windows.
module System.FileLock

-- | A token that represents ownership of a lock.
data FileLock

-- | A type of lock to be taken.
data SharedExclusive

-- | Other process can hold a shared lock at the same time.
Shared :: SharedExclusive

-- | No other process can hold a lock, shared or exclusive.
Exclusive :: SharedExclusive

-- | Take a lock. This function blocks until the lock is available.
lockFile :: FilePath -> SharedExclusive -> IO FileLock

-- | Try to take a lock. This function does not block. If the lock is not
--   immediately available, it returns Nothing.
tryLockFile :: FilePath -> SharedExclusive -> IO (Maybe FileLock)

-- | Release the lock.
unlockFile :: FileLock -> IO ()

-- | Perform some action with a lock held.
withFileLock :: FilePath -> SharedExclusive -> (FileLock -> IO a) -> IO a
instance GHC.Classes.Eq System.FileLock.SharedExclusive
instance GHC.Show.Show System.FileLock.SharedExclusive
instance GHC.Classes.Eq System.FileLock.FileLock
