-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Primitive byte array with type variable
--
-- Primitive byte array with type variable
@package prim-ref
@version 0.1
-- | Note: Edward Kmett wrote everything in this module. It was sitting
-- unpackaged on github, so I took it and published it.
module Data.Primitive.PrimRef
newtype PrimRef s a
PrimRef :: (MutableByteArray s) -> PrimRef s a
-- | Create a primitive reference.
newPrimRef :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a)
-- | Create a pinned primitive reference.
newPinnedPrimRef :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a)
-- | Create a pinned primitive reference with the appropriate alignment for
-- its contents.
newAlignedPinnedPrimRef :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a)
-- | Read a primitive value from the reference
readPrimRef :: (PrimMonad m, Prim a) => PrimRef (PrimState m) a -> m a
-- | Write a primitive value to the reference
writePrimRef :: (PrimMonad m, Prim a) => PrimRef (PrimState m) a -> a -> m ()
-- | Yield a pointer to the data of a PrimRef. This operation is
-- only safe on pinned byte arrays allocated by newPinnedPrimRef
-- or newAlignedPinnedPrimRef.
primRefContents :: PrimRef s a -> Addr
newtype FrozenPrimRef a
FrozenPrimRef :: ByteArray -> FrozenPrimRef a
newFrozenPrimRef :: Prim a => a -> FrozenPrimRef a
-- | Convert a mutable PrimRef to an immutable one without copying.
-- The reference should not be modified after the conversion.
unsafeFreezePrimRef :: PrimMonad m => PrimRef (PrimState m) a -> m (FrozenPrimRef a)
-- | Convert an immutable primitive reference to a mutable one without
-- copying. The original reference should not be used after the
-- conversion.
unsafeThawPrimRef :: PrimMonad m => FrozenPrimRef a -> m (PrimRef (PrimState m) a)
-- | Read the stored primitive value from the frozen reference.
indexFrozenPrimRef :: Prim a => FrozenPrimRef a -> a
-- | 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.
frozenPrimRefContents :: FrozenPrimRef a -> Addr
-- | 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.
casInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> Int -> m Int
-- | 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.
fetchAddInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
-- | 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.
fetchSubInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
-- | 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.
fetchAndInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
-- | 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.
fetchNandInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
-- | 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.
fetchOrInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
-- | 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.
fetchXorInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m Int
-- | Given a reference, read an element. Implies a full memory barrier.
atomicReadInt :: PrimMonad m => PrimRef (PrimState m) Int -> m Int
-- | Given a reference, write an element. Implies a full memory barrier.
atomicWriteInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m ()
instance (Data.Primitive.Types.Prim a, Data.Data.Data a) => Data.Data.Data (Data.Primitive.PrimRef.FrozenPrimRef a)
instance GHC.Classes.Eq (Data.Primitive.PrimRef.PrimRef s a)