on master help sign in
Rename IORef.Prim to IORef.Unboxed
614c226Adithya Kumar
core/src/Streamly/Internal/Data/IORef/Prim.hs → core/src/Streamly/Internal/Data/IORef/Unboxed.hsrenamed+2−2
@@ -1,7 +1,7 @@
1{-# LANGUAGE UnboxedTuples #-}
1{-# LANGUAGE UnboxedTuples #-}
2
2
3-- |
3-- |
4−-- Module : Streamly.Internal.Data.IORef.Prim
4+-- Module : Streamly.Internal.Data.IORef.Unboxed
5-- Copyright : (c) 2019 Composewell Technologies
5-- Copyright : (c) 2019 Composewell Technologies
6--
6--
7-- License : BSD3
7-- License : BSD3
@@ -21,7 +21,7 @@
21-- reading it from another thread should give consistent old or new value. The
21-- reading it from another thread should give consistent old or new value. The
22-- same holds true for 32-bit values on a 32-bit platform.
22-- same holds true for 32-bit values on a 32-bit platform.
23
23
24−module Streamly.Internal.Data.IORef.Prim
24+module Streamly.Internal.Data.IORef.Unboxed
25 (
25 (
26 IORef
26 IORef
27
27
core/src/Streamly/Internal/Data/Stream/StreamD/Transform.hs+5−4
@@ -144,7 +144,7 @@ import Streamly.Internal.Data.Time.Units
144 (TimeUnit64, toRelTime64, diffAbsTime64)
144 (TimeUnit64, toRelTime64, diffAbsTime64)
145
145
146import qualified Streamly.Internal.Data.Fold.Type as FL
146import 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
148import qualified Streamly.Internal.Data.Pipe.Type as Pipe
148import qualified Streamly.Internal.Data.Pipe.Type as Pipe
149
149
150import Prelude hiding
150import Prelude hiding
@@ -344,17 +344,18 @@ pollCounts predicate fld (Stream step state) = Stream step' Nothing
344 -- As long as we are using an "Int" for counts lockfree reads from
344 -- As long as we are using an "Int" for counts lockfree reads from
345 -- Var should work correctly on both 32-bit and 64-bit machines.
345 -- Var should work correctly on both 32-bit and 64-bit machines.
346 -- However, an Int on a 32-bit machine may overflow quickly.
346 -- 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)
348 tid <- forkManaged
348 tid <- forkManaged
349 $ void $ fld
349 $ void $ fld
350− $ Prim.toStreamD countVar
350+ $ Unboxed.toStreamD countVar
351 return $ Skip (Just (countVar, tid, state))
351 return $ Skip (Just (countVar, tid, state))
352
352
353 step' gst (Just (countVar, tid, st)) = do
353 step' gst (Just (countVar, tid, st)) = do
354 r <- step gst st
354 r <- step gst st
355 case r of
355 case r of
356 Yield x s -> do
356 Yield x s -> do
357+ when (predicate x)
357− when (predicate x) $ liftIO $ Prim.modifyIORef' countVar (+ 1)
358+ $ liftIO $ Unboxed.modifyIORef' countVar (+ 1)
358 return $ Yield x (Just (countVar, tid, s))
359 return $ Yield x (Just (countVar, tid, s))
359 Skip s -> return $ Skip (Just (countVar, tid, s))
360 Skip s -> return $ Skip (Just (countVar, tid, s))
360 Stop -> do
361 Stop -> do
core/src/Streamly/Internal/Data/Time/Clock.hs+13−13
@@ -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)
37
37
38−import qualified Streamly.Internal.Data.IORef.Prim as Prim
38+import qualified Streamly.Internal.Data.IORef.Unboxed as Unboxed
39
39
40------------------------------------------------------------------------------
40------------------------------------------------------------------------------
41-- Async clock
41-- Async clock
42------------------------------------------------------------------------------
42------------------------------------------------------------------------------
43
43
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)
49
49
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)
87
87
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
91
91
92------------------------------------------------------------------------------
92------------------------------------------------------------------------------
93-- Adjustable Timer
93-- Adjustable Timer
@@ -98,19 +98,19 @@ data Timer = Timer ThreadId (MVar ()) (IO ())
98
98
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))
106
106
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
core/streamly-core.cabal+1−2
@@ -276,8 +276,7 @@ library
276 -- streamly-core-array-types
276 -- streamly-core-array-types
277 , Streamly.Internal.Data.Unboxed
277 , Streamly.Internal.Data.Unboxed
278 -- Unboxed IORef
278 -- Unboxed IORef
279− -- XXX Depends on primitive
280− , Streamly.Internal.Data.IORef.Prim
279+ , Streamly.Internal.Data.IORef.Unboxed
281 -- May depend on streamly-core-stream
280 -- May depend on streamly-core-stream
282 , Streamly.Internal.Data.Array.Foreign.Mut.Type
281 , Streamly.Internal.Data.Array.Foreign.Mut.Type
283 , Streamly.Internal.Data.Array.Foreign.Mut
282 , 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:
241
241
242Unboxed IORef:
242Unboxed IORef:
243
243
244−* `Streamly.Data.IORef.Prim`
244+* `Streamly.Data.IORef.Unboxed`
245
245
246## Strict Data
246## Strict Data
247
247
src/Streamly/Internal/Data/Stream/IsStream/Generate.hs+4−4
@@ -106,7 +106,7 @@ import Streamly.Internal.Data.Stream.Zip (ZipSerialM)
106import Streamly.Internal.Data.Time.Units (AbsTime , RelTime64, addToAbsTime64)
106import Streamly.Internal.Data.Time.Units (AbsTime , RelTime64, addToAbsTime64)
107import Streamly.Internal.Data.Unboxed (Unboxed)
107import Streamly.Internal.Data.Unboxed (Unboxed)
108
108
109−import qualified Streamly.Internal.Data.IORef.Prim as Prim
109+import qualified Streamly.Internal.Data.IORef.Unboxed as Unboxed
110import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
110import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
111import qualified Streamly.Internal.Data.Stream.Parallel as Par
111import qualified Streamly.Internal.Data.Stream.Parallel as Par
112import qualified Streamly.Internal.Data.Stream.Serial as Serial
112import qualified Streamly.Internal.Data.Stream.Serial as Serial
@@ -655,10 +655,10 @@ fromCallback setCallback = concatM $ do
655 setCallback callback
655 setCallback callback
656 return $ Stream.fromStreamK stream
656 return $ Stream.fromStreamK stream
657
657
658−-- | Construct a stream by reading a 'Prim' 'IORef' repeatedly.
658+-- | Construct a stream by reading an 'Unboxed' 'IORef' repeatedly.
659--
659--
660-- /Pre-release/
660-- /Pre-release/
661--
661--
662{-# INLINE fromPrimIORef #-}
662{-# INLINE fromPrimIORef #-}
663−fromPrimIORef :: (IsStream t, MonadIO m, Unboxed a) => Prim.IORef a -> t m a
663+fromPrimIORef :: (IsStream t, MonadIO m, Unboxed a) => Unboxed.IORef a -> t m a
664−fromPrimIORef = fromStreamD . Prim.toStreamD
664+fromPrimIORef = fromStreamD . Unboxed.toStreamD
streamly.cabal+2−3
@@ -164,7 +164,7 @@ extra-source-files:
164 core/src/Streamly/Internal/Data/Parser/ParserD/Type.hs
164 core/src/Streamly/Internal/Data/Parser/ParserD/Type.hs
165 core/src/Streamly/Internal/Data/Pipe/Type.hs
165 core/src/Streamly/Internal/Data/Pipe/Type.hs
166 core/src/Streamly/Internal/Data/Unboxed.hs
166 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
168 core/src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs
168 core/src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs
169 core/src/Streamly/Internal/Data/Array/Foreign/Mut.hs
169 core/src/Streamly/Internal/Data/Array/Foreign/Mut.hs
170 core/src/Streamly/Internal/Data/Array/Foreign/Type.hs
170 core/src/Streamly/Internal/Data/Array/Foreign/Type.hs
@@ -567,8 +567,7 @@ library
567 -- streamly-core-array-types
567 -- streamly-core-array-types
568 , Streamly.Internal.Data.Unboxed
568 , Streamly.Internal.Data.Unboxed
569 -- Unboxed IORef
569 -- Unboxed IORef
570− -- XXX Depends on primitive
571− , Streamly.Internal.Data.IORef.Prim
570+ , Streamly.Internal.Data.IORef.Unboxed
572 -- May depend on streamly-core-stream
571 -- May depend on streamly-core-stream
573 , Streamly.Internal.Data.Array.Foreign.Mut.Type
572 , Streamly.Internal.Data.Array.Foreign.Mut.Type
574 , Streamly.Internal.Data.Array.Foreign.Mut
573 , Streamly.Internal.Data.Array.Foreign.Mut