From e4ab9a3270e4c29a556cdcea315a9a01477ed866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 30 Jun 2024 15:59:29 +0200 Subject: Single INotify instance per Storage object --- src/Erebos/Storage.hs | 22 ++++++++++++---------- src/Erebos/Storage/Internal.hs | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/Erebos') 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) -- cgit v1.2.3