{-# LANGUAGE Unsafe #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
{-# OPTIONS_HADDOCK hide #-}
module GHC.IORef (
IORef(..),
newIORef, readIORef, writeIORef, atomicModifyIORef
) where
import GHC.Base
import GHC.STRef
import GHC.IO
newtype IORef a = IORef (STRef RealWorld a)
deriving Eq
newIORef :: a -> IO (IORef a)
newIORef v = stToIO (newSTRef v) >>= \ var -> return (IORef var)
readIORef :: IORef a -> IO a
readIORef (IORef var) = stToIO (readSTRef var)
writeIORef :: IORef a -> a -> IO ()
writeIORef (IORef var) v = stToIO (writeSTRef var v)
atomicModifyIORef :: IORef a -> (a -> (a,b)) -> IO b
atomicModifyIORef (IORef (STRef r#)) f = IO $ \s -> atomicModifyMutVar# r# f s