{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UnliftedFFITypes #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module TextShow.Control.Concurrent () where
import Data.Text.Lazy.Builder (fromString)
import Foreign.C.Types
import GHC.Conc (BlockReason, ThreadStatus)
import GHC.Conc.Sync (ThreadId(..))
import GHC.Exts (Addr#, unsafeCoerce#)
import Prelude ()
import Prelude.Compat
import TextShow.Classes (TextShow(..))
import TextShow.Foreign.C.Types ()
import TextShow.TH.Internal (deriveTextShow)
#if MIN_VERSION_base(4,14,0)
import TextShow.Classes (showbParen)
import GHC.Show (appPrec)
#endif
instance TextShow ThreadId where
showbPrec :: Int -> ThreadId -> Builder
showbPrec Int
p ThreadId
t =
#if MIN_VERSION_base(4,14,0)
Bool -> Builder -> Builder
showbParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
appPrec) (Builder -> Builder) -> Builder -> Builder
forall a b. (a -> b) -> a -> b
$
#endif
String -> Builder
fromString String
"ThreadId " Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Int -> CInt -> Builder
forall a. TextShow a => Int -> a -> Builder
showbPrec Int
p (ThreadId -> CInt
getThreadId ThreadId
t)
{-# INLINE showbPrec #-}
foreign import ccall unsafe "rts_getThreadId" getThreadId# :: Addr# -> CInt
getThreadId :: ThreadId -> CInt
getThreadId :: ThreadId -> CInt
getThreadId (ThreadId ThreadId#
tid) = Addr# -> CInt
getThreadId# (ThreadId# -> Addr#
unsafeCoerce# ThreadId#
tid)
$(deriveTextShow ''BlockReason)
$(deriveTextShow ''ThreadStatus)