-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Wrappers for primops around atomic operations
--
-- Wrappers for primops around atomic operations
@package primitive-atomic
@version 0.1.0.2
module Data.Primitive.Array.Atomic
-- | Given an array, an offset in Int units, the expected old value, and
-- the new value, perform an 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. Implies a full memory
-- barrier.
--
-- Note that lifted values in GHC have limited guarantees concerning
-- pointer equality. In particular, data constructor applications of
-- single-constructor data types may be mangled by GHC Core
-- optimizations. Users of this function are expected to understand how
-- to make pointer equality survive GHC's optimization passes.
casArray :: PrimMonad m => MutableArray (PrimState m) a -> Int -> a -> a -> m (Bool, a)
module Data.Primitive.Class.Atomic
-- | Class of types supporting primitive operations that are isomorphic to
-- a machine integer. Such types support compare-and-swap and other
-- atomic operations.
class Prim a => PrimMach a
primMachToInt# :: PrimMach a => a -> Int#
primMachFromInt# :: PrimMach a => Int# -> a
instance Data.Primitive.Class.Atomic.PrimMach GHC.Types.Int
instance Data.Primitive.Class.Atomic.PrimMach GHC.Types.Word
module Data.Primitive.ByteArray.Atomic
-- | Given an array, an offset in Int units, the expected old value, and
-- the new value, perform an 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. Implies a full memory
-- barrier.
casByteArray :: (PrimMonad m, PrimMach a) => MutableByteArray (PrimState m) -> Int -> a -> a -> m a
-- | Given an array, and offset in Int units, and a value to add,
-- atomically add the value to the element. Returns the value of the
-- element before the operation. Implies a full memory barrier.
fetchAddByteArray :: (PrimMonad m, PrimMach a) => MutableByteArray (PrimState m) -> Int -> a -> m a
-- | Given an array, and offset in Int units, and a value to subtract,
-- atomically subtract the value to the element. Returns the value of the
-- element before the operation. Implies a full memory barrier.
fetchSubByteArray :: (PrimMonad m, PrimMach a) => MutableByteArray (PrimState m) -> Int -> a -> m a
-- | Given an array, and offset in Int units, and a value to AND,
-- atomically AND the value to the element. Returns the value of
-- the element before the operation. Implies a full memory barrier.
fetchAndByteArray :: (PrimMonad m, PrimMach a) => MutableByteArray (PrimState m) -> Int -> a -> m a
-- | Given an array, and offset in Int units, and a value to NAND,
-- atomically NAND the value to the element. Returns the value
-- of the element before the operation. Implies a full memory barrier.
fetchNandByteArray :: (PrimMonad m, PrimMach a) => MutableByteArray (PrimState m) -> Int -> a -> m a
-- | Given an array, and offset in Int units, and a value to OR,
-- atomically OR the value to the element. Returns the value of
-- the element before the operation. Implies a full memory barrier.
fetchOrByteArray :: (PrimMonad m, PrimMach a) => MutableByteArray (PrimState m) -> Int -> a -> m a
-- | Given an array, and offset in Int units, and a value to XOR,
-- atomically XOR the value to the element. Returns the value of
-- the element before the operation. Implies a full memory barrier.
fetchXorByteArray :: (PrimMonad m, PrimMach a) => MutableByteArray (PrimState m) -> Int -> a -> m a
module Data.Primitive.PrimArray.Atomic
-- | Given an array, an offset in Int units, the expected old value, and
-- the new value, perform an 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. Implies a full memory
-- barrier.
casPrimArray :: (PrimMonad m, PrimMach a) => MutablePrimArray (PrimState m) a -> Int -> a -> a -> m a
-- | Given an array, and offset in Int units, and a value to add,
-- atomically add the value to the element. Returns the value of the
-- element before the operation. Implies a full memory barrier.
fetchAddPrimArray :: (PrimMonad m, PrimMach a) => MutablePrimArray (PrimState m) a -> Int -> a -> m a
-- | Given an array, and offset in Int units, and a value to subtract,
-- atomically subtract the value to the element. Returns the value of the
-- element before the operation. Implies a full memory barrier.
fetchSubPrimArray :: (PrimMonad m, PrimMach a) => MutablePrimArray (PrimState m) a -> Int -> a -> m a
-- | Given an array, and offset in Int units, and a value to AND,
-- atomically AND the value to the element. Returns the value of
-- the element before the operation. Implies a full memory barrier.
fetchAndPrimArray :: (PrimMonad m, PrimMach a) => MutablePrimArray (PrimState m) a -> Int -> a -> m a
-- | Given an array, and offset in Int units, and a value to NAND,
-- atomically NAND the value to the element. Returns the value
-- of the element before the operation. Implies a full memory barrier.
fetchNandPrimArray :: (PrimMonad m, PrimMach a) => MutablePrimArray (PrimState m) a -> Int -> a -> m a
-- | Given an array, and offset in Int units, and a value to OR,
-- atomically OR the value to the element. Returns the value of
-- the element before the operation. Implies a full memory barrier.
fetchOrPrimArray :: (PrimMonad m, PrimMach a) => MutablePrimArray (PrimState m) a -> Int -> a -> m a
-- | Given an array, and offset in Int units, and a value to XOR,
-- atomically XOR the value to the element. Returns the value of
-- the element before the operation. Implies a full memory barrier.
fetchXorPrimArray :: (PrimMonad m, PrimMach a) => MutablePrimArray (PrimState m) a -> Int -> a -> m a
module Data.Primitive.Unlifted.Atomic
-- | Given an array, an offset, the expected old value, and the new value,
-- perform an 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. Implies a full memory barrier.
--
-- Some unlifted types, in particular the ones that correspond to mutable
-- resources, have good guarantees about pointer equality. With these
-- types, this function is much easier to reason about than
-- casArray.
casUnliftedArray :: forall m a. (PrimMonad m, PrimUnlifted a) => MutableUnliftedArray (PrimState m) a -> Int -> a -> a -> m (Bool, a)