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

Safe HaskellNone
LanguageHaskell2010

Data.IORef.Unboxed

Contents

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

type Counter = IORefU Int Source #

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

atomicAddCounter :: Counter -> Int -> IO Int Source #

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).

atomicSubCounter :: Counter -> Int -> IO Int Source #

Atomically sub a Counter, return the value AFTER subbed.

atomicAndCounter :: Counter -> Int -> IO Int Source #

Atomically and a Counter, return the value AFTER anded.

atomicNandCounter :: Counter -> Int -> IO Int Source #

Atomically nand a Counter, return the value AFTER nanded.

atomicOrCounter :: Counter -> Int -> IO Int Source #

Atomically or a Counter, return the value AFTER ored.

atomicXorCounter :: Counter -> Int -> IO Int Source #

Atomically xor a Counter, return the value AFTER xored.

atomicAddCounter_ :: Counter -> Int -> IO Int Source #

Atomically add a Counter, return the value BEFORE added.

Since: 0.4.0.0

atomicSubCounter_ :: Counter -> Int -> IO Int Source #

Atomically sub a Counter, return the value BEFORE subbed.

Since: 0.4.0.0

atomicAndCounter_ :: Counter -> Int -> IO Int Source #

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

atomicNandCounter_ :: Counter -> Int -> IO Int Source #

Atomically nand a Counter, return the value BEFORE nanded.

Since: 0.4.0.0

atomicOrCounter_ :: Counter -> Int -> IO Int Source #

Atomically or a Counter, return the value BEFORE ored.

Since: 0.4.0.0

atomicXorCounter_ :: Counter -> Int -> IO Int Source #

Atomically xor a Counter, return the value BEFORE xored.

Since: 0.4.0.0