stm 2.2.0.0 → 2.2.0.1
raw patch · 3 files changed
+40/−5 lines, 3 files
Files
- Control/Concurrent/STM/TArray.hs +1/−2
- Control/Monad/STM.hs +38/−2
- stm.cabal +1/−1
Control/Concurrent/STM/TArray.hs view
@@ -1,5 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}-{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE CPP, DeriveDataTypeable, FlexibleInstances, MultiParamTypeClasses #-} ----------------------------------------------------------------------------- -- |
Control/Monad/STM.hs view
@@ -1,4 +1,5 @@ {-# OPTIONS_GHC -fno-warn-orphans #-}+{-# LANGUAGE MagicHash #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Monad.STM@@ -36,9 +37,13 @@ ) where #ifdef __GLASGOW_HASKELL__-import GHC.Conc #if ! (MIN_VERSION_base(4,3,0))-import Control.Monad ( MonadPlus(..) )+import GHC.Conc hiding (catchSTM)+import Control.Monad ( MonadPlus(..) )+import GHC.Exts (raiseIO#, catchSTM#)+import Control.Exception+#else+import GHC.Conc #endif #else import Control.Sequential.STM@@ -53,4 +58,35 @@ check :: Bool -> STM a check b = if b then return undefined else retry+#endif++#if ! (MIN_VERSION_base(4,3,0))+-- |Exception handling within STM actions.+catchSTM :: Exception e => STM a -> (e -> STM a) -> STM a+catchSTM (STM m) handler = STM $ catchSTM# m handler'+ where+ handler' e = case fromException e of+ Just e' -> case handler e' of STM m' -> m'+ Nothing -> raiseIO# e++-- | A variant of 'throw' that can only be used within the 'STM' monad.+--+-- Throwing an exception in @STM@ aborts the transaction and propagates the+-- exception.+--+-- Although 'throwSTM' has a type that is an instance of the type of 'throw', the+-- two functions are subtly different:+--+-- > throw e `seq` x ===> throw e+-- > throwSTM e `seq` x ===> x+--+-- The first example will cause the exception @e@ to be raised,+-- whereas the second one won\'t. In fact, 'throwSTM' will only cause+-- an exception to be raised when it is used within the 'STM' monad.+-- The 'throwSTM' variant should be used in preference to 'throw' to+-- raise an exception within the 'STM' monad because it guarantees+-- ordering with respect to other 'STM' operations, whereas 'throw'+-- does not.+throwSTM :: Exception e => e -> STM a+throwSTM e = STM $ raiseIO# (toException e) #endif
stm.cabal view
@@ -1,5 +1,5 @@ name: stm-version: 2.2.0.0+version: 2.2.0.1 license: BSD3 license-file: LICENSE maintainer: libraries@haskell.org