lukko-0.1.1.2: File locking

Safe HaskellTrustworthy
LanguageHaskell2010

Lukko

Contents

Description

Open Handle based locking

Synopsis

Documentation

fileLockingSupported :: Bool Source #

A constants specifying whether file locking is supported.

data FileLockingMethod Source #

Potentially availble lock methods.

Constructors

MethodOFD

open file descriptor locking

MethodFLock

BSD flock

MethodWindows

Windows locking

MethodNoOp

No-Op (throws FileLockingNotSupported)

Instances
Bounded FileLockingMethod Source # 
Instance details

Defined in Lukko.Internal.Types

Enum FileLockingMethod Source # 
Instance details

Defined in Lukko.Internal.Types

Eq FileLockingMethod Source # 
Instance details

Defined in Lukko.Internal.Types

Ord FileLockingMethod Source # 
Instance details

Defined in Lukko.Internal.Types

Show FileLockingMethod Source # 
Instance details

Defined in Lukko.Internal.Types

fileLockingMethod :: FileLockingMethod Source #

A constant specifying this method

data LockMode Source #

Indicates a mode in which a file should be locked.

Constructors

SharedLock 
ExclusiveLock 

File descriptors

type FD = FD Source #

Opaque file descriptor

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

fdOpen :: FilePath -> IO FD Source #

Open file to be used for locking.

fdClose :: FD -> IO () Source #

Close lock file.

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

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

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

Non-blocking version of fdLock.

fdUnlock :: FD -> IO () Source #

Release a lock taken with fdLock or fdTryLock.

Handles

handleToFd :: Handle -> IO FD Source #

Convert GHC Handle to lukko FD.

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

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 Source #

Non-blocking version of hLock.

hUnlock :: Handle -> IO () Source #

Release a lock taken with hLock or hTryLock.