diff options
-rw-r--r-- | src/Control/Concurrent/Lifted/Instrument.hs | 20 |
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 @@ | |||
2 | module Control.Concurrent.Lifted.Instrument | 2 | module 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 | ||
11 | import qualified Control.Concurrent.Lifted as Raw | 12 | import qualified Control.Concurrent.Lifted as Raw |
12 | import Control.Concurrent.Lifted hiding (fork) | 13 | import Control.Concurrent.Lifted hiding (fork,forkOS) |
13 | import Control.Exception (fromException) | 14 | import Control.Exception (fromException) |
14 | import Control.Monad.Trans.Control | 15 | import Control.Monad.Trans.Control |
15 | import System.IO.Unsafe | 16 | import System.IO.Unsafe |
@@ -46,16 +47,25 @@ forkIO :: IO () -> IO ThreadId | |||
46 | forkIO = fork | 47 | forkIO = fork |
47 | {-# INLINE forkIO #-} | 48 | {-# INLINE forkIO #-} |
48 | 49 | ||
49 | fork :: (MonadBaseControl IO m, MonadIO m) => m () -> m ThreadId | 50 | forkOS :: MonadBaseControl IO m => m () -> m ThreadId |
50 | fork action = do | 51 | forkOS = instrumented Raw.forkOS |
51 | t <- Raw.fork $ do | 52 | {-# INLINE forkOS #-} |
53 | |||
54 | fork :: MonadBaseControl IO m => m () -> m ThreadId | ||
55 | fork = instrumented Raw.fork | ||
56 | {-# INLINE fork #-} | ||
57 | |||
58 | instrumented :: MonadBaseControl IO m => | ||
59 | (m () -> m ThreadId) -> m () -> m ThreadId | ||
60 | instrumented 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 | , " (" |