{-# LINE 1 "GHC.IORef.hs" #-}
# LANGUAGE Unsafe #
# LANGUAGE NoImplicitPrelude , MagicHash #
{-# OPTIONS_GHC -funbox-strict-fields #-}
{-# OPTIONS_HADDOCK hide #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  GHC.IORef
  Copyright    :   ( c ) The University of Glasgow 2008
-- License     :  see libraries/base/LICENSE
--
-- Maintainer  :  
-- Stability   :  internal
  Portability :   non - portable ( GHC Extensions )
--
-- The IORef type
--
-----------------------------------------------------------------------------

module GHC.IORef (
        IORef(..),
        newIORef, readIORef, writeIORef, atomicModifyIORef
    ) where

import GHC.Base
import GHC.STRef
import GHC.IO

-- ---------------------------------------------------------------------------
  IORefs

-- |A mutable variable in the 'IO' monad
newtype IORef a = IORef (STRef RealWorld a)

  explicit instance because  ca n't figure out a derived one
instance Eq (IORef a) where
  IORef x == IORef y = x == y

-- |Build a new 'IORef'
newIORef    :: a -> IO (IORef a)
newIORef v = stToIO (newSTRef v) >>= \ var -> return (IORef var)

-- |Read the value of an 'IORef'
readIORef   :: IORef a -> IO a
readIORef  (IORef var) = stToIO (readSTRef var)

-- |Write a new value into an 'IORef'
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


# LINE 1 "GHC.IORef.hs" #
# OPTIONS_GHC -funbox-strict-fields #
# OPTIONS_HADDOCK hide #
---------------------------------------------------------------------------
 |
 Module      :  GHC.IORef
 License     :  see libraries/base/LICENSE

 Maintainer  :  
 Stability   :  internal

 The IORef type

---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 |A mutable variable in the 'IO' monad
 |Build a new 'IORef'
 |Read the value of an 'IORef'
 |Write a new value into an 'IORef'
# LANGUAGE Unsafe #
# LANGUAGE NoImplicitPrelude , MagicHash #

  Copyright    :   ( c ) The University of Glasgow 2008
  Portability :   non - portable ( GHC Extensions )

module GHC.IORef (
        IORef(..),
        newIORef, readIORef, writeIORef, atomicModifyIORef
    ) where

import GHC.Base
import GHC.STRef
import GHC.IO

  IORefs

newtype IORef a = IORef (STRef RealWorld a)

  explicit instance because  ca n't figure out a derived one
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

