Z-Data-0.1.6.0: Array, vector and text

Z.Data.PrimRef

Description

This module provide fast unboxed references for ST and IO monad, and atomic operations for Counter type. Unboxed reference is implemented using single cell MutableByteArray s to eliminate indirection overhead which MutVar# s a carry, on the otherhand unboxed reference only support limited type(instances of Prim class).

Synopsis

# Unboxed ST references

data PrimSTRef s a Source #

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

newPrimSTRef :: Prim a => a -> ST s (PrimSTRef s a) Source #

Build a new PrimSTRef

readPrimSTRef :: Prim a => PrimSTRef s a -> ST s a Source #

Read the value of an PrimSTRef

writePrimSTRef :: Prim a => PrimSTRef s a -> a -> ST s () Source #

Write a new value into an PrimSTRef

modifyPrimSTRef :: Prim a => PrimSTRef s a -> (a -> a) -> ST s () Source #

Mutate the contents of an PrimSTRef.

Unboxed reference is always strict on the value it hold.

# Unboxed IO references

data PrimIORef a Source #

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

newPrimIORef :: Prim a => a -> IO (PrimIORef a) Source #

Build a new PrimIORef

readPrimIORef :: Prim a => PrimIORef a -> IO a Source #

Read the value of an PrimIORef

writePrimIORef :: Prim a => PrimIORef a -> a -> IO () Source #

Write a new value into an PrimIORef

modifyPrimIORef :: Prim a => PrimIORef a -> (a -> a) -> IO () Source #

Mutate the contents of an IORef.

Unboxed reference is always strict on the value it hold.

# Atomic operations for PrimIORef Int

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

Build a new Counter

## return value BEFORE atomic operation

Atomically add a Counter, return the value BEFORE added.

Atomically sub a Counter, return the value BEFORE subbed.

Atomically and a Counter, return the value BEFORE anded.

Atomically nand a Counter, return the value BEFORE nanded.

Atomically or a Counter, return the value BEFORE ored.

Atomically xor a Counter, return the value BEFORE xored.

## return value AFTER atomic operation

Atomically add a Counter, return the value AFTER added.

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.

## without returning

Atomically add a Counter.

Atomically sub a Counter

Atomically and a Counter

Atomically nand a Counter

Atomically or a Counter

Atomically xor a Counter