@@ -32,11 +32,16 @@ module Streamly.Internal.Data.IORef
3232
3333 -- Read
3434 , readIORef
35+ , pollGenericIORef
36+ , pollIORefInt
37+
38+ -- Deprecated
3539 , pollIntIORef
3640 )
3741where
3842
3943#include "inline.hs"
44+ #include "deprecation.h"
4045
4146import 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
0 commit comments