Z-Data-0.1.6.1: Array, vector and text

Copyright(c) Dong Han 2017~2019
LicenseBSD-style
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Z.Data.PrimRef.PrimIORef

Contents

Description

This package provide fast unboxed references for 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).

Atomic operations on Counter type are implemented using fetch-and-add primitives, which is much faster than a CAS loop(atomicModifyIORef). Beside basic atomic counter usage, you can also leverage idempotence of and 0, or (-1) to make a concurrent flag.

Synopsis

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

type Counter = PrimIORef Int Source #

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

return value BEFORE atomic operation

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

Atomically add a Counter, return the value BEFORE added.

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

Atomically sub a Counter, return the value BEFORE subbed.

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

Atomically and a Counter, return the value BEFORE anded.

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

Atomically nand a Counter, return the value BEFORE nanded.

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

Atomically or a Counter, return the value BEFORE ored.

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

Atomically xor a Counter, return the value BEFORE xored.

return value AFTER atomic operation

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

Atomically add a Counter, return the value AFTER added.

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.

without returning

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

Atomically add a Counter.

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

Atomically sub a Counter

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

Atomically and a Counter

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

Atomically nand a Counter

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

Atomically or a Counter

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

Atomically xor a Counter