summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Control/Concurrent/Lifted/Instrument.hs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/Control/Concurrent/Lifted/Instrument.hs b/src/Control/Concurrent/Lifted/Instrument.hs
index 7e4a7356..5b3237cc 100644
--- a/src/Control/Concurrent/Lifted/Instrument.hs
+++ b/src/Control/Concurrent/Lifted/Instrument.hs
@@ -2,6 +2,7 @@
2module Control.Concurrent.Lifted.Instrument 2module Control.Concurrent.Lifted.Instrument
3 ( module Control.Concurrent.Lifted 3 ( module Control.Concurrent.Lifted
4 , forkIO 4 , forkIO
5 , forkOS
5 , fork 6 , fork
6 , labelThread 7 , labelThread
7 , threadsInformation 8 , threadsInformation
@@ -9,7 +10,7 @@ module Control.Concurrent.Lifted.Instrument
9 ) where 10 ) where
10 11
11import qualified Control.Concurrent.Lifted as Raw 12import qualified Control.Concurrent.Lifted as Raw
12import Control.Concurrent.Lifted hiding (fork) 13import Control.Concurrent.Lifted hiding (fork,forkOS)
13import Control.Exception (fromException) 14import Control.Exception (fromException)
14import Control.Monad.Trans.Control 15import Control.Monad.Trans.Control
15import System.IO.Unsafe 16import System.IO.Unsafe
@@ -46,16 +47,25 @@ forkIO :: IO () -> IO ThreadId
46forkIO = fork 47forkIO = fork
47{-# INLINE forkIO #-} 48{-# INLINE forkIO #-}
48 49
49fork :: (MonadBaseControl IO m, MonadIO m) => m () -> m ThreadId 50forkOS :: MonadBaseControl IO m => m () -> m ThreadId
50fork action = do 51forkOS = instrumented Raw.forkOS
51 t <- Raw.fork $ do 52{-# INLINE forkOS #-}
53
54fork :: MonadBaseControl IO m => m () -> m ThreadId
55fork = instrumented Raw.fork
56{-# INLINE fork #-}
57
58instrumented :: MonadBaseControl IO m =>
59 (m () -> m ThreadId) -> m () -> m ThreadId
60instrumented rawFork action = do
61 t <- rawFork $ do
52 tid <- myThreadId 62 tid <- myThreadId
53 tm <- liftBase getCurrentTime 63 tm <- liftBase getCurrentTime
54 bracket_ (modifyThreads $! Map.insert tid (PerThread "" tm)) 64 bracket_ (modifyThreads $! Map.insert tid (PerThread "" tm))
55 (return ()) 65 (return ())
56 $ do catch action $ \e -> case fromException e of 66 $ do catch action $ \e -> case fromException e of
57 Just ThreadKilled -> return () 67 Just ThreadKilled -> return ()
58 Nothing -> liftIO $ do 68 Nothing -> liftBase $ do
59 g <- takeMVar globals 69 g <- takeMVar globals
60 let l = concat [ show e 70 let l = concat [ show e
61 , " (" 71 , " ("