planet-mitchell-0.1.0: Planet Mitchell

Safe HaskellNone





data AtomicCounter #

The type of mutable atomic counters.

newCounter :: Int -> IO AtomicCounter #

Create a new counter initialized to the given value.

incrCounter :: Int -> AtomicCounter -> IO Int #

Increment the counter by a given amount. Returns the value AFTER the increment (in contrast with the behavior of the underlying instruction on architectures like x86.)

Note that UNLIKE with boxed implementations of counters, where increment is based on CAS, this increment is O(1). Fetch-and-add does not require a retry loop like CAS.

incrCounter_ :: Int -> AtomicCounter -> IO () #

An alternate version for when you don't care about the old value.

readCounter :: AtomicCounter -> IO Int #

Equivalent to readCounterForCAS followed by peekCTicket.

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

Compare and swap for the counter ADT. Similar behavior to casIORef, in particular, in both success and failure cases it returns a ticket that you should use for the next attempt. (That is, in the success case, it actually returns the new value that you provided as input, but in ticket form.)