Safe Haskell | None |
---|
This reference version is implemented with atomicModifyIORef and can be a useful fallback if one of the other implementations needs to be debugged.
- newtype AtomicCounter = AtomicCounter (IORef Int)
- type CTicket = Int
- newCounter :: IO AtomicCounter
- readCounterForCAS :: AtomicCounter -> IO CTicket
- peekCTicket :: CTicket -> Int
- readCounter :: AtomicCounter -> IO Int
- writeCounter :: AtomicCounter -> Int -> IO ()
- casCounter :: AtomicCounter -> CTicket -> Int -> IO (Bool, CTicket)
Documentation
newtype AtomicCounter Source
newCounter :: IO AtomicCounterSource
Create a new counter initialized to zero.
readCounterForCAS :: AtomicCounter -> IO CTicketSource
Try repeatedly until we successfully increment the counter. incrCounter =
peekCTicket :: CTicket -> IntSource
readCounter :: AtomicCounter -> IO IntSource
writeCounter :: AtomicCounter -> Int -> IO ()Source
Make a non-atomic write to the counter. No memory-barrier.
casCounter :: AtomicCounter -> CTicket -> Int -> IO (Bool, CTicket)Source