-
-
Save dminuoso/e17a7de0657cb707078176bdb081b806 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE MagicHash #-} | |
{-# LANGUAGE UnboxedTuples #-} | |
{-# LANGUAGE UnliftedFFITypes #-} | |
module Modgud.Unsafe | |
( threadId | |
) | |
where | |
import GHC.Exts (ThreadId#, myThreadId#) | |
import Data.Word (Word64) | |
import Foreign.C.Types (CULLong(..)) | |
import GHC.IO (IO(..)) | |
foreign import ccall unsafe "rts_getThreadId" getThreadId :: ThreadId# -> CULLong | |
-- | Convenience version of 'getThreadId' that we can pretty print without roundtripping through Show. | |
threadId :: IO Word64 | |
threadId = IO $ \s -> | |
case myThreadId# s of | |
(# s1, tid #) -> case getThreadId tid of | |
CULLong ll -> (# s1, ll #) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment