primitive-unlifted-2.1.0.0: Primitive GHC types with unlifted types inside
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Primitive.Unlifted.MutVar.Primops

Synopsis

Documentation

data UnliftedMutVar# s (a :: UnliftedType) Source #

An UnliftedMutVar# behaves like a single-element mutable array.

sameUnliftedMutVar# :: UnliftedMutVar# s a -> UnliftedMutVar# s a -> Int# Source #

Check whether two UnliftedMutVar#es refer to the same mutable variable. This is a check on object identity, and not on contents.

casUnliftedMutVar# Source #

Arguments

:: UnliftedMutVar# s a

The UnliftedMutVar# on which to operate

-> a

The expected value

-> a

The new value to install if the 'UnliftedMutVar# contains the expected value

-> State# s 
-> (# State# s, Int#, a #) 

Performs a machine-level compare and swap (CAS) operation on an UnliftedMutVar#. Returns a tuple containing an Int# which is '1#' when a swap is performed, along with the most "current" value from the UnliftedMutVar#. This return value can be used as the expected value if a CAS loop is required, though it may be better to get a fresh read. Note that this behavior differs from the more common CAS behavior, which is to return the old value before the CAS occured.

atomicSwapUnliftedMutVar# :: UnliftedMutVar# s a -> a -> State# s -> (# State# s, a #) Source #

Atomically replace the value in an UnliftedMutVar# with the given one, returning the old value.

Implementation note: this really should be a GHC primop, because it is supported very efficiently in hardware, but unfortunately it's not (yet), so we implement it as a CAS loop.