impure-containers-0.5.1: Mutable containers in Haskell.

Safe HaskellUnsafe
LanguageHaskell2010

ImpureContainers.PrimRef

Contents

Description

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.

Synopsis

PrimRef

data PrimRef s a Source #

FIXME: doc

Instances
Eq (PrimRef s a) Source #

FIXME: doc

Instance details

Defined in ImpureContainers.PrimRef

Methods

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

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

Creation

new Source #

Arguments

:: (PrimMonad m, Prim a) 
=> a

FIXME: doc

-> m (PrimRef (PrimState m) a)

FIXME: doc

Create a primitive reference.

newPinned Source #

Arguments

:: (PrimMonad m, Prim a) 
=> a

FIXME: doc

-> m (PrimRef (PrimState m) a)

FIXME: doc

Create a pinned primitive reference.

newAlignedPinned Source #

Arguments

:: (PrimMonad m, Prim a) 
=> a

FIXME: doc

-> m (PrimRef (PrimState m) a)

FIXME: doc

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

Simple functions

read Source #

Arguments

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

FIXME: doc

-> m a

FIXME: doc

Read a primitive value from the reference

write Source #

Arguments

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

FIXME: doc

-> a

FIXME: doc

-> m ()

FIXME: doc

Write a primitive value to the reference

contents Source #

Arguments

:: PrimRef s a

FIXME: doc

-> Ptr Word8

FIXME: doc

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

atomicReadInt Source #

Arguments

:: PrimMonad m 
=> PrimRef (PrimState m) Int

A primitive reference.

-> m Int

A PrimMonad action that reads the primitive reference and returns its current value as an Int.

Given a reference, read an element.

Implies a full memory barrier.

atomicWriteInt Source #

Arguments

:: PrimMonad m 
=> PrimRef (PrimState m) Int

A primitive reference.

-> Int

The new value the primitive reference should take on.

-> m ()

A PrimMonad action that writes the given Int to the given primitive reference.

Given a reference, write an element.

Implies a full memory barrier.

casInt Source #

Arguments

:: PrimMonad m 
=> PrimRef (PrimState m) Int

A primitive reference.

-> Int

The expected old value.

-> Int

The new value.

-> m Int

A PrimMonad action that atomically writes the new value to the primitive reference if the current value matches the expected old value, and then returns the old value of the primitive reference.

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 Source #

Arguments

:: PrimMonad m 
=> PrimRef (PrimState m) Int

A primitive reference.

-> Int

An Int to add to the current value of the primitive reference.

-> m Int

A PrimMonad action that atomically sets the value of the given primitive reference to the result of adding the given Int to its current value, and then returns the value the primitive reference had before this modification.

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 Source #

Arguments

:: PrimMonad m 
=> PrimRef (PrimState m) Int

A primitive reference.

-> Int

An Int to subtract from the current value of the primitive reference.

-> m Int

A PrimMonad action that atomically sets the value of the given primitive reference to the result of subtracting the given Int from its current value, and then returns the value the primitive reference had before this modification.

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 Source #

Arguments

:: PrimMonad m 
=> PrimRef (PrimState m) Int

A primitive reference.

-> Int

An Int to AND with the current value of the primitive reference.

-> m Int

A PrimMonad action that atomically sets the value of the given primitive reference to the result of bitwise ANDing the given Int with the primitive reference's current value, and then returns the value the primitive reference had before this modification.

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.

fetchNandInt Source #

Arguments

:: PrimMonad m 
=> PrimRef (PrimState m) Int

A primitive reference.

-> Int

An Int to NAND with the current value of the primitive reference.

-> m Int

A PrimMonad action that atomically sets the value of the given primitive reference to the result of bitwise NANDing the given Int with the primitive reference's current value, and then returns the value the primitive reference had before this modification.

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.

fetchOrInt Source #

Arguments

:: PrimMonad m 
=> PrimRef (PrimState m) Int

A primitive reference.

-> Int

An Int to OR with the current value of the primitive reference.

-> m Int

A PrimMonad action that atomically sets the value of the given primitive reference to the result of bitwise ORing the given Int with the primitive reference's current value, and then returns the value the primitive reference had before this modification.

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.

fetchXorInt Source #

Arguments

:: PrimMonad m 
=> PrimRef (PrimState m) Int

A primitive reference.

-> Int

An Int to XOR with the current value of the primitive reference.

-> m Int

A PrimMonad action that atomically sets the value of the given primitive reference to the result of bitwise XORing the given Int with the primitive reference's current value, and then returns the value the primitive reference had before this modification.

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.

Unsafe functions

unsafeToMByteArray Source #

Arguments

:: PrimRef s a

FIXME: doc

-> MByteArray s

FIXME: doc

FIXME: doc

unsafeFromMByteArray Source #

Arguments

:: MByteArray s

FIXME: doc

-> PrimRef s a

FIXME: doc

FIXME: doc