Safe Haskell | None |
---|
This implementation stores an unboxed counter and uses FFI operations to modify its contents.
- type AtomicCounter = ForeignPtr Int
- type CTicket = Int
- newCounter :: IO AtomicCounter
- incrCounter :: AtomicCounter -> IO Int
- readCounterForCAS :: AtomicCounter -> IO CTicket
- peekCTicket :: CTicket -> Int
- readCounter :: AtomicCounter -> IO Int
- writeCounter :: AtomicCounter -> Int -> IO ()
- casCounter :: AtomicCounter -> CTicket -> Int -> IO (Bool, CTicket)
Documentation
type AtomicCounter = ForeignPtr IntSource
newCounter :: IO AtomicCounterSource
Create a new counter initialized to zero.
incrCounter :: AtomicCounter -> IO IntSource
Try repeatedly until we successfully increment the counter. Returns the original value before the increment.
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