primitive-primvar-0.0.0.0: Unboxed variables for `Prim` values.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Primitive.PrimVar

Description

PrimVar is internally a PrimArray of one element, but with a convenient MutVar-like API.

Synopsis

Types

newtype PrimVar s a Source #

Constructors

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 PrimVars 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 PrimVars allocated by newPinnedPrimVar or newAlignedPinnedPrimVar.

isPrimVarPinned :: PrimVar s a -> Bool Source #

Check whether or not a PrimVar is pinned.