module Data.IORef.Compat (
module Base
, modifyIORef'
, atomicModifyIORef'
, atomicWriteIORef
) where
import Data.IORef as Base
#if !(MIN_VERSION_base(4,6,0))
import Prelude
modifyIORef' :: IORef a -> (a -> a) -> IO ()
modifyIORef' ref f = do
x <- readIORef ref
let x' = f x
x' `seq` writeIORef ref x'
atomicModifyIORef' :: IORef a -> (a -> (a,b)) -> IO b
atomicModifyIORef' ref f = do
b <- atomicModifyIORef ref $ \a ->
case f a of
v@(a',_) -> a' `seq` v
b `seq` return b
atomicWriteIORef :: IORef a -> a -> IO ()
atomicWriteIORef ref a = do
x <- atomicModifyIORef ref (\_ -> (a, ()))
x `seq` return ()
#endif