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.
- data AtomicCounter
- type CTicket = Int
- newCounter :: Int -> IO AtomicCounter
- readCounterForCAS :: AtomicCounter -> IO CTicket
- readCounter :: AtomicCounter -> IO Int
- peekCTicket :: CTicket -> Int
- writeCounter :: AtomicCounter -> Int -> IO ()
- casCounter :: AtomicCounter -> CTicket -> Int -> IO (Bool, CTicket)
- incrCounter :: Int -> AtomicCounter -> IO Int
- incrCounter_ :: Int -> AtomicCounter -> IO ()
Just like the Data.Atomics CAS interface, this routine returns an opaque ticket that can be used in CAS operations.
Opaque tickets cannot be constructed, but they can be destructed into values.
Make a non-atomic write to the counter. No memory-barrier.
Compare and swap for the counter ADT. Similar behavior to
Try repeatedly until we successfully increment the counter by a given amount. Returns the original value of the counter (pre-increment).