aboutsummaryrefslogtreecommitdiff
path: root/Annex/LockPool.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-07-10 00:32:23 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-07-10 00:32:23 -0400
commitc42733876bcb72d1b4c85de6bac73f1c73b216ad (patch)
treec3edc52aa7b5b90594def0cd9eb7d4d1b8fc12d2 /Annex/LockPool.hs
parent200b8d462e46db7b6bb87ab832529199fff58247 (diff)
refactor locking
Diffstat (limited to 'Annex/LockPool.hs')
-rw-r--r--Annex/LockPool.hs60
1 files changed, 0 insertions, 60 deletions
diff --git a/Annex/LockPool.hs b/Annex/LockPool.hs
deleted file mode 100644
index 5fc167d28..000000000
--- a/Annex/LockPool.hs
+++ /dev/null
@@ -1,60 +0,0 @@
-{- git-annex lock pool
- -
- - Copyright 2012, 2014 Joey Hess <joey@kitenet.net>
- -
- - Licensed under the GNU GPL version 3 or higher.
- -}
-
-{-# LANGUAGE CPP #-}
-
-module Annex.LockPool where
-
-import Common.Annex
-import Annex
-import Types.LockPool
-
-import qualified Data.Map as M
-
-#ifndef mingw32_HOST_OS
-import Annex.Perms
-#else
-import Utility.WinLock
-#endif
-
-{- Create a specified lock file, and takes a shared lock. -}
-lockFile :: FilePath -> Annex ()
-lockFile file = go =<< fromPool file
- where
- go (Just _) = noop -- already locked
- go Nothing = do
-#ifndef mingw32_HOST_OS
- mode <- annexFileMode
- lockhandle <- liftIO $ noUmask mode $
- openFd file ReadOnly (Just mode) defaultFileFlags
- liftIO $ waitToSetLock lockhandle (ReadLock, AbsoluteSeek, 0, 0)
-#else
- lockhandle <- liftIO $ waitToLock $ lockShared file
-#endif
- changePool $ M.insert file lockhandle
-
-unlockFile :: FilePath -> Annex ()
-unlockFile file = maybe noop go =<< fromPool file
- where
- go lockhandle = do
-#ifndef mingw32_HOST_OS
- liftIO $ closeFd lockhandle
-#else
- liftIO $ dropLock lockhandle
-#endif
- changePool $ M.delete file
-
-getPool :: Annex LockPool
-getPool = getState lockpool
-
-fromPool :: FilePath -> Annex (Maybe LockHandle)
-fromPool file = M.lookup file <$> getPool
-
-changePool :: (LockPool -> LockPool) -> Annex ()
-changePool a = do
- m <- getPool
- changeState $ \s -> s { lockpool = a m }