on master help sign in
Rename IORef.Prim to IORef.Unboxed
commit614c226eac1f5a0f5dae8534f44084237cb79650 authorAdithya Kumar <adithya@composewell.com> dateSun 31 Jul 2022, 01:53 (4 years ago) parent4a2d68d
7 files changed+28−29
core/src/Streamly/Internal/Data/IORef/Prim.hs → core/src/Streamly/Internal/Data/IORef/Unboxed.hs+2−2 core/src/Streamly/Internal/Data/Stream/StreamD/Transform.hs+5−4 core/src/Streamly/Internal/Data/Time/Clock.hs+13−13 core/streamly-core.cabal+1−2 docs/Developer/module-organization.md+1−1 src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+4−4 streamly.cabal+2−3
core/src/Streamly/Internal/Data/IORef/Prim.hs → core/src/Streamly/Internal/Data/IORef/Unboxed.hsrenamed+2−2
@@ -1,7 +1,7 @@
11{-# LANGUAGE UnboxedTuples #-}
22
33-- |
4−-- Module : Streamly.Internal.Data.IORef.Prim
4+-- Module : Streamly.Internal.Data.IORef.Unboxed
55-- Copyright : (c) 2019 Composewell Technologies
66--
77-- License : BSD3
@@ -21,7 +21,7 @@
2121-- reading it from another thread should give consistent old or new value. The
2222-- same holds true for 32-bit values on a 32-bit platform.
2323
24−module Streamly.Internal.Data.IORef.Prim
24+module Streamly.Internal.Data.IORef.Unboxed
2525 (
2626 IORef
2727
core/src/Streamly/Internal/Data/Stream/StreamD/Transform.hs+5−4
@@ -144,7 +144,7 @@ import Streamly.Internal.Data.Time.Units
144144 (TimeUnit64, toRelTime64, diffAbsTime64)
145145
146146import qualified Streamly.Internal.Data.Fold.Type as FL
147−import qualified Streamly.Internal.Data.IORef.Prim as Prim
147+import qualified Streamly.Internal.Data.IORef.Unboxed as Unboxed
148148import qualified Streamly.Internal.Data.Pipe.Type as Pipe
149149
150150import Prelude hiding
@@ -344,17 +344,18 @@ pollCounts predicate fld (Stream step state) = Stream step' Nothing
344344 -- As long as we are using an "Int" for counts lockfree reads from
345345 -- Var should work correctly on both 32-bit and 64-bit machines.
346346 -- However, an Int on a 32-bit machine may overflow quickly.
347− countVar <- liftIO $ Prim.newIORef (0 :: Int)
347+ countVar <- liftIO $ Unboxed.newIORef (0 :: Int)
348348 tid <- forkManaged
349349 $ void $ fld
350− $ Prim.toStreamD countVar
350+ $ Unboxed.toStreamD countVar
351351 return $ Skip (Just (countVar, tid, state))
352352
353353 step' gst (Just (countVar, tid, st)) = do
354354 r <- step gst st
355355 case r of
356356 Yield x s -> do
357− when (predicate x) $ liftIO $ Prim.modifyIORef' countVar (+ 1)
357+ when (predicate x)
358+ $ liftIO $ Unboxed.modifyIORef' countVar (+ 1)
358359 return $ Yield x (Just (countVar, tid, s))
359360 Skip s -> return $ Skip (Just (countVar, tid, s))
360361 Stop -> do
core/src/Streamly/Internal/Data/Time/Clock.hs+13−13
@@ -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
core/streamly-core.cabal+1−2
@@ -276,8 +276,7 @@ library
276276 -- streamly-core-array-types
277277 , Streamly.Internal.Data.Unboxed
278278 -- Unboxed IORef
279− -- XXX Depends on primitive
280− , Streamly.Internal.Data.IORef.Prim
279+ , Streamly.Internal.Data.IORef.Unboxed
281280 -- May depend on streamly-core-stream
282281 , Streamly.Internal.Data.Array.Foreign.Mut.Type
283282 , Streamly.Internal.Data.Array.Foreign.Mut
docs/Developer/module-organization.md+1−1
@@ -241,7 +241,7 @@ Mutable arrays are a generalization of immutable arrays:
241241
242242Unboxed IORef:
243243
244−* `Streamly.Data.IORef.Prim`
244+* `Streamly.Data.IORef.Unboxed`
245245
246246## Strict Data
247247
src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+4−4
@@ -106,7 +106,7 @@ import Streamly.Internal.Data.Stream.Zip (ZipSerialM)
106106import Streamly.Internal.Data.Time.Units (AbsTime , RelTime64, addToAbsTime64)
107107import Streamly.Internal.Data.Unboxed (Unboxed)
108108
109−import qualified Streamly.Internal.Data.IORef.Prim as Prim
109+import qualified Streamly.Internal.Data.IORef.Unboxed as Unboxed
110110import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
111111import qualified Streamly.Internal.Data.Stream.Parallel as Par
112112import qualified Streamly.Internal.Data.Stream.Serial as Serial
@@ -655,10 +655,10 @@ fromCallback setCallback = concatM $ do
655655 setCallback callback
656656 return $ Stream.fromStreamK stream
657657
658−-- | Construct a stream by reading a 'Prim' 'IORef' repeatedly.
658+-- | Construct a stream by reading an 'Unboxed' 'IORef' repeatedly.
659659--
660660-- /Pre-release/
661661--
662662{-# INLINE fromPrimIORef #-}
663−fromPrimIORef :: (IsStream t, MonadIO m, Unboxed a) => Prim.IORef a -> t m a
664−fromPrimIORef = fromStreamD . Prim.toStreamD
663+fromPrimIORef :: (IsStream t, MonadIO m, Unboxed a) => Unboxed.IORef a -> t m a
664+fromPrimIORef = fromStreamD . Unboxed.toStreamD
streamly.cabal+2−3
@@ -164,7 +164,7 @@ extra-source-files:
164164 core/src/Streamly/Internal/Data/Parser/ParserD/Type.hs
165165 core/src/Streamly/Internal/Data/Pipe/Type.hs
166166 core/src/Streamly/Internal/Data/Unboxed.hs
167− core/src/Streamly/Internal/Data/IORef/Prim.hs
167+ core/src/Streamly/Internal/Data/IORef/Unboxed.hs
168168 core/src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs
169169 core/src/Streamly/Internal/Data/Array/Foreign/Mut.hs
170170 core/src/Streamly/Internal/Data/Array/Foreign/Type.hs
@@ -567,8 +567,7 @@ library
567567 -- streamly-core-array-types
568568 , Streamly.Internal.Data.Unboxed
569569 -- Unboxed IORef
570− -- XXX Depends on primitive
571− , Streamly.Internal.Data.IORef.Prim
570+ , Streamly.Internal.Data.IORef.Unboxed
572571 -- May depend on streamly-core-stream
573572 , Streamly.Internal.Data.Array.Foreign.Mut.Type
574573 , Streamly.Internal.Data.Array.Foreign.Mut