Copyright | (c) Dong Han 2017~2019 |
---|---|
License | BSD-style |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
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
- data PrimSTRef s a
- newPrimSTRef :: Prim a => a -> ST s (PrimSTRef s a)
- readPrimSTRef :: Prim a => PrimSTRef s a -> ST s a
- writePrimSTRef :: Prim a => PrimSTRef s a -> a -> ST s ()
- modifyPrimSTRef :: Prim a => PrimSTRef s a -> (a -> a) -> ST s ()
- data PrimIORef a
- newPrimIORef :: Prim a => a -> IO (PrimIORef a)
- readPrimIORef :: Prim a => PrimIORef a -> IO a
- writePrimIORef :: Prim a => PrimIORef a -> a -> IO ()
- modifyPrimIORef :: Prim a => PrimIORef a -> (a -> a) -> IO ()
- type Counter = PrimIORef Int
- newCounter :: Int -> IO Counter
- atomicAddCounter :: Counter -> Int -> IO Int
- atomicSubCounter :: Counter -> Int -> IO Int
- atomicAndCounter :: Counter -> Int -> IO Int
- atomicNandCounter :: Counter -> Int -> IO Int
- atomicOrCounter :: Counter -> Int -> IO Int
- atomicXorCounter :: Counter -> Int -> IO Int
- atomicAddCounter' :: Counter -> Int -> IO Int
- atomicSubCounter' :: Counter -> Int -> IO Int
- atomicAndCounter' :: Counter -> Int -> IO Int
- atomicNandCounter' :: Counter -> Int -> IO Int
- atomicOrCounter' :: Counter -> Int -> IO Int
- atomicXorCounter' :: Counter -> Int -> IO Int
- atomicAddCounter_ :: Counter -> Int -> IO ()
- atomicSubCounter_ :: Counter -> Int -> IO ()
- atomicAndCounter_ :: Counter -> Int -> IO ()
- atomicNandCounter_ :: Counter -> Int -> IO ()
- atomicOrCounter_ :: Counter -> Int -> IO ()
- atomicXorCounter_ :: Counter -> Int -> IO ()
Unboxed ST references
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
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.