transients-0: Transients

Safe HaskellUnsafe
LanguageHaskell2010

Data.Transient.Primitive.PrimRef

Contents

Synopsis

Primitive References

newtype PrimRef s a Source

Constructors

PrimRef (MutableByteArray s) 

Instances

Eq (PrimRef s a) Source 

newPrimRef :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a) Source

Create a primitive reference.

newPinnedPrimRef :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a) Source

Create a pinned primitive reference.

newAlignedPinnedPrimRef :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a) Source

Create a pinned primitive reference with the appropriate alignment for its contents.

readPrimRef :: (PrimMonad m, Prim a) => PrimRef (PrimState m) a -> m a Source

Read a primitive value from the reference

writePrimRef :: (PrimMonad m, Prim a) => PrimRef (PrimState m) a -> a -> m () Source

Write a primitive value to the reference

primRefContents :: PrimRef s a -> Addr Source

Yield a pointer to the data of a PrimRef. This operation is only safe on pinned byte arrays allocated by newPinnedPrimRef or newAlignedPinnedPrimRef.

Frozen Primitive References

newtype FrozenPrimRef a Source

Constructors

FrozenPrimRef ByteArray 

Instances

(Prim a, Data a) => Data (FrozenPrimRef a) Source 

unsafeFreezePrimRef :: PrimMonad m => PrimRef (PrimState m) a -> m (FrozenPrimRef a) Source

Convert a mutable PrimRef to an immutable one without copying. The reference should not be modified after the conversion.

unsafeThawPrimRef :: PrimMonad m => FrozenPrimRef a -> m (PrimRef (PrimState m) a) Source

Convert an immutable primitive reference to a mutable one without copying. The original reference should not be used after the conversion.

indexFrozenPrimRef :: Prim a => FrozenPrimRef a -> a Source

Read the stored primitive value from the frozen reference.

frozenPrimRefContents :: FrozenPrimRef a -> Addr Source

Yield a pointer to the data of a FrozenPrimRef. This operation is only safe on pinned byte arrays allocated by newPinnedPrimRef or newAlignedPinnedPrimRef and then subsequently frozen.

Atomic Operations

casInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> Int -> m Int Source

Given a primitive reference, the expected old value, and the new value, perform an atomic compare and swap i.e. write the new value if the current value matches the provided old value. Returns the value of the element before the operation. Implies a full memory barrier.

fetchAddInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int Source

Given a reference, and a value to add, atomically add the value to the element. Returns the value of the element before the operation. Implies a full memory barrier.

fetchSubInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int Source

Given a reference, and a value to subtract, atomically subtract the value from the element. Returns the value of the element before the operation. Implies a full memory barrier.

fetchAndInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int Source

Given a reference, and a value to bitwise and, atomically and the value with the element. Returns the value of the element before the operation. Implies a full memory barrier.

fetchNandInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int Source

Given a reference, and a value to bitwise nand, atomically nand the value with the element. Returns the value of the element before the operation. Implies a full memory barrier.

fetchOrInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int Source

Given a reference, and a value to bitwise or, atomically or the value with the element. Returns the value of the element before the operation. Implies a full memory barrier.

fetchXorInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int Source

Given a reference, and a value to bitwise xor, atomically xor the value with the element. Returns the value of the element before the operation. Implies a full memory barrier.

atomicReadInt :: PrimMonad m => PrimRef (PrimState m) Int -> m Int Source

Given a reference, read an element. Implies a full memory barrier.

atomicWriteInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m () Source

Given a reference, write an element. Implies a full memory barrier.

Prefetching

prefetchPrimRef0 :: PrimMonad m => PrimRef (PrimState m) a -> m () Source

prefetchPrimRef1 :: PrimMonad m => PrimRef (PrimState m) a -> m () Source

prefetchPrimRef2 :: PrimMonad m => PrimRef (PrimState m) a -> m () Source

prefetchPrimRef3 :: PrimMonad m => PrimRef (PrimState m) a -> m () Source

prefetchFrozenPrimRef0 :: PrimMonad m => FrozenPrimRef a -> m () Source

prefetchFrozenPrimRef1 :: PrimMonad m => FrozenPrimRef a -> m () Source

prefetchFrozenPrimRef2 :: PrimMonad m => FrozenPrimRef a -> m () Source

prefetchFrozenPrimRef3 :: PrimMonad m => FrozenPrimRef a -> m () Source