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


-- | Mutable counters that can be modified with atomic operatinos
--   
--   This package defines Counter type that can be safely modified
--   concurrently from multiple threads. The type supports only few
--   operations, namely read, write, cas (compare and swap), add, subtract
--   and a few bitwise ones like or, and xor.
--   
--   Most common use case is having a shared counter that multiple threads
--   increment. Another potential use case is lightweight locks.
@package atomic-counter
@version 0.1.2.4


-- | Counters that support some atomic operations. Safe to use from
--   multiple threads and likely faster than using <a>IORef</a> or
--   <a>TVar</a> for the same operation (terms and conditions apply).
--   
--   This module defines unlifted newtype wrapper and corresponding
--   operations, they're not suitable for use with e.g. monads or being
--   stored in other data structures that expect lifted types. For general
--   use start with <a>Counter</a> module.
module Control.Concurrent.Counter.Unlifted

-- | Memory location that supports select few atomic operations.
data Counter s :: UnliftedType

-- | Create new counter with initial value.
new :: Int# -> State# s -> (# State# s, Counter s #)

-- | Atomically read the counter's value.
get :: Counter s -> State# s -> (# State# s, Int# #)

-- | Atomically assign new value to the counter.
set :: Counter s -> Int# -> State# s -> (# State# s #)

-- | Atomic compare and swap, i.e. write the new value if the current value
--   matches the provided old value. Returns the value of the element
--   before the operation
cas :: Counter s -> Int# -> Int# -> State# s -> (# State# s, Int# #)

-- | Atomically add an amount to the counter and return its old value.
add :: Counter s -> Int# -> State# s -> (# State# s, Int# #)

-- | Atomically subtract an amount from the counter and return its old
--   value.
sub :: Counter s -> Int# -> State# s -> (# State# s, Int# #)

-- | Atomically combine old value with a new one via bitwise and. Returns
--   old counter value.
and :: Counter s -> Int# -> State# s -> (# State# s, Int# #)

-- | Atomically combine old value with a new one via bitwise or. Returns
--   old counter value.
or :: Counter s -> Int# -> State# s -> (# State# s, Int# #)

-- | Atomically combine old value with a new one via bitwise xor. Returns
--   old counter value.
xor :: Counter s -> Int# -> State# s -> (# State# s, Int# #)

-- | Atomically combine old value with a new one via bitwise nand. Returns
--   old counter value.
nand :: Counter s -> Int# -> State# s -> (# State# s, Int# #)

-- | Compare the underlying pointers of two counters.
sameCounter :: Counter s -> Counter s -> Bool


-- | Counters that support some atomic operations. Safe to use from
--   multiple threads and likely faster than using IORef or TVar for the
--   same operation (terms and conditions apply).
module Control.Concurrent.Counter.Lifted.ST

-- | Memory location that supports select few atomic operations.
--   
--   Isomorphic to <tt>STRef s Int</tt>.
data Counter s

-- | Create new counter with initial value.
new :: Int -> ST s (Counter s)

-- | Atomically read the counter's value.
get :: Counter s -> ST s Int

-- | Atomically assign new value to the counter.
set :: Counter s -> Int -> ST s ()

-- | Atomic compare and swap, i.e. write the new value if the current value
--   matches the provided old value. Returns the value of the element
--   before the operation
cas :: Counter s -> Int -> Int -> ST s Int

-- | Atomically add an amount to the counter and return its old value.
add :: Counter s -> Int -> ST s Int

-- | Atomically subtract an amount from the counter and return its old
--   value.
sub :: Counter s -> Int -> ST s Int

-- | Atomically combine old value with a new one via bitwise and. Returns
--   old counter value.
and :: Counter s -> Int -> ST s Int

-- | Atomically combine old value with a new one via bitwise or. Returns
--   old counter value.
or :: Counter s -> Int -> ST s Int

-- | Atomically combine old value with a new one via bitwise xor. Returns
--   old counter value.
xor :: Counter s -> Int -> ST s Int

-- | Atomically combine old value with a new one via bitwise nand. Returns
--   old counter value.
nand :: Counter s -> Int -> ST s Int
instance GHC.Classes.Eq (Control.Concurrent.Counter.Lifted.ST.Counter s)


-- | Lifted <a>Counter</a> specialized to operate in the <a>IO</a> monad.
module Control.Concurrent.Counter.Lifted.IO

-- | Memory location that supports select few atomic operations.
--   
--   Isomorphic to <tt>IORef Int</tt>.
data Counter

-- | Create new counter with initial value.
new :: Int -> IO Counter

-- | Atomically read the counter's value.
get :: Counter -> IO Int

-- | Atomically assign new value to the counter.
set :: Counter -> Int -> IO ()

-- | Atomic compare and swap, i.e. write the new value if the current value
--   matches the provided old value. Returns the value of the element
--   before the operation
cas :: Counter -> Int -> Int -> IO Int

-- | Atomically add an amount to the counter and return its old value.
add :: Counter -> Int -> IO Int

-- | Atomically subtract an amount from the counter and return its old
--   value.
sub :: Counter -> Int -> IO Int

-- | Atomically combine old value with a new one via bitwise and. Returns
--   old counter value.
and :: Counter -> Int -> IO Int

-- | Atomically combine old value with a new one via bitwise or. Returns
--   old counter value.
or :: Counter -> Int -> IO Int

-- | Atomically combine old value with a new one via bitwise xor. Returns
--   old counter value.
xor :: Counter -> Int -> IO Int

-- | Atomically combine old value with a new one via bitwise nand. Returns
--   old counter value.
nand :: Counter -> Int -> IO Int
instance GHC.Classes.Eq Control.Concurrent.Counter.Lifted.IO.Counter


-- | Work with lifted <a>Counter</a> values in the <a>IO</a> monad. Please
--   see other modules in this package for <a>ST</a> monad and for unlifted
--   values.
module Control.Concurrent.Counter

-- | Memory location that supports select few atomic operations.
--   
--   Isomorphic to <tt>IORef Int</tt>.
data Counter

-- | Create new counter with initial value.
new :: Int -> IO Counter

-- | Atomically read the counter's value.
get :: Counter -> IO Int

-- | Atomically assign new value to the counter.
set :: Counter -> Int -> IO ()

-- | Atomic compare and swap, i.e. write the new value if the current value
--   matches the provided old value. Returns the value of the element
--   before the operation
cas :: Counter -> Int -> Int -> IO Int

-- | Atomically add an amount to the counter and return its old value.
add :: Counter -> Int -> IO Int

-- | Atomically subtract an amount from the counter and return its old
--   value.
sub :: Counter -> Int -> IO Int

-- | Atomically combine old value with a new one via bitwise and. Returns
--   old counter value.
and :: Counter -> Int -> IO Int

-- | Atomically combine old value with a new one via bitwise or. Returns
--   old counter value.
or :: Counter -> Int -> IO Int

-- | Atomically combine old value with a new one via bitwise xor. Returns
--   old counter value.
xor :: Counter -> Int -> IO Int

-- | Atomically combine old value with a new one via bitwise nand. Returns
--   old counter value.
nand :: Counter -> Int -> IO Int
