@@ -35,21 +35,21 @@ import Streamly.Internal.Data.Time.Units
3535 (MicroSecond64(..), fromAbsTime, addToAbsTime, toRelTime)
3636import Streamly.Internal.Control.ForkIO (forkIOManaged)
3737
38−import qualified Streamly.Internal.Data.IORef.Prim as Prim
38+import qualified Streamly.Internal.Data.IORef.Unboxed as Unboxed
3939
4040------------------------------------------------------------------------------
4141-- Async clock
4242------------------------------------------------------------------------------
4343
4444{-# INLINE updateTimeVar #-}
45−updateTimeVar :: Clock -> Prim.IORef MicroSecond64 -> IO ()
45+updateTimeVar :: Clock -> Unboxed.IORef MicroSecond64 -> IO ()
4646updateTimeVar clock timeVar = do
4747 t <- fromAbsTime <$> getTime clock
48− Prim.modifyIORef' timeVar (const t)
48+ Unboxed.modifyIORef' timeVar (const t)
4949
5050{-# INLINE updateWithDelay #-}
5151updateWithDelay :: RealFrac a =>
52− Clock -> a -> Prim.IORef MicroSecond64 -> IO ()
52+ Clock -> a -> Unboxed.IORef MicroSecond64 -> IO ()
5353updateWithDelay clock precision timeVar = do
5454 threadDelay (delayTime precision)
5555 updateTimeVar clock timeVar
@@ -78,16 +78,16 @@ updateWithDelay clock precision timeVar = do
7878-- CAUTION! This is safe only on a 64-bit machine. On a 32-bit machine a 64-bit
7979-- 'Var' cannot be read consistently without a lock while another thread is
8080-- writing to it.
81−asyncClock :: Clock -> Double -> IO (ThreadId, Prim.IORef MicroSecond64)
81+asyncClock :: Clock -> Double -> IO (ThreadId, Unboxed.IORef MicroSecond64)
8282asyncClock clock g = do
83− timeVar <- Prim.newIORef 0
83+ timeVar <- Unboxed.newIORef 0
8484 updateTimeVar clock timeVar
8585 tid <- forkIOManaged $ forever (updateWithDelay clock g timeVar)
8686 return (tid, timeVar)
8787
8888{-# INLINE readClock #-}
89−readClock :: (ThreadId, Prim.IORef MicroSecond64) -> IO MicroSecond64
90−readClock (_, timeVar) = Prim.readIORef timeVar
89+readClock :: (ThreadId, Unboxed.IORef MicroSecond64) -> IO MicroSecond64
90+readClock (_, timeVar) = Unboxed.readIORef timeVar
9191
9292------------------------------------------------------------------------------
9393-- Adjustable Timer
@@ -98,19 +98,19 @@ data Timer = Timer ThreadId (MVar ()) (IO ())
9898
9999-- Set the expiry to current time + timer period
100100{-# INLINE resetTimerExpiry #-}
101−resetTimerExpiry :: Clock -> MicroSecond64 -> Prim.IORef MicroSecond64 -> IO ()
101+resetTimerExpiry :: Clock -> MicroSecond64 -> Unboxed.IORef MicroSecond64 -> IO ()
102102resetTimerExpiry clock period timeVar = do
103103 t <- getTime clock
104104 let t1 = addToAbsTime t (toRelTime period)
105− Prim.modifyIORef' timeVar (const (fromAbsTime t1))
105+ Unboxed.modifyIORef' timeVar (const (fromAbsTime t1))
106106
107107{-# INLINE processTimerTick #-}
108108processTimerTick :: RealFrac a =>
109− Clock -> a -> Prim.IORef MicroSecond64 -> MVar () -> IO () -> IO ()
109+ Clock -> a -> Unboxed.IORef MicroSecond64 -> MVar () -> IO () -> IO ()
110110processTimerTick clock precision timeVar mvar reset = do
111111 threadDelay (delayTime precision)
112112 t <- fromAbsTime <$> getTime clock
113− expiry <- Prim.readIORef timeVar
113+ expiry <- Unboxed.readIORef timeVar
114114 when (t >= expiry) $ do
115115 -- non-blocking put so that we can process multiple timers in a
116116 -- non-blocking manner in future.
@@ -139,7 +139,7 @@ processTimerTick clock precision timeVar mvar reset = do
139139timer :: Clock -> Double -> Double -> IO Timer
140140timer clock g period = do
141141 mvar <- newEmptyMVar
142− timeVar <- Prim.newIORef 0
142+ timeVar <- Unboxed.newIORef 0
143143 let p = round (period * 1e6) :: Int
144144 p1 = fromIntegral p :: MicroSecond64
145145 reset = resetTimerExpiry clock p1 timeVar