on master help sign in
Expose the 'pin' and 'unpin' operations in arrays
8452956Adithya Kumar
core/src/Streamly/Data/Array.hs+5
@@ -69,6 +69,10 @@ module Streamly.Data.Array
69 -- * Unbox Type Class
69 -- * Unbox Type Class
70 , Unbox (..)
70 , Unbox (..)
71
71
72+ -- * Pinning & Unpinning
73+ , pin
74+ , unpin
75+
72 -- * Deprecated
76 -- * Deprecated
73 , read
77 , read
74 , readRev
78 , readRev
@@ -79,6 +83,7 @@ where
79
83
80import Streamly.Internal.Data.Unfold (Unfold)
84import Streamly.Internal.Data.Unfold (Unfold)
81import Streamly.Internal.Data.Array as A hiding (read, readRev)
85import Streamly.Internal.Data.Array as A hiding (read, readRev)
86+import Streamly.Internal.Data.Array.Type (pin, unpin)
82
87
83import Streamly.Internal.Data.Unbox (Unbox (..))
88import Streamly.Internal.Data.Unbox (Unbox (..))
84import Prelude hiding (read)
89import Prelude hiding (read)
core/src/Streamly/Data/MutArray.hs+4
@@ -80,6 +80,10 @@ module Streamly.Data.MutArray
80
80
81 -- * Unbox Type Class
81 -- * Unbox Type Class
82 , Unbox (..)
82 , Unbox (..)
83+
84+ -- * Pinning & Unpinning
85+ , pin
86+ , unpin
83 )
87 )
84where
88where
85
89
core/src/Streamly/Internal/Data/Array/Mut/Type.hs+4
@@ -353,12 +353,16 @@ data MutArray a =
353-- Pinning & Unpinning
353-- Pinning & Unpinning
354-------------------------------------------------------------------------------
354-------------------------------------------------------------------------------
355
355
356+-- | Copy the 'MutArray' to pinned memory if unpinned, else do nothing. The
357+-- overhead is a copy if the input array is unpinned.
356{-# INLINE pin #-}
358{-# INLINE pin #-}
357pin :: MutArray a -> IO (MutArray a)
359pin :: MutArray a -> IO (MutArray a)
358pin arr@MutArray{..} = do
360pin arr@MutArray{..} = do
359 contents <- Unboxed.pin arrContents
361 contents <- Unboxed.pin arrContents
360 return $ arr {arrContents = contents}
362 return $ arr {arrContents = contents}
361
363
364+-- | Copy the 'MutArray' to unpinned memory if pinned, else do nothing. The
365+-- overhead is a copy if the input array is pinned.
362{-# INLINE unpin #-}
366{-# INLINE unpin #-}
363unpin :: MutArray a -> IO (MutArray a)
367unpin :: MutArray a -> IO (MutArray a)
364unpin arr@MutArray{..} = do
368unpin 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
214-- Pinning & Unpinning
214-- Pinning & Unpinning
215-------------------------------------------------------------------------------
215-------------------------------------------------------------------------------
216
216
217+-- | Copy the 'Array' to pinned memory if unpinned, else do nothing. The
218+-- overhead is a copy if the input array is unpinned.
217{-# INLINE pin #-}
219{-# INLINE pin #-}
218pin :: Array a -> IO (Array a)
220pin :: Array a -> IO (Array a)
219pin = fmap unsafeFreeze . MA.pin . unsafeThaw
221pin = fmap unsafeFreeze . MA.pin . unsafeThaw
220
222
223+-- | Copy the 'Array' to unpinned memory if pinned, else do nothing. The
224+-- overhead is a copy if the input array is pinned.
221{-# INLINE unpin #-}
225{-# INLINE unpin #-}
222unpin :: Array a -> IO (Array a)
226unpin :: Array a -> IO (Array a)
223unpin = fmap unsafeFreeze . MA.unpin . unsafeThaw
227unpin = fmap unsafeFreeze . MA.unpin . unsafeThaw