Skip to content

Commit f37999f

Browse files
Change the signature of pollIntIORef
1 parent f568c76 commit f37999f

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

core/src/Streamly/Internal/Data/IORef.hs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ module Streamly.Internal.Data.IORef
3232

3333
-- Read
3434
, readIORef
35+
, pollGenericIORef
36+
, pollIORefInt
37+
38+
-- Deprecated
3539
, pollIntIORef
3640
)
3741
where
3842

3943
#include "inline.hs"
44+
#include "deprecation.h"
4045

4146
import Control.Monad.IO.Class (MonadIO(..))
4247
#if __GLASGOW_HASKELL__ >= 810
@@ -88,20 +93,30 @@ modifyIORef' var g = do
8893
x <- readIORef var
8994
writeIORef var (g x)
9095

91-
-- | Generate a stream by continuously reading the IORef.
92-
--
93-
-- This operation reads the IORef without any synchronization. It can be
94-
-- assumed to be atomic because the IORef (MutableByteArray) is always aligned
95-
-- to Int boundaries, we are assuming that compiler uses single instructions to
96-
-- access the memory. It may read stale values though until caches are
97-
-- synchronised in a multiprocessor architecture.
98-
--
99-
-- /Pre-release/
100-
{-# INLINE_NORMAL pollIntIORef #-}
101-
pollIntIORef :: (MonadIO m, Unbox a) => IORef a -> D.Stream m a
102-
pollIntIORef var = D.Stream step ()
96+
-- | Internal, do not use.
97+
{-# INLINE_NORMAL pollGenericIORef #-}
98+
pollGenericIORef :: (MonadIO m, Unbox a) => IORef a -> D.Stream m a
99+
pollGenericIORef var = D.Stream step ()
103100

104101
where
105102

106103
{-# INLINE_LATE step #-}
107104
step _ () = liftIO (readIORef var) >>= \x -> return $ D.Yield x ()
105+
106+
{-# DEPRECATED pollIntIORef "Use pollIORefInt instead." #-}
107+
{-# INLINE_NORMAL pollIntIORef #-}
108+
pollIntIORef :: (MonadIO m, Unbox a) => IORef a -> D.Stream m a
109+
pollIntIORef = pollGenericIORef
110+
111+
-- | Generate a stream by continuously reading the IORef.
112+
--
113+
-- This operation reads the IORef without any synchronization. It can be
114+
-- assumed to be atomic because the size fits into machine register size. We
115+
-- are assuming that compiler uses single instructions to access the memory. It
116+
-- may read stale values though until caches are synchronised in a
117+
-- multiprocessor architecture.
118+
--
119+
-- /Pre-release/
120+
{-# INLINE_NORMAL pollIORefInt #-}
121+
pollIORefInt :: MonadIO m => IORef Int -> D.Stream m Int
122+
pollIORefInt = pollGenericIORef

core/src/Streamly/Internal/Data/MutArray.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ type IORef = IORef.IORef
402402

403403
{-# DEPRECATED pollIntIORef "Use pollIntIORef from MutByteArray module." #-}
404404
pollIntIORef :: (MonadIO m, Unbox a) => IORef a -> Stream m a
405-
pollIntIORef = IORef.pollIntIORef
405+
pollIntIORef = IORef.pollGenericIORef
406406

407407
{-# DEPRECATED newIORef "Use newIORef from MutByteArray module." #-}
408408
newIORef :: forall a. Unbox a => a -> IO (IORef a)

src/Streamly/Internal/Data/Stream/Concurrent.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ parTapCount predicate fld (D.Stream step state) = D.Stream step' Nothing
749749
countVar <- liftIO $ Unboxed.newIORef (0 :: Int)
750750
tid <- forkManaged
751751
$ void $ fld
752-
$ Unboxed.pollIntIORef countVar
752+
$ Unboxed.pollIORefInt countVar
753753
return $ Skip (Just (countVar, tid, state))
754754

755755
step' gst (Just (countVar, tid, st)) = do

0 commit comments

Comments
 (0)