Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
PrimVar
is internally a PrimArray
of one element,
but with a convenient MutVar
-like API.
Synopsis
- newtype PrimVar s a = PrimVar (MutablePrimArray s a)
- newPrimVar :: (Prim a, PrimMonad m) => a -> m (PrimVar (PrimState m) a)
- newPinnedPrimVar :: (Prim a, PrimMonad m) => a -> m (PrimVar (PrimState m) a)
- newAlignedPinnedPrimVar :: (Prim a, PrimMonad m) => a -> m (PrimVar (PrimState m) a)
- readPrimVar :: (Prim a, PrimMonad m) => PrimVar (PrimState m) a -> m a
- writePrimVar :: (Prim a, PrimMonad m) => PrimVar (PrimState m) a -> a -> m ()
- modifyPrimVar :: (Prim a, PrimMonad m) => PrimVar (PrimState m) a -> (a -> a) -> m ()
- samePrimVar :: PrimVar s a -> PrimVar s a -> Bool
- primVarContents :: PrimVar s a -> Ptr a
- isPrimVarPinned :: PrimVar s a -> Bool
Types
PrimVar (MutablePrimArray s a) |
Allocation
newPrimVar :: (Prim a, PrimMonad m) => a -> m (PrimVar (PrimState m) a) Source #
Create a new PrimVar
with the specified initial value.
newPinnedPrimVar :: (Prim a, PrimMonad m) => a -> m (PrimVar (PrimState m) a) Source #
Create a new pinned PrimVar
with the specified initial value.
The garbage collector is guaranteed not to move it.
newAlignedPinnedPrimVar :: (Prim a, PrimMonad m) => a -> m (PrimVar (PrimState m) a) Source #
Create a new pinned PrimVar
with the specified initial value
and with the alignment given by its Prim instance.
The garbage collector is guaranteed not to move it.
Access
readPrimVar :: (Prim a, PrimMonad m) => PrimVar (PrimState m) a -> m a Source #
Read the value of a PrimVar
.
writePrimVar :: (Prim a, PrimMonad m) => PrimVar (PrimState m) a -> a -> m () Source #
Write a new value into a PrimVar
.
modifyPrimVar :: (Prim a, PrimMonad m) => PrimVar (PrimState m) a -> (a -> a) -> m () Source #
Mutate the contents of a PrimVar
.
Information
samePrimVar :: PrimVar s a -> PrimVar s a -> Bool Source #
Check if two PrimVar
s refer to the same memory block.
primVarContents :: PrimVar s a -> Ptr a Source #
Yield a pointer to a PrimVar
's data.
This operation is only safe on pinned PrimVar
s
allocated by newPinnedPrimVar
or newAlignedPinnedPrimVar
.