diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2024-06-30 15:59:29 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2024-06-30 15:59:29 +0200 |
commit | e4ab9a3270e4c29a556cdcea315a9a01477ed866 (patch) | |
tree | 6b9d9fce6335ae68e4a6588f7b4136788063979a /src/Erebos/Storage.hs | |
parent | fb2f418a6b2b00f5b1f032547bb7e47749a23b80 (diff) |
Single INotify instance per Storage object
Diffstat (limited to 'src/Erebos/Storage.hs')
-rw-r--r-- | src/Erebos/Storage.hs | 22 |
1 files changed, 12 insertions, 10 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 |