prim-array-0.2.1: Primitive byte array with type variable

Safe HaskellUnsafe
LanguageHaskell2010

Data.Primitive.PrimRef

Contents

Description

Note: Edward Kmett wrote everything in this module. It was sitting unpackaged on github, so I took it and published it as a part of this package.

Synopsis

Primitive References

newtype PrimRef s a Source #

Constructors

PrimRef (MutableByteArray s) 

Instances

Eq (PrimRef s a) Source # 

Methods

(==) :: PrimRef s a -> PrimRef s a -> Bool #

(/=) :: PrimRef s a -> PrimRef s a -> Bool #

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 # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> FrozenPrimRef a -> c (FrozenPrimRef a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (FrozenPrimRef a) #

toConstr :: FrozenPrimRef a -> Constr #

dataTypeOf :: FrozenPrimRef a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (FrozenPrimRef a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (FrozenPrimRef a)) #

gmapT :: (forall b. Data b => b -> b) -> FrozenPrimRef a -> FrozenPrimRef a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FrozenPrimRef a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FrozenPrimRef a -> r #

gmapQ :: (forall d. Data d => d -> u) -> FrozenPrimRef a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> FrozenPrimRef a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> FrozenPrimRef a -> m (FrozenPrimRef a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> FrozenPrimRef a -> m (FrozenPrimRef a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> FrozenPrimRef a -> m (FrozenPrimRef a) #

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.