Atomic bit operations, using GCC's built-in atomic operations in small C wrapper functions called through the FFI. See http://gcc.gnu.org/wiki/Atomic and http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html for more detail.
- class Bits x => AtomicBits x where
- fetchAndAdd :: Ptr x -> x -> IO x
- fetchAndSub :: Ptr x -> x -> IO x
- fetchAndOr :: Ptr x -> x -> IO x
- fetchAndAnd :: Ptr x -> x -> IO x
- fetchAndXor :: Ptr x -> x -> IO x
- fetchAndNand :: Ptr x -> x -> IO x
- addAndFetch :: Ptr x -> x -> IO x
- subAndFetch :: Ptr x -> x -> IO x
- orAndFetch :: Ptr x -> x -> IO x
- andAndFetch :: Ptr x -> x -> IO x
- xorAndFetch :: Ptr x -> x -> IO x
- nandAndFetch :: Ptr x -> x -> IO x
- compareAndSwapBool :: Ptr x -> x -> x -> IO Bool
- compareAndSwap :: Ptr x -> x -> x -> IO x
- lockTestAndSet :: Ptr x -> IO x
- lockRelease :: Ptr x -> IO ()
- memoryBarrier :: IO ()
Atomic bit operations on Word
-sized memory locations
class Bits x => AtomicBits x whereSource
Atomic bit operations on a memory location.
Instances: Word
, Word8
, Word16
, Word32
, Word64
, Int
, Int8
,
Int16
, Int32
, Int64
.
fetchAndAdd :: Ptr x -> x -> IO xSource
Atomic (+)
, returning the original value.
fetchAndSub :: Ptr x -> x -> IO xSource
Atomic (-)
, returning the originial value.
fetchAndOr :: Ptr x -> x -> IO xSource
Atomic (.|.)
, returning the original value.
fetchAndAnd :: Ptr x -> x -> IO xSource
Atomic (.&.)
, returning the original value.
fetchAndXor :: Ptr x -> x -> IO xSource
Atomic xor
, returning the original value.
fetchAndNand :: Ptr x -> x -> IO xSource
Atomic nand
, returning the original value.
addAndFetch :: Ptr x -> x -> IO xSource
Atomic (+)
, returning the updated value.
subAndFetch :: Ptr x -> x -> IO xSource
Atomic (-)
, returning the updated value.
orAndFetch :: Ptr x -> x -> IO xSource
Atomic (.|.)
, returning the updated value.
andAndFetch :: Ptr x -> x -> IO xSource
Atomic (.&.)
, returning the updated value.
xorAndFetch :: Ptr x -> x -> IO xSource
Atomic xor
, returning the updated value.
nandAndFetch :: Ptr x -> x -> IO xSource
Atomic nand
, returning the updated value.
Atomic CAS
with boolean return.
Atomic CAS
, returning the original value.
lockTestAndSet :: Ptr x -> IO xSource
Atomically update the memory location with the value 1 and return the
original value, 0 in case lockRelease
was previously called or 1
if
another call to lockTestAndSet
aquired the lock earlier. Implies an
aquire barrier.
lockRelease :: Ptr x -> IO ()Source
Release the lock by writing a 0
. Includes a release barrier.
Utility
A full memory barrier.