module Data.IORefStable
(IORefStable(..)
,newIORefStable
,readIORefStable
,writeIORefStable
,modifyIORefStable
,modifyIORefStable'
,atomicModifyIORefStable
,atomicModifyIORefStable'
,atomicWriteIORefStable
) where
import Data.Unique
import Data.IORef
data IORefStable a = IORefStable !Unique !(IORef a) deriving (Eq)
instance Ord (IORefStable a) where
(IORefStable u1 _) `compare` (IORefStable u2 _) = u1 `compare` u2
newIORefStable :: a -> IO (IORefStable a)
newIORefStable a = do
u <- newUnique
ref <- newIORef a
return (IORefStable u ref)
readIORefStable :: IORefStable a -> IO a
readIORefStable (IORefStable _ r) = readIORef r
writeIORefStable :: IORefStable a -> a -> IO ()
writeIORefStable (IORefStable _ r) a = writeIORef r a
modifyIORefStable :: IORefStable a -> (a -> a) -> IO ()
modifyIORefStable (IORefStable _ r) f = modifyIORef r f
modifyIORefStable' :: IORefStable a -> (a -> a) -> IO ()
modifyIORefStable' (IORefStable _ r) f = modifyIORef' r f
atomicModifyIORefStable :: IORefStable a -> (a -> (a, b)) -> IO b
atomicModifyIORefStable (IORefStable _ r) f = atomicModifyIORef r f
atomicModifyIORefStable' :: IORefStable a -> (a -> (a, b)) -> IO b
atomicModifyIORefStable' (IORefStable _ r) f = atomicModifyIORef' r f
atomicWriteIORefStable :: IORefStable a -> a -> IO ()
atomicWriteIORefStable (IORefStable _ r) a = atomicWriteIORef r a