module Data.Atomic (
Atomic,
new,
add, and,
) where
import Data.Int
import Foreign.Ptr
import Foreign.ForeignPtr
import Foreign.Storable
import Prelude ( ($), IO, return )
newtype Atomic = Atomic ( ForeignPtr Int64 )
new :: Int64 -> IO Atomic
new v = do
fp <- mallocForeignPtr
withForeignPtr fp $ \p -> poke p v
return $ Atomic fp
add :: Atomic -> Int64 -> IO Int64
add (Atomic fp) v =
withForeignPtr fp $ \p -> atomic_fetch_and_add_64 p v
and :: Atomic -> Int64 -> IO Int64
and (Atomic fp) v =
withForeignPtr fp $ \p -> atomic_fetch_and_and_64 p v
foreign import ccall unsafe "hs_atomic_fetch_and_add_64" atomic_fetch_and_add_64 :: Ptr Int64 -> Int64 -> IO Int64
foreign import ccall unsafe "hs_atomic_fetch_and_and_64" atomic_fetch_and_and_64 :: Ptr Int64 -> Int64 -> IO Int64