{-# OPTIONS_GHC -optc-DHAVE_CLOCK_MONOTONIC_RAW #-}
{-# OPTIONS_GHC -optc-DHAVE_CLOCK_MONOTONIC_COARSE #-}
{-# OPTIONS_GHC -optc-DHAVE_CLOCK_MONOTONIC_UPTIME #-}
{-# OPTIONS_GHC -optc-DHAVE_CLOCK_REALTIME_COARSE #-}
{-# LINE 1 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# OPTIONS_GHC -Wno-identities #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# LINE 5 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 7 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
module Streamly.Internal.Data.Time.Clock.Type
(
Clock(..)
, getTime
)
where
import Data.Int (Int32, Int64)
import Data.Typeable (Typeable)
import Data.Word (Word32)
import Foreign.C (CInt(..), throwErrnoIfMinus1_, CTime(..), CLong(..))
import Foreign.Marshal.Alloc (alloca)
import Foreign.Ptr (Ptr)
import Foreign.Storable (Storable(..), peek)
import GHC.Generics (Generic)
import Streamly.Internal.Data.Time.Units (TimeSpec(..), AbsTime(..))
{-# LINE 46 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 49 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 51 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 54 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 56 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 60 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 62 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 64 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 68 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 70 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 72 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 74 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
data Clock
= Monotonic
| Realtime
{-# LINE 100 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
| ProcessCPUTime
| ThreadCPUTime
{-# LINE 110 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 112 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
| MonotonicRaw
{-# LINE 119 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 121 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
| MonotonicCoarse
{-# LINE 126 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 128 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
| Uptime
{-# LINE 137 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 139 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
| RealtimeCoarse
{-# LINE 144 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
deriving (Clock -> Clock -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Clock -> Clock -> Bool
$c/= :: Clock -> Clock -> Bool
== :: Clock -> Clock -> Bool
$c== :: Clock -> Clock -> Bool
Eq, Int -> Clock
Clock -> Int
Clock -> [Clock]
Clock -> Clock
Clock -> Clock -> [Clock]
Clock -> Clock -> Clock -> [Clock]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Clock -> Clock -> Clock -> [Clock]
$cenumFromThenTo :: Clock -> Clock -> Clock -> [Clock]
enumFromTo :: Clock -> Clock -> [Clock]
$cenumFromTo :: Clock -> Clock -> [Clock]
enumFromThen :: Clock -> Clock -> [Clock]
$cenumFromThen :: Clock -> Clock -> [Clock]
enumFrom :: Clock -> [Clock]
$cenumFrom :: Clock -> [Clock]
fromEnum :: Clock -> Int
$cfromEnum :: Clock -> Int
toEnum :: Int -> Clock
$ctoEnum :: Int -> Clock
pred :: Clock -> Clock
$cpred :: Clock -> Clock
succ :: Clock -> Clock
$csucc :: Clock -> Clock
Enum, forall x. Rep Clock x -> Clock
forall x. Clock -> Rep Clock x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Clock x -> Clock
$cfrom :: forall x. Clock -> Rep Clock x
Generic, ReadPrec [Clock]
ReadPrec Clock
Int -> ReadS Clock
ReadS [Clock]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Clock]
$creadListPrec :: ReadPrec [Clock]
readPrec :: ReadPrec Clock
$creadPrec :: ReadPrec Clock
readList :: ReadS [Clock]
$creadList :: ReadS [Clock]
readsPrec :: Int -> ReadS Clock
$creadsPrec :: Int -> ReadS Clock
Read, Int -> Clock -> ShowS
[Clock] -> ShowS
Clock -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Clock] -> ShowS
$cshowList :: [Clock] -> ShowS
show :: Clock -> String
$cshow :: Clock -> String
showsPrec :: Int -> Clock -> ShowS
$cshowsPrec :: Int -> Clock -> ShowS
Show)
{-# LINE 152 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
clockToPosixClockId :: Clock -> Int32
{-# LINE 154 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
clockToPosixClockId Monotonic = 1
{-# LINE 155 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
clockToPosixClockId Realtime = 0
{-# LINE 156 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
clockToPosixClockId ProcessCPUTime = 2
{-# LINE 157 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
clockToPosixClockId ThreadCPUTime = 3
{-# LINE 158 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 160 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
clockToPosixClockId MonotonicRaw = 4
{-# LINE 161 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 162 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 164 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
clockToPosixClockId MonotonicCoarse = 6
{-# LINE 165 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 168 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 170 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
clockToPosixClockId RealtimeCoarse = 5
{-# LINE 171 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 172 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 174 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
clockToPosixClockId Uptime = 7
{-# LINE 175 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 178 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# LINE 195 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# INLINE getTimeWith #-}
getTimeWith :: (Ptr TimeSpec -> IO ()) -> IO AbsTime
getTimeWith :: (Ptr TimeSpec -> IO ()) -> IO AbsTime
getTimeWith Ptr TimeSpec -> IO ()
f = do
TimeSpec
t <- forall a b. Storable a => (Ptr a -> IO b) -> IO b
alloca (\Ptr TimeSpec
ptr -> Ptr TimeSpec -> IO ()
f Ptr TimeSpec
ptr forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Storable a => Ptr a -> IO a
peek Ptr TimeSpec
ptr)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ TimeSpec -> AbsTime
AbsTime TimeSpec
t
{-# LINE 218 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
foreign import ccall unsafe "time.h clock_gettime"
clock_gettime :: Int32 -> Ptr TimeSpec -> IO CInt
{-# LINE 221 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}
{-# INLINABLE getTime #-}
getTime :: Clock -> IO AbsTime
getTime :: Clock -> IO AbsTime
getTime Clock
clock =
(Ptr TimeSpec -> IO ()) -> IO AbsTime
getTimeWith (forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"clock_gettime" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int32 -> Ptr TimeSpec -> IO CInt
clock_gettime (Clock -> Int32
clockToPosixClockId Clock
clock))
{-# LINE 253 "src/Streamly/Internal/Data/Time/Clock/Type.hsc" #-}