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

Safe HaskellNone
LanguageHaskell2010

Data.Atomics.Counter.Reference

Description

This reference version is implemented with atomicModifyIORef and can be a useful fallback if one of the other implementations needs to be debugged for a given architecture.

Synopsis

Documentation

newCounter :: Int -> IO AtomicCounter Source

Create a new counter initialized to the given value.

readCounterForCAS :: AtomicCounter -> IO CTicket Source

Just like the Data.Atomics CAS interface, this routine returns an opaque ticket that can be used in CAS operations.

peekCTicket :: CTicket -> Int Source

Opaque tickets cannot be constructed, but they can be destructed into values.

writeCounter :: AtomicCounter -> Int -> IO () Source

Make a non-atomic write to the counter. No memory-barrier.

casCounter :: AtomicCounter -> CTicket -> Int -> IO (Bool, CTicket) Source

Compare and swap for the counter ADT. Similar behavior to casIORef.

incrCounter :: Int -> AtomicCounter -> IO Int Source

Try repeatedly until we successfully increment the counter by a given amount. Returns the original value of the counter (pre-increment).