summaryrefslogtreecommitdiff
path: root/lifted-concurrent
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-11-28 21:25:01 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-01 22:50:28 -0500
commit0e0e49d2381738501139d311b3147c6ae8179e11 (patch)
treec87408749d2fede5b2f31eeeaae31cf429a1c45b /lifted-concurrent
parent05f443e31b52de18e6e2dd3b7b7bd599f28e4a6f (diff)
This seems to be more stable.
Diffstat (limited to 'lifted-concurrent')
-rw-r--r--lifted-concurrent/src/Control/Concurrent/Lifted/Instrument.hs33
1 files changed, 21 insertions, 12 deletions
diff --git a/lifted-concurrent/src/Control/Concurrent/Lifted/Instrument.hs b/lifted-concurrent/src/Control/Concurrent/Lifted/Instrument.hs
index 070745b6..2c35419e 100644
--- a/lifted-concurrent/src/Control/Concurrent/Lifted/Instrument.hs
+++ b/lifted-concurrent/src/Control/Concurrent/Lifted/Instrument.hs
@@ -81,15 +81,22 @@ instrumented rawFork action = do
81 $ do catch action $ \e -> case fromException e of 81 $ do catch action $ \e -> case fromException e of
82 Just ThreadKilled -> return () 82 Just ThreadKilled -> return ()
83 Nothing -> liftBase $ do 83 Nothing -> liftBase $ do
84 g <- takeMVar globals 84 bracket (takeMVar globals)
85 let l = concat [ show e 85 (\g -> do
86 , " (" 86 let l = concat [ show e
87 , maybe "" lbl $ Map.lookup tid (threads g) 87 , " ("
88 , ")" 88 , maybe "" lbl $ Map.lookup tid (threads g)
89 ] 89 , ")"
90 reportException g l 90 ]
91 putMVar globals $! g { threads = Map.insert tid (PerThread l tm) $ threads g } 91 putMVar globals $! g { threads = Map.insert tid (PerThread l tm) $ threads g }
92 throwIO e 92 throwIO e)
93 (\g -> do
94 let l = concat [ show e
95 , " ("
96 , maybe "" lbl $ Map.lookup tid (threads g)
97 , ")"
98 ]
99 reportException g l)
93 -- Remove the thread only if it terminated normally or was killed. 100 -- Remove the thread only if it terminated normally or was killed.
94 modifyThreads $! Map.delete tid 101 modifyThreads $! Map.delete tid
95 return t 102 return t
@@ -106,8 +113,10 @@ threadsInformation = do
106 return $ Map.toList m 113 return $ Map.toList m
107 114
108 115
109modifyThreads :: MonadBase IO m => (Map.Map ThreadId PerThread -> Map.Map ThreadId PerThread) -> m () 116modifyThreads :: MonadBaseControl IO m =>
117 (Map.Map ThreadId PerThread -> Map.Map ThreadId PerThread) -> m ()
110modifyThreads f = do 118modifyThreads f = do
111 g <- takeMVar globals
112 let f' st = st { threads = f (threads st) } 119 let f' st = st { threads = f (threads st) }
113 putMVar globals $! f' g 120 bracket (takeMVar globals)
121 (\g -> putMVar globals $! f' g)
122 (\g -> return ())