summaryrefslogtreecommitdiff
path: root/Utility/LockPool
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-05-18 16:23:07 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-05-19 14:09:52 -0400
commitae5433c4caf0ee57e3338df6dcd625f20ece7101 (patch)
tree5bdab44419df36e7e5aab2e36cd6b221654de04e /Utility/LockPool
parent94a3e606fb31150c969d63790ec1ef870f413cc1 (diff)
use lock pools throughout git-annex
The one exception is in Utility.Daemon. As long as a process only daemonizes once, which seems reasonable, and as long as it avoids calling checkDaemon once it's already running as a daemon, the fcntl locking gotchas won't be a problem there. Annex.LockFile has it's own separate lock pool layer, which has been renamed to LockCache. This is a persistent cache of locks that persist until closed. This is not quite done; lockContent stil needs to be converted.
Diffstat (limited to 'Utility/LockPool')
-rw-r--r--Utility/LockPool/Posix.hs4
-rw-r--r--Utility/LockPool/STM.hs9
2 files changed, 5 insertions, 8 deletions
diff --git a/Utility/LockPool/Posix.hs b/Utility/LockPool/Posix.hs
index e460272f2..e05ab9754 100644
--- a/Utility/LockPool/Posix.hs
+++ b/Utility/LockPool/Posix.hs
@@ -18,11 +18,9 @@ module Utility.LockPool.Posix (
import qualified Utility.LockFile.Posix as F
import qualified Utility.LockPool.STM as P
-import Utility.LockPool.STM (LockPool, LockFile, LockMode(..))
+import Utility.LockPool.STM (LockFile, LockMode(..))
import Utility.LockPool.LockHandle
-import Utility.Monad
-import Control.Concurrent.STM
import System.IO
import System.Posix
import Data.Maybe
diff --git a/Utility/LockPool/STM.hs b/Utility/LockPool/STM.hs
index a60bbc7bf..f422c8a73 100644
--- a/Utility/LockPool/STM.hs
+++ b/Utility/LockPool/STM.hs
@@ -80,16 +80,15 @@ tryTakeLock pool file mode =
--
-- Note that the lock pool is left empty while the checker action is run.
-- This allows checker actions that open/close files, and so would be in
--- danger of conflicting with existing locks. Since the lock pool is
--- kept empty, anything that attempts to take a lock will block,
--- avoiding that race.
+-- danger of conflicting with locks created at the same time this is
+-- running. With the lock pool empty, anything that attempts
+-- to take a lock will block, avoiding that race.
getLockStatus :: LockPool -> LockFile -> IO v -> IO (Maybe v) -> IO (Maybe v)
getLockStatus pool file getdefault checker = do
v <- atomically $ do
m <- takeTMVar pool
let threadlocked = case M.lookup file m of
- Just (LockStatus _ n)
- | n > 0 -> True
+ Just (LockStatus _ n) | n > 0 -> True
_ -> False
if threadlocked
then do