@@ -38,6 +38,7 @@ data Status = Active | Inactive
39newtype MutableStatus = MutableStatus (IORef Status)
39newtype MutableStatus = MutableStatus (IORef Status)
41+-- | An action to activate a Fd cache entry.
41type Refresh = IO ()
42type Refresh = IO ()
43status :: MutableStatus -> IO Status
44status :: MutableStatus -> IO Status
@@ -65,6 +66,8 @@ newFdEntry path = FdEntry path
66type Hash = Int
67type Hash = Int
67type FdCache = MMap Hash FdEntry
68type FdCache = MMap Hash FdEntry
70+-- | Mutable Fd cacher.
68newtype MutableFdCache = MutableFdCache (IORef FdCache)
71newtype MutableFdCache = MutableFdCache (IORef FdCache)
70fdCache :: MutableFdCache -> IO FdCache
73fdCache :: MutableFdCache -> IO FdCache
@@ -93,6 +96,8 @@ look mfc path key = searchWith key check <$> fdCache mfc
94----------------------------------------------------------------
97----------------------------------------------------------------
99+-- | Creating 'MutableFdCache' and executing the action in the second
100+-- argument. The first argument is a cache duration in second.
96withFdCache :: Int -> (Maybe MutableFdCache -> IO a) -> IO a
101withFdCache :: Int -> (Maybe MutableFdCache -> IO a) -> IO a
97withFdCache duration action = bracket (initialize duration)
102withFdCache duration action = bracket (initialize duration)
98 terminate
103 terminate
@@ -100,6 +105,7 @@ withFdCache duration action = bracket (initialize duration)
101----------------------------------------------------------------
106----------------------------------------------------------------
108+-- The first argument is a cache duration in second.
103initialize :: Int -> IO (Maybe MutableFdCache)
109initialize :: Int -> IO (Maybe MutableFdCache)
104initialize 0 = return Nothing
110initialize 0 = return Nothing
105initialize duration = do
111initialize duration = do
@@ -142,6 +148,7 @@ terminate (Just (MutableFdCache ref)) = mask_ $ do
143----------------------------------------------------------------
149----------------------------------------------------------------
151+-- | Getting 'Fd' and 'Refresh' from the mutable Fd cacher.
145getFd :: MutableFdCache -> FilePath -> IO (Fd, Refresh)
152getFd :: MutableFdCache -> FilePath -> IO (Fd, Refresh)
146getFd mfc path = look mfc path key >>= getFd'
153getFd mfc path = look mfc path key >>= getFd'