on master help sign in
Remove threadId from EventF
commit45e820430ecf5d9ccba82b83da727b6a48da9696 authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 8 Jun 2017, 00:53 (9 years ago) parente4bbcd6
3 files changed+7−20
src/Duct/AsyncT.hs+2−3 src/Duct/Event.hs+1−4 src/Duct/Threads.hs+4−13
src/Duct/AsyncT.hs+2−3
@@ -23,7 +23,7 @@ module Duct.AsyncT
2323where
2424
2525import Control.Applicative (Alternative (..))
26−import Control.Concurrent (ThreadId, myThreadId)
26+import Control.Concurrent (ThreadId)
2727import Control.Concurrent.STM (TChan, atomically, newTChan,
2828 readTChan)
2929import Control.Exception (SomeException, catch)
@@ -365,10 +365,9 @@ runTransient t = do
365365 zombieChan <- liftIO $ atomically newTChan
366366 pendingRef <- liftIO $ newIORef []
367367 credit <- liftIO $ newIORef maxBound
368− th <- liftIO $ myThreadId
369368
370369 r <- runStateT (runAsyncT t) $ initEventF
371− (empty :: AsyncT m a) th zombieChan pendingRef credit
370+ (empty :: AsyncT m a) zombieChan pendingRef credit
372371
373372 waitForChildren zombieChan pendingRef
374373 return r
src/Duct/Event.hs+1−4
@@ -40,7 +40,6 @@ data EventF = forall m a b. EventF
4040 -- ^ State data accessed with get or put operations
4141
4242 , mfSequence :: Int
43− , threadId :: ThreadId -- Do we need this?
4443
4544 , parent :: Maybe EventF -- We need the channel of the parent, but do we
4645 -- need the parent itself?
@@ -87,18 +86,16 @@ data EventF = forall m a b. EventF
8786
8887initEventF
8988 :: m a
90− -> ThreadId
9189 -> TChan ThreadId
9290 -> IORef [ThreadId]
9391 -> IORef Int
9492 -> EventF
95−initEventF x th zombieChan pending credit =
93+initEventF x zombieChan pending credit =
9694 EventF { event = mempty
9795 , xcomp = x
9896 , fcomp = []
9997 , mfData = mempty
10098 , mfSequence = 0
101− , threadId = th
10299 , parent = Nothing
103100 , zombieChannel = zombieChan
104101 , pendingThreads = pending
src/Duct/Threads.hs+4−13
@@ -119,10 +119,7 @@ forkFinally1 action and_then =
119119forkIt :: (MonadBaseControl IO m, MonadIO m) => EventF -> (EventF -> m t) -> m ()
120120forkIt current proc = do
121121 child <- newChildCont current
122− tid <- forkFinally1 (runInChild proc child)
123− $ \res -> do
124− thId <- myThreadId
125− beforeExit child{threadId = thId} res
122+ tid <- forkFinally1 (proc child) (beforeExit child)
126123 updatePendingThreads current tid
127124
128125 where
@@ -144,11 +141,6 @@ forkIt current proc = do
144141 , zombieChannel = chan
145142 }
146143
147− runInChild m child = do
148− th <- liftIO $ myThreadId
149− dbg $ "Forked: child " ++ show th
150− m child{threadId = th}
151−
152144 beforeExit cur res = do
153145 case res of
154146 Left _exc -> liftIO $ killChildren cur
@@ -161,7 +153,8 @@ forkIt current proc = do
161153 -- We are guaranteed to have a parent because we have been explicitly
162154 -- forked by some parent.
163155 let p = fromJust (parent cur)
164− liftIO $ atomically $ writeTChan (zombieChannel p) (threadId cur)
156+ tid <- myThreadId
157+ liftIO $ atomically $ writeTChan (zombieChannel p) tid
165158
166159forkMaybe :: (MonadBaseControl IO m, MonadIO m) => EventF -> (EventF -> m ()) -> m ()
167160forkMaybe current toRun = do
@@ -179,9 +172,7 @@ forkMaybe current toRun = do
179172 waitForOneChild (zombieChannel current)
180173 (pendingThreads current)
181174 forkMaybe current toRun
182− True -> do
183− dbg $ "Forking: parent " ++ show (threadId current)
184− forkIt current toRun
175+ True -> forkIt current toRun
185176
186177-- | 'StreamData' represents a task in a task stream being generated.
187178data StreamData a =