lukko-0.1.1.3: File locking
Safe HaskellTrustworthy
LanguageHaskell2010

Lukko

Description

Open Handle based locking

Synopsis

Documentation

fileLockingSupported :: Bool #

A constants specifying whether file locking is supported.

data FileLockingMethod #

Potentially availble lock methods.

Constructors

MethodOFD

open file descriptor locking

MethodFLock

BSD flock

MethodWindows

Windows locking

MethodNoOp

No-Op (throws FileLockingNotSupported)

Instances

Instances details
Bounded FileLockingMethod # 
Instance details

Defined in Lukko.Internal.Types

Enum FileLockingMethod # 
Instance details

Defined in Lukko.Internal.Types

Show FileLockingMethod # 
Instance details

Defined in Lukko.Internal.Types

Eq FileLockingMethod # 
Instance details

Defined in Lukko.Internal.Types

Ord FileLockingMethod # 
Instance details

Defined in Lukko.Internal.Types

fileLockingMethod :: FileLockingMethod #

A constant specifying this method

data LockMode #

Indicates a mode in which a file should be locked.

Constructors

SharedLock 
ExclusiveLock 

File descriptors

type FD = FD #

Opaque file descriptor

An int / CInt on unix systems, and HANDLE on windows.

fdOpen :: FilePath -> IO FD #

Open file to be used for locking.

fdClose :: FD -> IO () #

Close lock file.

fdLock :: FD -> LockMode -> IO () #

Like hLock, but work on "raw" file descriptor, as handled by fdOpen and fdClose.

fdTryLock :: FD -> LockMode -> IO Bool #

Non-blocking version of fdLock.

fdUnlock :: FD -> IO () #

Release a lock taken with fdLock or fdTryLock.

Handles

handleToFd :: Handle -> IO FD #

Convert GHC Handle to lukko FD.

hLock :: Handle -> LockMode -> IO () #

If a Handle references a file descriptor, attempt to lock contents of the underlying file in appropriate mode. If the file is already locked in incompatible mode, this function blocks until the lock is established. The lock is automatically released upon closing a Handle.

Things to be aware of:

1) This function may block inside a C call. If it does, in order to be able to interrupt it with asynchronous exceptions and/or for other threads to continue working, you MUST use threaded version of the runtime system.

2) The implementation uses LockFileEx on Windows, open file descriptor locks on Linux, and flock otherwise, hence all of their caveats also apply here.

3) On non-Windows plaftorms that don't support flock (e.g. Solaris) this function throws FileLockingNotImplemented. We deliberately choose to not provide fcntl based locking instead because of its broken semantics.

hTryLock :: Handle -> LockMode -> IO Bool #

Non-blocking version of hLock.

hUnlock :: Handle -> IO () #

Release a lock taken with hLock or hTryLock.