make LockPool's LockHandle be able to support multiple different types of file locks

This commit is contained in:
Joey Hess 2015-11-12 16:28:11 -04:00
parent 710d1eeeac
commit e7552e4cee
Failed to extract signature
3 changed files with 37 additions and 21 deletions

View file

@ -24,7 +24,7 @@ import Utility.LockPool.STM (LockFile, LockMode(..))
lockShared :: LockFile -> IO (Maybe LockHandle)
lockShared file = tryMakeLockHandle
(P.tryTakeLock P.lockPool file LockShared)
(F.lockShared file)
(fmap mk <$> F.lockShared file)
{- Tries to take an exclusive lock on a file. Fails if another process has
- a shared or exclusive lock.
@ -35,9 +35,14 @@ lockShared file = tryMakeLockHandle
lockExclusive :: LockFile -> IO (Maybe LockHandle)
lockExclusive file = tryMakeLockHandle
(P.tryTakeLock P.lockPool file LockExclusive)
(F.lockExclusive file)
(fmap mk <$> F.lockExclusive file)
{- If the initial lock fails, this is a BUSY wait, and does not
- guarentee FIFO order of waiters. In other news, Windows is a POS. -}
waitToLock :: IO (Maybe lockhandle) -> IO lockhandle
waitToLock = F.waitToLock
mk :: F.LockHandle -> FileLockOps
mk h = FileLockOps
{ fDropLock = F.dropLock h
}