diff options
author | joe <joe@jerkface.net> | 2017-01-23 22:32:17 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-01-23 22:33:08 -0500 |
commit | 058ccb22f43e9053fa37ed719d31c72dd6dac27c (patch) | |
tree | f6faea43c0b4cc9428e0b8cb8d0b836a9ec13107 /src/Network/KRPC | |
parent | 6a2506745dd06ad0849a1b0d440ad9751a69cf81 (diff) |
Added thread-debug flag and "threads" command.
Diffstat (limited to 'src/Network/KRPC')
-rw-r--r-- | src/Network/KRPC/Manager.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Network/KRPC/Manager.hs b/src/Network/KRPC/Manager.hs index 4852eb38..22d111e2 100644 --- a/src/Network/KRPC/Manager.hs +++ b/src/Network/KRPC/Manager.hs | |||
@@ -7,6 +7,7 @@ | |||
7 | -- | 7 | -- |
8 | -- Normally, you don't need to import this module. | 8 | -- Normally, you don't need to import this module. |
9 | -- | 9 | -- |
10 | {-# LANGUAGE CPP #-} | ||
10 | {-# LANGUAGE OverloadedStrings #-} | 11 | {-# LANGUAGE OverloadedStrings #-} |
11 | {-# LANGUAGE FlexibleInstances #-} | 12 | {-# LANGUAGE FlexibleInstances #-} |
12 | {-# LANGUAGE FlexibleContexts #-} | 13 | {-# LANGUAGE FlexibleContexts #-} |
@@ -41,8 +42,12 @@ module Network.KRPC.Manager | |||
41 | ) where | 42 | ) where |
42 | 43 | ||
43 | import Control.Applicative | 44 | import Control.Applicative |
44 | import Control.Concurrent | 45 | #ifdef THREAD_DEBUG |
45 | import Control.Concurrent.Lifted (fork) | 46 | import Control.Concurrent.Lifted.Instrument |
47 | #else | ||
48 | import GHC.Conc (labelThread) | ||
49 | import Control.Concurrent.Lifted | ||
50 | #endif | ||
46 | import Control.Exception hiding (Handler) | 51 | import Control.Exception hiding (Handler) |
47 | import qualified Control.Exception.Lifted as E (Handler (..)) | 52 | import qualified Control.Exception.Lifted as E (Handler (..)) |
48 | import Control.Exception.Lifted as Lifted (catches, finally) | 53 | import Control.Exception.Lifted as Lifted (catches, finally) |
@@ -432,6 +437,7 @@ dispatchHandler q @ KQuery {..} addr = do | |||
432 | -- | 437 | -- |
433 | handleQuery :: MonadKRPC h m => BValue -> KQuery -> SockAddr -> m () | 438 | handleQuery :: MonadKRPC h m => BValue -> KQuery -> SockAddr -> m () |
434 | handleQuery raw q addr = void $ fork $ do | 439 | handleQuery raw q addr = void $ fork $ do |
440 | myThreadId >>= liftIO . flip labelThread "KRPC.handleQuery" | ||
435 | Manager {..} <- getManager | 441 | Manager {..} <- getManager |
436 | res <- dispatchHandler q addr | 442 | res <- dispatchHandler q addr |
437 | let resbe = either toBEncode toBEncode res | 443 | let resbe = either toBEncode toBEncode res |
@@ -481,6 +487,7 @@ listen :: MonadKRPC h m => m () | |||
481 | listen = do | 487 | listen = do |
482 | Manager {..} <- getManager | 488 | Manager {..} <- getManager |
483 | tid <- fork $ do | 489 | tid <- fork $ do |
490 | myThreadId >>= liftIO . flip labelThread "KRPC.listen" | ||
484 | listener `Lifted.finally` | 491 | listener `Lifted.finally` |
485 | liftIO (takeMVar listenerThread) | 492 | liftIO (takeMVar listenerThread) |
486 | liftIO $ putMVar listenerThread tid | 493 | liftIO $ putMVar listenerThread tid |