Safe Haskell | Unsafe |
---|---|
Language | Haskell2010 |
Unboxed primitive references.
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.
- data PrimRef s a
- new :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a)
- newPinned :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a)
- newAlignedPinned :: (PrimMonad m, Prim a) => a -> m (PrimRef (PrimState m) a)
- read :: (PrimMonad m, Prim a) => PrimRef (PrimState m) a -> m a
- write :: (PrimMonad m, Prim a) => PrimRef (PrimState m) a -> a -> m ()
- contents :: PrimRef s a -> Addr
- atomicReadInt :: PrimMonad m => PrimRef (PrimState m) Int -> m Int
- atomicWriteInt :: PrimMonad m => PrimRef (PrimState m) Int -> Int -> m ()
- 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
- unsafeToMByteArray :: PrimRef s a -> MByteArray s
- unsafeFromMByteArray :: MByteArray s -> PrimRef s a
PrimRef
Creation
Create a primitive reference.
Create a pinned primitive reference.
Create a pinned primitive reference with the appropriate alignment for its contents.
Simple functions
Read a primitive value from the reference
Write a primitive value to the reference
Yield a pointer to the data of a PrimRef
.
This operation is only safe on pinned byte arrays allocated by
newPinned
or newAlignedPinned
.
Atomic mutators
:: PrimMonad m | |
=> PrimRef (PrimState m) Int | A primitive reference. |
-> m Int | A |
Given a reference, read an element.
Implies a full memory barrier.
:: PrimMonad m | |
=> PrimRef (PrimState m) Int | A primitive reference. |
-> Int | The new value the primitive reference should take on. |
-> m () | A |
Given a reference, write an element.
Implies a full memory barrier.
:: PrimMonad m | |
=> PrimRef (PrimState m) Int | A primitive reference. |
-> Int | The expected old value. |
-> Int | The new value. |
-> m Int | A |
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.
:: PrimMonad m | |
=> PrimRef (PrimState m) Int | A primitive reference. |
-> Int | An |
-> m Int | A |
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.
:: PrimMonad m | |
=> PrimRef (PrimState m) Int | A primitive reference. |
-> Int | An |
-> m Int | A |
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.
:: PrimMonad m | |
=> PrimRef (PrimState m) Int | A primitive reference. |
-> Int | An |
-> m Int | A |
Given a reference and a value with which to bitwise AND, atomically AND the value with the element.
Returns the value of the element before the operation.
Implies a full memory barrier.
:: PrimMonad m | |
=> PrimRef (PrimState m) Int | A primitive reference. |
-> Int | An |
-> m Int | A |
Given a reference and a value with which to bitwise NAND, atomically NAND the value with the element.
Returns the value of the element before the operation.
Implies a full memory barrier.
:: PrimMonad m | |
=> PrimRef (PrimState m) Int | A primitive reference. |
-> Int | An |
-> m Int | A |
Given a reference and a value with which to bitwise OR, atomically OR the value with the element.
Returns the value of the element before the operation.
Implies a full memory barrier.
:: PrimMonad m | |
=> PrimRef (PrimState m) Int | A primitive reference. |
-> Int | An |
-> m Int | A |
Given a reference, and a value with which to bitwise XOR, atomically XOR the value with the element.
Returns the value of the element before the operation.
Implies a full memory barrier.