-- 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 supports only few operations, -- namely read, write, add, subtract and a few bitwise ones like or, and, -- xor. -- -- Most common use case is having a shared counter that multiple threads -- increment. @package atomic-counter @version 0.1 -- | 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). -- -- 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 Counter module. module Control.Concurrent.Counter.Unlifted -- | Memory location that supports select few atomic operations. data Counter s -- | 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 -- | 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 STRef s Int. 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 () -- | 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 Counter specialized to operate in the IO monad. module Control.Concurrent.Counter.Lifted.IO -- | Memory location that supports select few atomic operations. -- -- Isomorphic to IORef Int. 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 () -- | 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 Counter values in the IO monad. Please -- see other modules in this package for ST monad and for unlifted -- values. module Control.Concurrent.Counter