bits-atomic-0.1.0: Atomic bit operations on memory locations for low-level synchronization

Safe HaskellSafe-Inferred
LanguageHaskell98

Data.Bits.Atomic

Contents

Description

Atomic bit operations, using GCC's built-in atomic operations in small C wrapper functions called through the FFI. See http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Atomic-Builtins.html or the version corresponding to your compiler for more detail.

Synopsis

Atomic bit operations on Word-sized memory locations

class Bits x => AtomicBits x where Source

Atomic bit operations on a memory location.

Instances: Word, Word8, Word16, Word32, Word64, Int, Int8, Int16, Int32, Int64.

Methods

fetchAndAdd :: Ptr x -> x -> IO x Source

Atomic (+), returning the original value.

fetchAndSub :: Ptr x -> x -> IO x Source

Atomic (-), returning the originial value.

fetchAndOr :: Ptr x -> x -> IO x Source

Atomic (.|.), returning the original value.

fetchAndAnd :: Ptr x -> x -> IO x Source

Atomic (.&.), returning the original value.

fetchAndXor :: Ptr x -> x -> IO x Source

Atomic xor, returning the original value.

fetchAndNand :: Ptr x -> x -> IO x Source

Atomic nand, returning the original value.

addAndFetch :: Ptr x -> x -> IO x Source

Atomic (+), returning the updated value.

subAndFetch :: Ptr x -> x -> IO x Source

Atomic (-), returning the updated value.

orAndFetch :: Ptr x -> x -> IO x Source

Atomic (.|.), returning the updated value.

andAndFetch :: Ptr x -> x -> IO x Source

Atomic (.&.), returning the updated value.

xorAndFetch :: Ptr x -> x -> IO x Source

Atomic xor, returning the updated value.

nandAndFetch :: Ptr x -> x -> IO x Source

Atomic nand, returning the updated value.

compareAndSwapBool Source

Arguments

:: Ptr x

The memory location to update

-> x

Old value

-> x

Intended new value

-> IO Bool

True if swapped, False otherwise

Atomic CAS with boolean return.

compareAndSwap Source

Arguments

:: Ptr x

The memory location to update

-> x

Old value

-> x

Intended new value

-> IO x

Original value

Atomic CAS, returning the original value.

lockTestAndSet :: Ptr x -> IO x Source

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

memoryBarrier :: IO () Source

A full memory barrier.