From a5f7dcaa3ebb00c8e6237f62b08ad9c2f65cfda7 Mon Sep 17 00:00:00 2001 From: ross Date: Fri, 18 Oct 2002 12:28:38 +0000 Subject: [PATCH] [project @ 2002-10-18 12:28:38 by ross] Hugs only: simple version of atomicModifyIORef, relying on the absence of preemption from Hugs. If Hugs gets Haskell finalizers, they'll have to be blocked during this operation. --- Data/IORef.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Data/IORef.hs b/Data/IORef.hs index 55cb52f..527e20a 100644 --- a/Data/IORef.hs +++ b/Data/IORef.hs @@ -20,7 +20,7 @@ module Data.IORef readIORef, -- :: IORef a -> IO a writeIORef, -- :: IORef a -> a -> IO () modifyIORef, -- :: IORef a -> (a -> a) -> IO () - atomicModifyIORef, -- :: IORef a -> (a -> (a,b)) -> IO () + atomicModifyIORef, -- :: IORef a -> (a -> (a,b)) -> IO b #if !defined(__PARALLEL_HASKELL__) && defined(__GLASGOW_HASKELL__) mkWeakIORef, -- :: IORef a -> IO () -> IO (Weak (IORef a)) @@ -77,7 +77,14 @@ modifyIORef ref f = writeIORef ref . f =<< readIORef ref -- then using 'MVar' instead is a good idea. -- atomicModifyIORef :: IORef a -> (a -> (a,b)) -> IO b +#if defined(__GLASGOW_HASKELL__) atomicModifyIORef (IORef (STRef r#)) f = IO $ \s -> atomicModifyMutVar# r# f s +#elif defined(__HUGS__) +atomicModifyIORef = plainModifyIORef -- Hugs has no preemption + where plainModifyIORef r f = do + a <- readIORef r + case f a of (a',b) -> writeIORef r a' >> return b +#endif #ifndef __NHC__ #include "Dynamic.h" -- 1.7.10.4