Data.Atomics.Internal

atomic-primops-0.8.8: A safe approach to CAS and other atomic ops in Haskell.

Safe Haskell | None
Language | Haskell2010

Data.Atomics.Internal

Contents

- Very unsafe, not to be used

Description

This module provides only the raw primops (and necessary types) for atomic operations.

Synopsis

- casIntArray# :: MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> (# State# d, Int# #)
- fetchAddIntArray# :: MutableByteArray# d -> Int# -> Int# -> State# d -> (# State# d, Int# #)
- readForCAS# :: MutVar# RealWorld a -> State# RealWorld -> (# State# RealWorld, Ticket a #)
- casMutVarTicketed# :: MutVar# RealWorld a -> Ticket a -> Ticket a -> State# RealWorld -> (# State# RealWorld, Int#, Ticket a #)
- casArrayTicketed# :: MutableArray# RealWorld a -> Int# -> Ticket a -> Ticket a -> State# RealWorld -> (# State# RealWorld, Int#, Ticket a #)
- data Ticket a
- ptrEq :: a -> a -> Bool

# Documentation

casIntArray# :: MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> (# State# d, Int# #) #

Given an array, an offset in machine words, 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.

Warning: this can fail with an unchecked exception.

fetchAddIntArray# :: MutableByteArray# d -> Int# -> Int# -> State# d -> (# State# d, Int# #) #

Given an array, and offset in machine words, 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.

Warning: this can fail with an unchecked exception.

readForCAS# :: MutVar# RealWorld a -> State# RealWorld -> (# State# RealWorld, Ticket a #) #

casMutVarTicketed# :: MutVar# RealWorld a -> Ticket a -> Ticket a -> State# RealWorld -> (# State# RealWorld, Int#, Ticket a #) #

casArrayTicketed# :: MutableArray# RealWorld a -> Int# -> Ticket a -> Ticket a -> State# RealWorld -> (# State# RealWorld, Int#, Ticket a #) #

Unsafe, machine-level atomic compare and swap on an element within an Array.

data Ticket a #

When performing compare-and-swaps, the ticket encapsulates proof that a thread observed a specific previous value of a mutable variable. It is provided in lieu of the "old" value to compare-and-swap.

Design note: `Ticket`s exist to hide objects from the GHC compiler, which can normally perform many optimizations that change pointer equality. A Ticket, on the other hand, is a first-class object that can be handled by the user, but will not have its pointer identity changed by compiler optimizations (but will of course, change addresses during garbage collection).

#### Instances

Instances details

Show (Ticket a) # |
Instance details Defined in Data.Atomics.Internal Methods showsPrec :: Int -> Ticket a -> ShowS # show :: Ticket a -> String # showList :: [Ticket a] -> ShowS #
Eq (Ticket a) # |
Instance details Defined in Data.Atomics.Internal Methods (==) :: Ticket a -> Ticket a -> Bool # (/=) :: Ticket a -> Ticket a -> Bool #

# Very unsafe, not to be used

ptrEq :: a -> a -> Bool #