From: Simon Marlow Date: Fri, 10 Oct 2008 11:38:35 +0000 (+0000) Subject: add readTVarIO :: TVar a -> IO a X-Git-Tag: 2009-06-25~107 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=6567f258a7a9e8ec0f5167f87ee6a104f83582b3;p=ghc-base.git add readTVarIO :: TVar a -> IO a --- diff --git a/GHC/Conc.lhs b/GHC/Conc.lhs index b19f520..9e0969d 100644 --- a/GHC/Conc.lhs +++ b/GHC/Conc.lhs @@ -72,6 +72,7 @@ module GHC.Conc , newTVar -- :: a -> STM (TVar a) , newTVarIO -- :: a -> STM (TVar a) , readTVar -- :: TVar a -> STM a + , readTVarIO -- :: TVar a -> IO a , writeTVar -- :: a -> TVar a -> STM () , unsafeIOToSTM -- :: IO a -> STM a @@ -550,6 +551,16 @@ newTVarIO val = IO $ \s1# -> case newTVar# val s1# of (# s2#, tvar# #) -> (# s2#, TVar tvar# #) +-- |Return the current value stored in a TVar. +-- This is equivalent to +-- +-- > readTVarIO = atomically . readTVar +-- +-- but works much faster, because it doesn't perform a complete +-- transaction, it just reads the current value of the 'TVar'. +readTVarIO :: TVar a -> IO a +readTVarIO (TVar tvar#) = IO $ \s# -> readTVarIO# tvar# s# + -- |Return the current value stored in a TVar readTVar :: TVar a -> STM a readTVar (TVar tvar#) = STM $ \s# -> readTVar# tvar# s#