License | BSD3 |
---|---|

Maintainer | Julian Sutherland (julian.sutherland10@imperial.ac.uk) |

Safe Haskell | None |

Language | Haskell98 |

An implementation of a lock-free spin counter. Works with any monad that has atomically modificable references.

- data SpinCounter r
- type SpinCounterIO = SpinCounter IORef
- type SpinCounterSTM = SpinCounter TVar
- newSpinCounter :: (MonadAtomicRef r m, Integral a) => a -> m (SpinCounter r)
- incSpinCounter :: MonadAtomicRef r m => SpinCounter r -> m ()
- readSpinCounter :: (MonadAtomicRef r m, Num a) => SpinCounter r -> m a

# Documentation

data SpinCounter r Source

A lock-free concurrent Spin counter usable in any monad, m, that is paired with a reference type, r, by an instance of `MonadAtomicRef`

. Can use Specializations `SpinCounterIO`

and `SpinCounterSTM`

type SpinCounterIO = SpinCounter IORef Source

SpinCounter inside the IO Monad.

type SpinCounterSTM = SpinCounter TVar Source

SpinCounter inside the STM Monad.

newSpinCounter :: (MonadAtomicRef r m, Integral a) => a -> m (SpinCounter r) Source

Creates a new instance of the `SpinCounter`

data type initialized to value of the input to the function, an instance of the class `Integral`

.

incSpinCounter :: MonadAtomicRef r m => SpinCounter r -> m () Source

Increments an instance of the `SpinCounter`

data type by one in a lock-free manner.

readSpinCounter :: (MonadAtomicRef r m, Num a) => SpinCounter r -> m a Source

Reads the value of an instance of the `SpinCounter`

data type in a lock-free manner.