speculation 0.6.0 → 0.7.0
raw patch · 2 files changed
+22/−28 lines, 2 files
Files
- Control/Concurrent/Speculation.hs +14/−25
- speculation.cabal +8/−3
Control/Concurrent/Speculation.hs view
@@ -15,18 +15,14 @@ , specOnSTM' , specBySTM , specBySTM'- -- * Throw to break out of current speculation- , SpeculationException -- * Determining if a closure is evaluated , unsafeGetTagBits , unsafeIsEvaluated ) where import Control.Concurrent.STM-import Control.Exception (Exception, throw, fromException) import Control.Parallel (par)-import Control.Monad (liftM2)-import Data.Typeable (Typeable)+import Control.Monad (liftM2, unless) import Data.Function (on) import Data.Bits ((.&.)) import Foreign (sizeOf)@@ -76,9 +72,9 @@ -- | 'spec' with a user defined comparison function specBy :: (a -> a -> Bool) -> a -> (a -> b) -> a -> b-specBy cmp g f a+specBy cmp guess f a | unsafeIsEvaluated a = f a- | otherwise = specBy' cmp g f a+ | otherwise = specBy' cmp guess f a {-# INLINE specBy #-} -- | 'spec'' with a user defined comparison function@@ -147,26 +143,22 @@ -- | 'specSTM' using a user defined comparison function specBySTM :: (a -> a -> STM Bool) -> STM a -> (a -> STM b) -> a -> STM b-specBySTM cmp g f a +specBySTM cmp guess f a | unsafeIsEvaluated a = f a - | otherwise = specBySTM' cmp g f a+ | otherwise = specBySTM' cmp guess f a {-# INLINE specBySTM #-} -- | 'specSTM'' using a user defined comparison function specBySTM' :: (a -> a -> STM Bool) -> STM a -> (a -> STM b) -> a -> STM b-specBySTM' cmp g f a = a `par` - let - try = do- g' <- g- result <- f g'- test <- cmp g' a- if test- then return result- else throw SpeculationException- in - try `catchSTM` \e -> case fromException e of- Just SpeculationException -> f a -- rerun with alternative input- _ -> throw e -- this is a bigger problem+specBySTM' cmp mguess f a = a `par` do+ guess <- mguess+ result <- f guess+ -- rendezvous with a+ matching <- cmp guess a + unless matching retry + return result+ `orElse` + f a {-# INLINE specBySTM' #-} -- | @'specBySTM' . 'on' (==)@@@ -178,9 +170,6 @@ specOnSTM' :: Eq c => (a -> STM c) -> STM a -> (a -> STM b) -> a -> STM b specOnSTM' = specBySTM' . on (liftM2 (==)) {-# INLINE specOnSTM' #-}--data SpeculationException = SpeculationException deriving (Show,Eq,Typeable)-instance Exception SpeculationException -- | Used to inspect tag bits data Box a = Box a
speculation.cabal view
@@ -1,5 +1,5 @@ name: speculation-version: 0.6.0+version: 0.7.0 license: BSD3 license-file: LICENSE author: Edward A. Kmett@@ -42,13 +42,18 @@ . 'specSTM' provides a similar time table for STM actions, but also rolls back side-effects. . + /Changes in 0.7.0:/+ .+ * Changed @'throw' 'SpeculationException'@ to 'retry'+ * Removed 'SpeculationException'+ . /Changes in 0.6.0:/ .- * Upgraded the comparisons used by the STM combinators STM actions, so they can check for other STM side-effects.+ * Upgraded the comparisons used by the STM combinators to STM actions, so they can check other STM state . /Changes in 0.5.1:/ . - * Exposed unsafeGetTagBits and unsafeIsEvaluated+ * Exposed 'unsafeGetTagBits' and 'unsafeIsEvaluated' copyright: (c) 2010 Edward A. Kmett build-type: Simple