summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-06-30 15:59:29 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-06-30 15:59:29 +0200
commite4ab9a3270e4c29a556cdcea315a9a01477ed866 (patch)
tree6b9d9fce6335ae68e4a6588f7b4136788063979a /src
parentfb2f418a6b2b00f5b1f032547bb7e47749a23b80 (diff)
Single INotify instance per Storage object
Diffstat (limited to 'src')
-rw-r--r--src/Erebos/Storage.hs22
-rw-r--r--src/Erebos/Storage/Internal.hs2
2 files changed, 13 insertions, 11 deletions
diff --git a/src/Erebos/Storage.hs b/src/Erebos/Storage.hs
index 6526f40..5730b4c 100644
--- a/src/Erebos/Storage.hs
+++ b/src/Erebos/Storage.hs
@@ -142,7 +142,7 @@ openStorage path = modifyIOError annotate $ do
createDirectoryIfMissing True $ path </> "objects"
createDirectoryIfMissing True $ path </> "heads"
- watchers <- newMVar ([], WatchList 1 [])
+ watchers <- newMVar (Nothing, [], WatchList 1 [])
refgen <- newMVar =<< HT.new
refroots <- newMVar =<< HT.new
return $ Storage
@@ -542,19 +542,21 @@ watchHeadRaw st tid hid sel cb = do
}
watched <- case stBacking st of
- StorageDir { dirPath = spath, dirWatchers = mvar } -> modifyMVar mvar $ \(ilist, wl) -> do
- ilist' <- case lookup tid ilist of
- Just _ -> return ilist
- Nothing -> do
- inotify <- initINotify
- void $ addWatch inotify [Move] (BC.pack $ headTypePath spath tid) $ \case
+ StorageDir { dirPath = spath, dirWatchers = mvar } -> modifyMVar mvar $ \(mbmanager, ilist, wl) -> do
+ manager <- maybe initINotify return mbmanager
+ ilist' <- case tid `elem` ilist of
+ True -> return ilist
+ False -> do
+ void $ addWatch manager [ Move ] (BC.pack $ headTypePath spath tid) $ \case
MovedIn { filePath = fpath } | Just ihid <- HeadID <$> U.fromASCIIBytes fpath -> do
loadHeadRaw st tid ihid >>= \case
- Just ref -> mapM_ ($ ref) . map wlFun . filter ((== (tid, ihid)) . wlHead) . wlList . snd =<< readMVar mvar
+ Just ref -> do
+ (_, _, iwl) <- readMVar mvar
+ mapM_ ($ ref) . map wlFun . filter ((== (tid, ihid)) . wlHead) . wlList $ iwl
Nothing -> return ()
_ -> return ()
- return $ (tid, inotify) : ilist
- return $ first (ilist',) $ addWatcher wl
+ return $ tid : ilist
+ return $ first ( Just manager, ilist', ) $ addWatcher wl
StorageMemory { memWatchers = mvar } -> modifyMVar mvar $ return . addWatcher
diff --git a/src/Erebos/Storage/Internal.hs b/src/Erebos/Storage/Internal.hs
index 116d7fa..b9cf6dd 100644
--- a/src/Erebos/Storage/Internal.hs
+++ b/src/Erebos/Storage/Internal.hs
@@ -60,7 +60,7 @@ showParentStorage Storage { stParent = Just st } = "@" ++ show st
data StorageBacking c
= StorageDir { dirPath :: FilePath
- , dirWatchers :: MVar ([(HeadTypeID, INotify)], WatchList c)
+ , dirWatchers :: MVar ( Maybe INotify, [ HeadTypeID ], WatchList c )
}
| StorageMemory { memHeads :: MVar [((HeadTypeID, HeadID), Ref' c)]
, memObjs :: MVar (Map RefDigest BL.ByteString)