Safe Haskell | Unsafe |
---|---|
Language | Haskell2010 |
Data.Primitive.PrimRef
Description
Note: Edward Kmett wrote everything in this module. It was sitting unpackaged on github, so I took it and published it.
- newtype PrimRef s a = PrimRef (MutableByteArray s)
- newPrimRef :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a)
- newPinnedPrimRef :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a)
- newAlignedPinnedPrimRef :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a)
- readPrimRef :: (PrimMonad m, Prim a) => PrimRef (PrimState m) a -> m a
- writePrimRef :: (PrimMonad m, Prim a) => PrimRef (PrimState m) a -> a -> m ()
- primRefContents :: PrimRef s a -> Addr
- newtype FrozenPrimRef a = FrozenPrimRef ByteArray
- newFrozenPrimRef :: Prim a => a -> FrozenPrimRef a
- unsafeFreezePrimRef :: PrimMonad m => PrimRef (PrimState m) a -> m (FrozenPrimRef a)
- unsafeThawPrimRef :: PrimMonad m => FrozenPrimRef a -> m (PrimRef (PrimState m) a)
- indexFrozenPrimRef :: Prim a => FrozenPrimRef a -> a
- frozenPrimRefContents :: FrozenPrimRef a -> Addr
- casInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> Int -> m Int
- fetchAddInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
- fetchSubInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
- fetchAndInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
- fetchNandInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
- fetchOrInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
- fetchXorInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
- atomicReadInt :: PrimMonad m => PrimRef (PrimState m) Int -> m Int
- atomicWriteInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m ()
Primitive References
Constructors
PrimRef (MutableByteArray s) |
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 |
newFrozenPrimRef :: Prim a => a -> 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.