Copyright | (c) Alexey Kuleshevich 2020 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <alexey@kuleshevi.ch> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Addr e = Addr {}
- castAddr :: Addr e -> Addr b
- fromBytesAddr :: Bytes 'Pin -> Addr e
- curOffAddr :: Prim e => Addr e -> Off e
- byteCountAddr :: Addr e -> Count Word8
- countAddr :: forall e. Prim e => Addr e -> Count e
- plusOffAddr :: Prim e => Addr e -> Off e -> Addr e
- plusByteOffAddr :: Addr e -> Off Word8 -> Addr e
- indexAddr :: Prim e => Addr e -> e
- indexOffAddr :: Prim e => Addr e -> Off e -> e
- indexByteOffAddr :: Prim e => Addr e -> Off Word8 -> e
- readAddr :: (MonadPrim s m, Prim e) => Addr e -> m e
- readOffAddr :: (MonadPrim s m, Prim e) => Addr e -> Off e -> m e
- readByteOffAddr :: (MonadPrim s m, Prim e) => Addr e -> Off Word8 -> m e
- thawAddr :: MonadPrim s m => Addr e -> m (MAddr e s)
- freezeMAddr :: MonadPrim s m => MAddr e s -> m (Addr e)
- withPtrAddr :: MonadPrim s m => Addr e -> (Ptr e -> m b) -> m b
- withAddrAddr# :: MonadPrim s m => Addr e -> (Addr# -> m b) -> m b
- withNoHaltPtrAddr :: MonadUnliftPrim s m => Addr e -> (Ptr e -> m b) -> m b
- data MAddr e s = MAddr {
- mAddrAddr# :: Addr#
- mAddrMBytes :: MBytes 'Pin s
- castMAddr :: MAddr e s -> MAddr b s
- newMAddr :: forall e m s. (MonadPrim s m, Prim e) => e -> m (MAddr e s)
- allocMAddr :: forall e m s. (MonadPrim s m, Prim e) => Count e -> m (MAddr e s)
- allocAlignedMAddr :: forall e m s. (MonadPrim s m, Prim e) => Count e -> m (MAddr e s)
- allocZeroMAddr :: forall e m s. (MonadPrim s m, Prim e) => Count e -> m (MAddr e s)
- allocZeroAlignedMAddr :: forall e m s. (MonadPrim s m, Prim e) => Count e -> m (MAddr e s)
- reallocMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Count e -> m (MAddr e s)
- shrinkMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Count e -> m ()
- shrinkByteCountMAddr :: MonadPrim s m => MAddr e s -> Count Word8 -> m ()
- setMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> Count e -> e -> m ()
- curOffMAddr :: forall e s. Prim e => MAddr e s -> Off e
- getByteCountMAddr :: MonadPrim s m => MAddr e s -> m (Count Word8)
- getCountMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> m (Count e)
- plusOffMAddr :: Prim e => MAddr e s -> Off e -> MAddr e s
- plusByteOffMAddr :: MAddr e s -> Off Word8 -> MAddr e s
- readMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> m e
- readOffMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> m e
- readByteOffMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off Word8 -> m e
- writeMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> e -> m ()
- writeOffMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> e -> m ()
- writeByteOffMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off Word8 -> e -> m ()
- copyAddrToMAddr :: (MonadPrim s m, Prim e) => Addr e -> Off e -> MAddr e s -> Off e -> Count e -> m ()
- moveMAddrToMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> MAddr e s -> Off e -> Count e -> m ()
- modifyMAddr :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> (a, b)) -> m b
- modifyMAddr_ :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> a) -> m ()
- modifyFetchOldMAddr :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> a) -> m a
- modifyFetchNewMAddr :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> a) -> m a
- modifyMAddrM :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m (a, b)) -> m b
- modifyMAddrM_ :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m a) -> m ()
- modifyFetchOldMAddrM :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m a) -> m a
- modifyFetchNewMAddrM :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m a) -> m a
- swapMAddrs_ :: (MonadPrim s m, Prim a) => MAddr a s -> MAddr a s -> m ()
- swapMAddrs :: (MonadPrim s m, Prim a) => MAddr a s -> MAddr a s -> m (a, a)
- withPtrMAddr :: MonadPrim s m => MAddr e s -> (Ptr e -> m b) -> m b
- withAddrMAddr# :: MonadPrim s m => MAddr e s -> (Addr# -> m b) -> m b
- withNoHaltPtrMAddr :: MonadUnliftPrim s m => MAddr e s -> (Ptr e -> m b) -> m b
- toForeignPtrAddr :: Addr e -> ForeignPtr e
- toForeignPtrMAddr :: MAddr e s -> ForeignPtr e
- fromForeignPtrAddr :: ForeignPtr e -> Maybe (Addr e)
- fromForeignPtrMAddr :: ForeignPtr e -> Maybe (MAddr e s)
- toByteStringAddr :: Addr Word8 -> ByteString
- toShortByteStringAddr :: Addr Word8 -> (ShortByteString, Off Word8)
- fromShortByteStringAddr :: ShortByteString -> Addr Word8
- fromByteStringAddr :: ByteString -> (Addr Word8, Count Word8)
- fromByteStringMAddr :: ByteString -> (MAddr Word8 s, Count Word8)
- casOffMAddr :: (MonadPrim s m, Atomic e) => MAddr e s -> Off e -> e -> e -> m e
- casBoolOffMAddr :: (MonadPrim s m, Atomic e) => MAddr e s -> Off e -> e -> e -> m Bool
- casBoolFetchOffMAddr :: (MonadPrim s m, Atomic e) => MAddr e s -> Off e -> e -> e -> m (Bool, e)
- atomicReadOffMAddr :: (MonadPrim s m, Atomic e) => MAddr e s -> Off e -> m e
- atomicWriteOffMAddr :: (MonadPrim s m, Atomic e) => MAddr e s -> Off e -> e -> m ()
- atomicModifyOffMAddr :: (MonadPrim s m, Atomic e) => MAddr e s -> Off e -> (e -> (e, b)) -> m b
- atomicModifyOffMAddr_ :: (MonadPrim s m, Atomic e) => MAddr e s -> Off e -> (e -> e) -> m ()
- atomicModifyFetchOldOffMAddr :: (MonadPrim s m, Atomic e) => MAddr e s -> Off e -> (e -> e) -> m e
- atomicModifyFetchNewOffMAddr :: (MonadPrim s m, Atomic e) => MAddr e s -> Off e -> (e -> e) -> m e
- atomicAddFetchOldOffMAddr :: (MonadPrim s m, AtomicCount e) => MAddr e s -> Off e -> e -> m e
- atomicAddFetchNewOffMAddr :: (MonadPrim s m, AtomicCount e) => MAddr e s -> Off e -> e -> m e
- atomicSubFetchOldOffMAddr :: (MonadPrim s m, AtomicCount e) => MAddr e s -> Off e -> e -> m e
- atomicSubFetchNewOffMAddr :: (MonadPrim s m, AtomicCount e) => MAddr e s -> Off e -> e -> m e
- atomicAndFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e
- atomicAndFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e
- atomicNandFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e
- atomicNandFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e
- atomicOrFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e
- atomicOrFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e
- atomicXorFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e
- atomicXorFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e
- atomicNotFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> m e
- atomicNotFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> m e
- prefetchAddr0 :: MonadPrim s m => Addr e -> m ()
- prefetchMAddr0 :: MonadPrim s m => MAddr e s -> m ()
- prefetchAddr1 :: MonadPrim s m => Addr e -> m ()
- prefetchMAddr1 :: MonadPrim s m => MAddr e s -> m ()
- prefetchAddr2 :: MonadPrim s m => Addr e -> m ()
- prefetchMAddr2 :: MonadPrim s m => MAddr e s -> m ()
- prefetchAddr3 :: MonadPrim s m => Addr e -> m ()
- prefetchMAddr3 :: MonadPrim s m => MAddr e s -> m ()
- prefetchOffAddr0 :: (MonadPrim s m, Prim e) => Addr e -> Off e -> m ()
- prefetchOffMAddr0 :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> m ()
- prefetchOffAddr1 :: (MonadPrim s m, Prim e) => Addr e -> Off e -> m ()
- prefetchOffMAddr1 :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> m ()
- prefetchOffAddr2 :: (MonadPrim s m, Prim e) => Addr e -> Off e -> m ()
- prefetchOffMAddr2 :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> m ()
- prefetchOffAddr3 :: (MonadPrim s m, Prim e) => Addr e -> Off e -> m ()
- prefetchOffMAddr3 :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> m ()
- module Data.Prim
Immutable Addr
Immutable read-only address
Instances
withNoHaltPtrAddr :: MonadUnliftPrim s m => Addr e -> (Ptr e -> m b) -> m b Source #
Mutable MAddr
Mutable address
MAddr | |
|
Instances
shrinkMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Count e -> m () Source #
Shrink mutable address to new specified size in number of elements. The new count
must be less than or equal to the current as reported by getCountMAddr
.
shrinkByteCountMAddr :: MonadPrim s m => MAddr e s -> Count Word8 -> m () Source #
Shrink mutable address to new specified size in bytes. The new count must be less
than or equal to the current as reported by getByteCountMAddr
.
copyAddrToMAddr :: (MonadPrim s m, Prim e) => Addr e -> Off e -> MAddr e s -> Off e -> Count e -> m () Source #
moveMAddrToMAddr :: (MonadPrim s m, Prim e) => MAddr e s -> Off e -> MAddr e s -> Off e -> Count e -> m () Source #
modifyMAddr :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> (a, b)) -> m b Source #
Apply a pure function to the contents of a mutable variable. Returns the artifact of computation.
Since: 0.2.0
modifyMAddr_ :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> a) -> m () Source #
Apply a pure function to the contents of a mutable variable.
Since: 0.1.0
modifyFetchOldMAddr :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> a) -> m a Source #
Apply a pure function to the contents of a mutable variable. Returns the old value.
Since: 2.0.0
modifyFetchNewMAddr :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> a) -> m a Source #
Apply a pure function to the contents of a mutable variable. Returns the new value.
Since: 2.0.0
modifyMAddrM :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m (a, b)) -> m b Source #
Apply a monadic action to the contents of a mutable variable. Returns the artifact of computation.
Since: 0.2.0
modifyMAddrM_ :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m a) -> m () Source #
Apply a monadic action to the contents of a mutable variable.
Since: 0.1.0
modifyFetchOldMAddrM :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m a) -> m a Source #
Apply a monadic action to the contents of a mutable variable. Returns the old value.
Since: 2.0.0
modifyFetchNewMAddrM :: (MonadPrim s m, Prim a) => MAddr a s -> (a -> m a) -> m a Source #
Apply a monadic action to the contents of a mutable variable. Returns the new value.
Since: 2.0.0
swapMAddrs_ :: (MonadPrim s m, Prim a) => MAddr a s -> MAddr a s -> m () Source #
Swap contents of two mutable variables.
Since: 0.1.0
swapMAddrs :: (MonadPrim s m, Prim a) => MAddr a s -> MAddr a s -> m (a, a) Source #
Swap contents of two mutable variables. Returns their old values.
Since: 0.1.0
withNoHaltPtrMAddr :: MonadUnliftPrim s m => MAddr e s -> (Ptr e -> m b) -> m b Source #
toForeignPtrAddr :: Addr e -> ForeignPtr e Source #
toForeignPtrMAddr :: MAddr e s -> ForeignPtr e Source #
fromForeignPtrAddr :: ForeignPtr e -> Maybe (Addr e) Source #
This is a unsafe cast therefore modification of ForeignPtr
will be reflected in
resulting immutable Addr
. Pointer created with malloc
cannot be converted to Addr
and will result in Nothing
Since: 0.1.0
fromForeignPtrMAddr :: ForeignPtr e -> Maybe (MAddr e s) Source #
Conversion
ByteString
toByteStringAddr :: Addr Word8 -> ByteString Source #
O(1) - Cast an immutable Addr
to an immutable ByteString
Since: 0.1.0
toShortByteStringAddr :: Addr Word8 -> (ShortByteString, Off Word8) Source #
O(1) - Cast an immutable Addr
to an immutable ShortByteString
Since: 0.1.0
fromShortByteStringAddr :: ShortByteString -> Addr Word8 Source #
O(n) - Convert an immutable ShortByteString
to an immutable Addr
. In a most common
case when ShortByteString
is not backed by pinned memory, this function will return
Nothing
.
Since: 0.1.0
fromByteStringAddr :: ByteString -> (Addr Word8, Count Word8) Source #
O(1) - Cast an immutable ByteString
to Addr
. Also returns the original length of
ByteString, which will be less or equal to countOfAddr
in the produced Addr
.
Since: 0.1.0
fromByteStringMAddr :: ByteString -> (MAddr Word8 s, Count Word8) Source #
O(1) - Cast an immutable ByteString
to a mutable MAddr
. Also returns the
original length of ByteString, which will be less or equal to getCountOfMAddr
in the
produced MAddr
.
Unsafe - Further modification of MAddr
will affect the source ByteString
Since: 0.1.0
Atomic
:: (MonadPrim s m, Atomic e) | |
=> MAddr e s | Array to be mutated |
-> Off e | Index is in elements of |
-> e | Expected old value |
-> e | New value |
-> m e |
Perform atomic modification of an element in the MAddr
at the supplied
index. Returns the artifact of computation b
. Offset is in number of elements,
rather than bytes. Implies a full memory barrier.
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
:: (MonadPrim s m, Atomic e) | |
=> MAddr e s | Array to be mutated |
-> Off e | Index is in elements of |
-> e | Expected old value |
-> e | New value |
-> m (Bool, e) |
Just like casBoolOffMAddr
, but also returns the actual value, which will match the
supplied expected value if the returned flag is True
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
:: (MonadPrim s m, Atomic e) | |
=> MAddr e s | Array to be mutated |
-> Off e | Index is in elements of |
-> m e |
Perform atomic read of an element in the MAddr
at the supplied offset. Offset is in
number of elements, rather than bytes. Implies a full memory barrier.
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
:: (MonadPrim s m, Atomic e) | |
=> MAddr e s | Array to be mutated |
-> Off e | Index is in elements of |
-> e | |
-> m () |
Perform atomic write of an element in the MAddr
at the supplied offset. Offset is in
number of elements, rather than bytes. Implies a full memory barrier.
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
:: (MonadPrim s m, Atomic e) | |
=> MAddr e s | Array to be mutated |
-> Off e | Index is in elements of |
-> (e -> (e, b)) | Function that is applied to the old value and returns new value
and some artifact of computation |
-> m b |
Perform atomic modification of an element in the MAddr
at the supplied
index. Returns the artifact of computation b
. Offset is in number of elements,
rather than bytes. Implies a full memory barrier.
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
atomicModifyOffMAddr_ Source #
:: (MonadPrim s m, Atomic e) | |
=> MAddr e s | Array to be mutated |
-> Off e | Index is in elements of |
-> (e -> e) | Function that is applied to the current value |
-> m () |
Perform atomic modification of an element in the MAddr
at the supplied
index. Offset is in number of elements, rather than bytes. Implies a full memory
barrier.
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
atomicModifyFetchOldOffMAddr Source #
:: (MonadPrim s m, Atomic e) | |
=> MAddr e s | Array to be mutated |
-> Off e | Index is in elements of |
-> (e -> e) | Function that is applied to the old value |
-> m e | Returns the old value |
Perform atomic modification of an element in the MAddr
at the supplied
index. Returns the previous value. Offset is in number of elements, rather than
bytes. Implies a full memory barrier.
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
atomicModifyFetchNewOffMAddr Source #
:: (MonadPrim s m, Atomic e) | |
=> MAddr e s | Array to be mutated |
-> Off e | Index is in elements of |
-> (e -> e) | Function that is applied to the old value |
-> m e | Returns the new value |
Perform atomic modification of an element in the MAddr
at the supplied
index. Offset is in number of elements, rather than bytes. Implies a full memory
barrier.
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
Numeric
atomicAddFetchOldOffMAddr :: (MonadPrim s m, AtomicCount e) => MAddr e s -> Off e -> e -> m e Source #
atomicAddFetchNewOffMAddr :: (MonadPrim s m, AtomicCount e) => MAddr e s -> Off e -> e -> m e Source #
atomicSubFetchOldOffMAddr :: (MonadPrim s m, AtomicCount e) => MAddr e s -> Off e -> e -> m e Source #
atomicSubFetchNewOffMAddr :: (MonadPrim s m, AtomicCount e) => MAddr e s -> Off e -> e -> m e Source #
Binary
atomicAndFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #
Binary conjunction (AND) of an element of a MAddr
with the supplied value,
corresponds to (
done atomically. Returns the previous value. Offset
is in number of elements, rather than bytes. Implies a full memory barrier..&.
)
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
atomicAndFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #
atomicNandFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #
Negation of binary conjunction (NAND) of an element of a MAddr
with the
supplied value, corresponds to \x y ->
done atomically. Returns the previous value. Offset is in number of elements, rather
than bytes. Implies a full memory barrier.complement
(x .&.
y)
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
atomicNandFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #
Negation of binary conjunction (NAND) of an element of a MAddr
with the supplied
value, corresponds to \x y ->
done
atomically. Returns the new value. Offset is in number of elements, rather than
bytes. Implies a full memory barrier.complement
(x .&.
y)
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
atomicOrFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #
atomicOrFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #
atomicXorFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #
Binary exclusive disjunction (XOR) of an element of a MAddr
with the supplied value,
corresponds to
done atomically. Returns the previous value. Offset
is in number of elements, rather than bytes. Implies a full memory barrier.xor
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
atomicXorFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> e -> m e Source #
Binary exclusive disjunction (XOR) of an element of a MAddr
with the supplied value,
corresponds to
done atomically. Returns the new value. Offset is
in number of elements, rather than bytes. Implies a full memory barrier.xor
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
atomicNotFetchOldOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> m e Source #
Binary negation (NOT) of an element of a MAddr
, corresponds to
(
done atomically. Returns the previous value. Offset is in
number of elements, rather than bytes. Implies a full memory barrier.complement
)
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
atomicNotFetchNewOffMAddr :: (MonadPrim s m, AtomicBits e) => MAddr e s -> Off e -> m e Source #
Binary negation (NOT) of an element of a MAddr
, corresponds to
(
done atomically. Returns the new value. Offset is in number
of elements, rather than bytes. Implies a full memory barrier.complement
)
Note - Bounds are not checked, therefore this function is unsafe.
Since: 0.1.0
Prefetch
Directly
prefetchAddr0 :: MonadPrim s m => Addr e -> m () Source #
prefetchMAddr0 :: MonadPrim s m => MAddr e s -> m () Source #
prefetchAddr1 :: MonadPrim s m => Addr e -> m () Source #
prefetchMAddr1 :: MonadPrim s m => MAddr e s -> m () Source #
prefetchAddr2 :: MonadPrim s m => Addr e -> m () Source #
prefetchMAddr2 :: MonadPrim s m => MAddr e s -> m () Source #
prefetchAddr3 :: MonadPrim s m => Addr e -> m () Source #
prefetchMAddr3 :: MonadPrim s m => MAddr e s -> m () Source #
With offset
Re-export
module Data.Prim