From c42733876bcb72d1b4c85de6bac73f1c73b216ad Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 10 Jul 2014 00:32:23 -0400 Subject: refactor locking --- Annex/LockPool.hs | 60 ------------------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 Annex/LockPool.hs (limited to 'Annex/LockPool.hs') 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 - - - - 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 } -- cgit v1.2.3