{-# LANGUAGE Unsafe #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash, AutoDeriveTypeable #-}
{-# 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
import Data.Typeable.Internal( Typeable )
newtype IORef a = IORef (STRef RealWorld a) deriving( Typeable )
instance Eq (IORef a) where
IORef x == IORef y = x == y
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