unboxed-ref-0.4.0.0: Fast unboxed references for ST and IO monad

Data.IORef.Unboxed

Synopsis

# Unboxed IO references

data IORefU a Source #

A mutable variable in the IO monad which can hold an instance of Prim.

newIORefU :: Prim a => a -> IO (IORefU a) Source #

Build a new IORefU

readIORefU :: Prim a => IORefU a -> IO a Source #

Read the value of an IORefU

writeIORefU :: Prim a => IORefU a -> a -> IO () Source #

Write a new value into an IORefU

modifyIORefU :: Prim a => IORefU a -> (a -> a) -> IO () Source #

Mutate the contents of an IORef.

Unboxed reference is always strict on the value it hold.

# Atomic operations for IORefU Int

Alias for 'IORefU Int' which support several atomic operations.

Build a new Counter

Atomically add a Counter, return the value AFTER added.

It's implemented using fetch-and-add primitive, which is much faster than a CAS loop(atomicModifyIORef).

Atomically sub a Counter, return the value AFTER subbed.

Atomically and a Counter, return the value AFTER anded.

Atomically nand a Counter, return the value AFTER nanded.

Atomically or a Counter, return the value AFTER ored.

Atomically xor a Counter, return the value AFTER xored.

Atomically add a Counter, return the value BEFORE added.

Since: 0.4.0.0

Atomically sub a Counter, return the value BEFORE subbed.

Since: 0.4.0.0

Atomically and a Counter, return the value BEFORE anded.

You can leverage idempotence of anding zero to make a concurrent resource lock.

Since: 0.4.0.0

Atomically nand a Counter, return the value BEFORE nanded.

Since: 0.4.0.0

Atomically or a Counter, return the value BEFORE ored.

Since: 0.4.0.0

Atomically xor a Counter, return the value BEFORE xored.

Since: 0.4.0.0