[commit: stm] master: Control.Concurrent.STM.TMVar: added tryReadTMVar (86b8629)
Simon Marlow
marlowsd at gmail.com
Mon Apr 11 12:42:51 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/packages/stm
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/86b8629bebf53f00afb641e0a9b2cb3eff7b38d3
>---------------------------------------------------------------
commit 86b8629bebf53f00afb641e0a9b2cb3eff7b38d3
Author: Simon Marlow <marlowsd at gmail.com>
Date: Mon Apr 11 11:06:05 2011 +0100
Control.Concurrent.STM.TMVar: added tryReadTMVar
>---------------------------------------------------------------
Control/Concurrent/STM/TMVar.hs | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Control/Concurrent/STM/TMVar.hs b/Control/Concurrent/STM/TMVar.hs
index 0a43b0a..05c83f6 100644
--- a/Control/Concurrent/STM/TMVar.hs
+++ b/Control/Concurrent/STM/TMVar.hs
@@ -26,6 +26,7 @@ module Control.Concurrent.STM.TMVar (
takeTMVar,
putTMVar,
readTMVar,
+ tryReadTMVar,
swapTMVar,
tryTakeTMVar,
tryPutTMVar,
@@ -115,10 +116,9 @@ tryPutTMVar (TMVar t) a = do
Nothing -> do writeTVar t (Just a); return True
Just _ -> return False
-{-|
- This is a combination of 'takeTMVar' and 'putTMVar'; ie. it takes the value
- from the 'TMVar', puts it back, and also returns it.
--}
+-- | This is a combination of 'takeTMVar' and 'putTMVar'; ie. it
+-- takes the value from the 'TMVar', puts it back, and also returns
+-- it.
readTMVar :: TMVar a -> STM a
readTMVar (TMVar t) = do
m <- readTVar t
@@ -126,6 +126,10 @@ readTMVar (TMVar t) = do
Nothing -> retry
Just a -> return a
+-- | Non-blocking version of 'readTMVar'.
+tryReadTMVar :: TMVar a -> STM (Maybe a)
+tryReadTMVar (TMVar t) = readTVar t
+
-- |Swap the contents of a 'TMVar' for a new value.
swapTMVar :: TMVar a -> a -> STM a
swapTMVar (TMVar t) new = do
More information about the Cvs-libraries
mailing list