module TextShow.Control.Concurrent (
showbThreadIdPrec
, showbThreadStatusPrec
, showbBlockReason
) where
import Data.Monoid.Compat ((<>))
import Data.Text.Lazy.Builder (Builder, fromString)
import Foreign.C.Types
import GHC.Conc (BlockReason, ThreadStatus)
import GHC.Conc.Sync (ThreadId(..))
import GHC.Prim
import TextShow.Classes (TextShow(..))
import TextShow.Foreign.C.Types (showbCIntPrec)
import TextShow.TH.Internal (deriveTextShow)
#include "inline.h"
showbThreadIdPrec :: Int -> ThreadId -> Builder
showbThreadIdPrec p t = fromString "ThreadId " <> showbCIntPrec p (getThreadId t)
foreign import ccall unsafe "rts_getThreadId" getThreadId# :: Addr# -> CInt
getThreadId :: ThreadId -> CInt
getThreadId (ThreadId tid) = getThreadId# (unsafeCoerce# tid)
showbThreadStatusPrec :: Int -> ThreadStatus -> Builder
showbThreadStatusPrec = showbPrec
showbBlockReason :: BlockReason -> Builder
showbBlockReason = showb
instance TextShow ThreadId where
showbPrec = showbThreadIdPrec
INLINE_INST_FUN(showbPrec)
$(deriveTextShow ''ThreadStatus)
$(deriveTextShow ''BlockReason)