@@ -35,21 +35,21 @@ import Streamly.Internal.Data.Time.Units
35 (MicroSecond64(..), fromAbsTime, addToAbsTime, toRelTime)
35 (MicroSecond64(..), fromAbsTime, addToAbsTime, toRelTime)
36import Streamly.Internal.Control.ForkIO (forkIOManaged)
36import Streamly.Internal.Control.ForkIO (forkIOManaged)
38−import qualified Streamly.Internal.Data.IORef.Prim as Prim
38+import qualified Streamly.Internal.Data.IORef.Unboxed as Unboxed
40------------------------------------------------------------------------------
40------------------------------------------------------------------------------
41-- Async clock
41-- Async clock
42------------------------------------------------------------------------------
42------------------------------------------------------------------------------
44{-# INLINE updateTimeVar #-}
44{-# INLINE updateTimeVar #-}
45−updateTimeVar :: Clock -> Prim.IORef MicroSecond64 -> IO ()
45+updateTimeVar :: Clock -> Unboxed.IORef MicroSecond64 -> IO ()
46updateTimeVar clock timeVar = do
46updateTimeVar clock timeVar = do
47 t <- fromAbsTime <$> getTime clock
47 t <- fromAbsTime <$> getTime clock
48− Prim.modifyIORef' timeVar (const t)
48+ Unboxed.modifyIORef' timeVar (const t)
50{-# INLINE updateWithDelay #-}
50{-# INLINE updateWithDelay #-}
51updateWithDelay :: RealFrac a =>
51updateWithDelay :: RealFrac a =>
52− Clock -> a -> Prim.IORef MicroSecond64 -> IO ()
52+ Clock -> a -> Unboxed.IORef MicroSecond64 -> IO ()
53updateWithDelay clock precision timeVar = do
53updateWithDelay clock precision timeVar = do
54 threadDelay (delayTime precision)
54 threadDelay (delayTime precision)
55 updateTimeVar clock timeVar
55 updateTimeVar clock timeVar
@@ -78,16 +78,16 @@ updateWithDelay clock precision timeVar = do
78-- CAUTION! This is safe only on a 64-bit machine. On a 32-bit machine a 64-bit
78-- CAUTION! This is safe only on a 64-bit machine. On a 32-bit machine a 64-bit
79-- 'Var' cannot be read consistently without a lock while another thread is
79-- 'Var' cannot be read consistently without a lock while another thread is
80-- writing to it.
80-- writing to it.
81−asyncClock :: Clock -> Double -> IO (ThreadId, Prim.IORef MicroSecond64)
81+asyncClock :: Clock -> Double -> IO (ThreadId, Unboxed.IORef MicroSecond64)
82asyncClock clock g = do
82asyncClock clock g = do
83− timeVar <- Prim.newIORef 0
83+ timeVar <- Unboxed.newIORef 0
84 updateTimeVar clock timeVar
84 updateTimeVar clock timeVar
85 tid <- forkIOManaged $ forever (updateWithDelay clock g timeVar)
85 tid <- forkIOManaged $ forever (updateWithDelay clock g timeVar)
86 return (tid, timeVar)
86 return (tid, timeVar)
88{-# INLINE readClock #-}
88{-# INLINE readClock #-}
89−readClock :: (ThreadId, Prim.IORef MicroSecond64) -> IO MicroSecond64
89+readClock :: (ThreadId, Unboxed.IORef MicroSecond64) -> IO MicroSecond64
90−readClock (_, timeVar) = Prim.readIORef timeVar
90+readClock (_, timeVar) = Unboxed.readIORef timeVar
92------------------------------------------------------------------------------
92------------------------------------------------------------------------------
93-- Adjustable Timer
93-- Adjustable Timer
@@ -98,19 +98,19 @@ data Timer = Timer ThreadId (MVar ()) (IO ())
99-- Set the expiry to current time + timer period
99-- Set the expiry to current time + timer period
100{-# INLINE resetTimerExpiry #-}
100{-# INLINE resetTimerExpiry #-}
101−resetTimerExpiry :: Clock -> MicroSecond64 -> Prim.IORef MicroSecond64 -> IO ()
101+resetTimerExpiry :: Clock -> MicroSecond64 -> Unboxed.IORef MicroSecond64 -> IO ()
102resetTimerExpiry clock period timeVar = do
102resetTimerExpiry clock period timeVar = do
103 t <- getTime clock
103 t <- getTime clock
104 let t1 = addToAbsTime t (toRelTime period)
104 let t1 = addToAbsTime t (toRelTime period)
105− Prim.modifyIORef' timeVar (const (fromAbsTime t1))
105+ Unboxed.modifyIORef' timeVar (const (fromAbsTime t1))
107{-# INLINE processTimerTick #-}
107{-# INLINE processTimerTick #-}
108processTimerTick :: RealFrac a =>
108processTimerTick :: RealFrac a =>
109− Clock -> a -> Prim.IORef MicroSecond64 -> MVar () -> IO () -> IO ()
109+ Clock -> a -> Unboxed.IORef MicroSecond64 -> MVar () -> IO () -> IO ()
110processTimerTick clock precision timeVar mvar reset = do
110processTimerTick clock precision timeVar mvar reset = do
111 threadDelay (delayTime precision)
111 threadDelay (delayTime precision)
112 t <- fromAbsTime <$> getTime clock
112 t <- fromAbsTime <$> getTime clock
113− expiry <- Prim.readIORef timeVar
113+ expiry <- Unboxed.readIORef timeVar
114 when (t >= expiry) $ do
114 when (t >= expiry) $ do
115 -- non-blocking put so that we can process multiple timers in a
115 -- non-blocking put so that we can process multiple timers in a
116 -- non-blocking manner in future.
116 -- non-blocking manner in future.
@@ -139,7 +139,7 @@ processTimerTick clock precision timeVar mvar reset = do
139timer :: Clock -> Double -> Double -> IO Timer
139timer :: Clock -> Double -> Double -> IO Timer
140timer clock g period = do
140timer clock g period = do
141 mvar <- newEmptyMVar
141 mvar <- newEmptyMVar
142− timeVar <- Prim.newIORef 0
142+ timeVar <- Unboxed.newIORef 0
143 let p = round (period * 1e6) :: Int
143 let p = round (period * 1e6) :: Int
144 p1 = fromIntegral p :: MicroSecond64
144 p1 = fromIntegral p :: MicroSecond64
145 reset = resetTimerExpiry clock p1 timeVar
145 reset = resetTimerExpiry clock p1 timeVar