summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
authorThomas Schilling <nominolo@googlemail.com>2009-08-16 23:13:16 +0000
committerThomas Schilling <nominolo@googlemail.com>2009-08-16 23:13:16 +0000
commitca8d50e001ffa64cefac0231f1cdbdff19b47e8c (patch)
tree6eb78f0da626db8142d1fec4529d07499e59c928 /compiler/utils
parent8a9eb3cd35117c62ac9758d118c6f4109b7330cb (diff)
downloadhaskell-ca8d50e001ffa64cefac0231f1cdbdff19b47e8c.tar.gz
Make updates to the external package state atomic.
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/IOEnv.hs17
1 files changed, 15 insertions, 2 deletions
diff --git a/compiler/utils/IOEnv.hs b/compiler/utils/IOEnv.hs
index b81b2e8fde..1f1dd8fec4 100644
--- a/compiler/utils/IOEnv.hs
+++ b/compiler/utils/IOEnv.hs
@@ -22,13 +22,15 @@ module IOEnv (
tryM, tryAllM, tryMostM, fixM,
-- I/O operations
- IORef, newMutVar, readMutVar, writeMutVar, updMutVar
+ IORef, newMutVar, readMutVar, writeMutVar, updMutVar,
+ atomicUpdMutVar, atomicUpdMutVar'
) where
import Exception
import Panic
-import Data.IORef ( IORef, newIORef, readIORef, writeIORef, modifyIORef )
+import Data.IORef ( IORef, newIORef, readIORef, writeIORef, modifyIORef,
+ atomicModifyIORef )
import Data.Typeable
import System.IO.Unsafe ( unsafeInterleaveIO )
import System.IO ( fixIO )
@@ -162,6 +164,17 @@ readMutVar var = liftIO (readIORef var)
updMutVar :: IORef a -> (a -> a) -> IOEnv env ()
updMutVar var upd = liftIO (modifyIORef var upd)
+-- | Atomically update the reference. Does not force the evaluation of the
+-- new variable contents. For strict update, use 'atomicUpdMutVar''.
+atomicUpdMutVar :: IORef a -> (a -> (a, b)) -> IOEnv env b
+atomicUpdMutVar var upd = liftIO (atomicModifyIORef var upd)
+
+-- | Strict variant of 'atomicUpdMutVar'.
+atomicUpdMutVar' :: IORef a -> (a -> (a, b)) -> IOEnv env b
+atomicUpdMutVar' var upd = do
+ r <- atomicUpdMutVar var upd
+ _ <- liftIO . evaluate =<< readMutVar var
+ return r
----------------------------------------------------------------------
-- Accessing the environment