summaryrefslogtreecommitdiff
path: root/src/Network/KRPC
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-01-23 22:32:17 -0500
committerjoe <joe@jerkface.net>2017-01-23 22:33:08 -0500
commit058ccb22f43e9053fa37ed719d31c72dd6dac27c (patch)
treef6faea43c0b4cc9428e0b8cb8d0b836a9ec13107 /src/Network/KRPC
parent6a2506745dd06ad0849a1b0d440ad9751a69cf81 (diff)
Added thread-debug flag and "threads" command.
Diffstat (limited to 'src/Network/KRPC')
-rw-r--r--src/Network/KRPC/Manager.hs11
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
43import Control.Applicative 44import Control.Applicative
44import Control.Concurrent 45#ifdef THREAD_DEBUG
45import Control.Concurrent.Lifted (fork) 46import Control.Concurrent.Lifted.Instrument
47#else
48import GHC.Conc (labelThread)
49import Control.Concurrent.Lifted
50#endif
46import Control.Exception hiding (Handler) 51import Control.Exception hiding (Handler)
47import qualified Control.Exception.Lifted as E (Handler (..)) 52import qualified Control.Exception.Lifted as E (Handler (..))
48import Control.Exception.Lifted as Lifted (catches, finally) 53import Control.Exception.Lifted as Lifted (catches, finally)
@@ -432,6 +437,7 @@ dispatchHandler q @ KQuery {..} addr = do
432-- 437--
433handleQuery :: MonadKRPC h m => BValue -> KQuery -> SockAddr -> m () 438handleQuery :: MonadKRPC h m => BValue -> KQuery -> SockAddr -> m ()
434handleQuery raw q addr = void $ fork $ do 439handleQuery 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 ()
481listen = do 487listen = 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