-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Fast unboxed references for ST and IO monad
--   
--   Fast unboxed references for ST and IO monad
@package unboxed-ref
@version 0.4.0.0

module Data.STRef.Unboxed

-- | A mutable variable in the ST monad which can hold an instance of
--   <a>Prim</a>.
data STRefU s a

-- | Build a new <a>STRefU</a>
newSTRefU :: Prim a => a -> ST s (STRefU s a)

-- | Read the value of an <a>STRefU</a>
readSTRefU :: Prim a => STRefU s a -> ST s a

-- | Write a new value into an <a>STRefU</a>
writeSTRefU :: Prim a => STRefU s a -> a -> ST s ()

-- | Mutate the contents of an <a>STRefU</a>.
--   
--   Unboxed reference is always strict on the value it hold.
modifySTRefU :: Prim a => STRefU s a -> (a -> a) -> ST s ()

module Data.IORef.Unboxed

-- | A mutable variable in the IO monad which can hold an instance of
--   <a>Prim</a>.
data IORefU a

-- | Build a new <a>IORefU</a>
newIORefU :: Prim a => a -> IO (IORefU a)

-- | Read the value of an <a>IORefU</a>
readIORefU :: Prim a => IORefU a -> IO a

-- | Write a new value into an <a>IORefU</a>
writeIORefU :: Prim a => IORefU a -> a -> IO ()

-- | Mutate the contents of an <tt>IORef</tt>.
--   
--   Unboxed reference is always strict on the value it hold.
modifyIORefU :: Prim a => IORefU a -> (a -> a) -> IO ()

-- | Alias for 'IORefU Int' which support several atomic operations.
type Counter = IORefU Int

-- | Build a new <a>Counter</a>
newCounter :: Int -> IO Counter

-- | Atomically add a <a>Counter</a>, return the value AFTER added.
--   
--   It's implemented using fetch-and-add primitive, which is much faster
--   than a CAS loop(<tt>atomicModifyIORef</tt>).
atomicAddCounter :: Counter -> Int -> IO Int

-- | Atomically sub a <a>Counter</a>, return the value AFTER subbed.
atomicSubCounter :: Counter -> Int -> IO Int

-- | Atomically and a <a>Counter</a>, return the value AFTER anded.
atomicAndCounter :: Counter -> Int -> IO Int

-- | Atomically nand a <a>Counter</a>, return the value AFTER nanded.
atomicNandCounter :: Counter -> Int -> IO Int

-- | Atomically or a <a>Counter</a>, return the value AFTER ored.
atomicOrCounter :: Counter -> Int -> IO Int

-- | Atomically xor a <a>Counter</a>, return the value AFTER xored.
atomicXorCounter :: Counter -> Int -> IO Int

-- | Atomically add a <a>Counter</a>, return the value BEFORE added.
atomicAddCounter_ :: Counter -> Int -> IO Int

-- | Atomically sub a <a>Counter</a>, return the value BEFORE subbed.
atomicSubCounter_ :: Counter -> Int -> IO Int

-- | Atomically and a <a>Counter</a>, return the value BEFORE anded.
--   
--   You can leverage idempotence of anding zero to make a concurrent
--   resource lock.
atomicAndCounter_ :: Counter -> Int -> IO Int

-- | Atomically nand a <a>Counter</a>, return the value BEFORE nanded.
atomicNandCounter_ :: Counter -> Int -> IO Int

-- | Atomically or a <a>Counter</a>, return the value BEFORE ored.
atomicOrCounter_ :: Counter -> Int -> IO Int

-- | Atomically xor a <a>Counter</a>, return the value BEFORE xored.
atomicXorCounter_ :: Counter -> Int -> IO Int
