on master help sign in
Expose the 'pin' and 'unpin' operations in arrays
commit84529565cad0e97d249ac38d3e5e46458ee2354a authorAdithya Kumar <adithya@composewell.com> dateTue 25 Jul 2023, 00:47 (3 years ago) parent3236d73
4 files changed+17
core/src/Streamly/Data/Array.hs+5 core/src/Streamly/Data/MutArray.hs+4 core/src/Streamly/Internal/Data/Array/Mut/Type.hs+4 core/src/Streamly/Internal/Data/Array/Type.hs+4
core/src/Streamly/Data/Array.hs+5
@@ -69,6 +69,10 @@ module Streamly.Data.Array
6969 -- * Unbox Type Class
7070 , Unbox (..)
7171
72+ -- * Pinning & Unpinning
73+ , pin
74+ , unpin
75+
7276 -- * Deprecated
7377 , read
7478 , readRev
@@ -79,6 +83,7 @@ where
7983
8084import Streamly.Internal.Data.Unfold (Unfold)
8185import Streamly.Internal.Data.Array as A hiding (read, readRev)
86+import Streamly.Internal.Data.Array.Type (pin, unpin)
8287
8388import Streamly.Internal.Data.Unbox (Unbox (..))
8489import Prelude hiding (read)
core/src/Streamly/Data/MutArray.hs+4
@@ -80,6 +80,10 @@ module Streamly.Data.MutArray
8080
8181 -- * Unbox Type Class
8282 , Unbox (..)
83+
84+ -- * Pinning & Unpinning
85+ , pin
86+ , unpin
8387 )
8488where
8589
core/src/Streamly/Internal/Data/Array/Mut/Type.hs+4
@@ -353,12 +353,16 @@ data MutArray a =
353353-- Pinning & Unpinning
354354-------------------------------------------------------------------------------
355355
356+-- | Copy the 'MutArray' to pinned memory if unpinned, else do nothing. The
357+-- overhead is a copy if the input array is unpinned.
356358{-# INLINE pin #-}
357359pin :: MutArray a -> IO (MutArray a)
358360pin arr@MutArray{..} = do
359361 contents <- Unboxed.pin arrContents
360362 return $ arr {arrContents = contents}
361363
364+-- | Copy the 'MutArray' to unpinned memory if pinned, else do nothing. The
365+-- overhead is a copy if the input array is pinned.
362366{-# INLINE unpin #-}
363367unpin :: MutArray a -> IO (MutArray a)
364368unpin arr@MutArray{..} = do
core/src/Streamly/Internal/Data/Array/Type.hs+4
@@ -214,10 +214,14 @@ unsafeThaw (Array ac as ae) = MutArray ac as ae ae
214214-- Pinning & Unpinning
215215-------------------------------------------------------------------------------
216216
217+-- | Copy the 'Array' to pinned memory if unpinned, else do nothing. The
218+-- overhead is a copy if the input array is unpinned.
217219{-# INLINE pin #-}
218220pin :: Array a -> IO (Array a)
219221pin = fmap unsafeFreeze . MA.pin . unsafeThaw
220222
223+-- | Copy the 'Array' to unpinned memory if pinned, else do nothing. The
224+-- overhead is a copy if the input array is pinned.
221225{-# INLINE unpin #-}
222226unpin :: Array a -> IO (Array a)
223227unpin = fmap unsafeFreeze . MA.unpin . unsafeThaw