git.iko.soy/distributed-process
on master help sign in
Fix a bug in CQueue
a3aced6Simon Marlow
distributed-process/src/Control/Distributed/Process/Internal/CQueue.hs+11−6
@@ -33,8 +33,8 @@ import Control.Distributed.Process.Internal.StrictMVar
33 )
33 )
34import Control.Distributed.Process.Internal.StrictList
34import Control.Distributed.Process.Internal.StrictList
35 ( StrictList(..)
35 ( StrictList(..)
36+ , append
36 )
37 )
37−import qualified Control.Distributed.Process.Internal.StrictList as S
38import Data.Maybe (fromJust)
38import Data.Maybe (fromJust)
39import GHC.MVar (MVar(MVar))
39import GHC.MVar (MVar(MVar))
40import GHC.IO (IO(IO))
40import GHC.IO (IO(IO))
@@ -146,8 +146,8 @@ dequeue (CQueue arrived incoming) blockSpec matchons =
146 -- of passing around restore and setting up exception handlers is
146 -- of passing around restore and setting up exception handlers is
147 -- high. So just don't use expensive matchIfs!
147 -- high. So just don't use expensive matchIfs!
148 case checkArrived matches old of
148 case checkArrived matches old of
149− (old', Just r) -> returnOld old' (Just r)
149+ (old', Just r) -> returnOld old' (Just r)
150− (old', Nothing) -> goCheck rest old'
150+ (old', Nothing) -> goCheck rest old'
151 -- use the result list, which is now left-biased
151 -- use the result list, which is now left-biased
152
152
153 --
153 --
@@ -222,11 +222,16 @@ dequeue (CQueue arrived incoming) blockSpec matchons =
222
222
223 -- as a side-effect, this left-biases the list
223 -- as a side-effect, this left-biases the list
224 checkArrived :: [m -> Maybe a] -> StrictList m -> (StrictList m, Maybe a)
224 checkArrived :: [m -> Maybe a] -> StrictList m -> (StrictList m, Maybe a)
225− checkArrived matches list = S.foldr f (Nil, Nothing) list
225+ checkArrived matches list = go list Nil
226 where
226 where
227− f x (rest,r)
227+ go Nil Nil = (Nil, Nothing)
228+ go Nil r = go r Nil
229+ go (Append xs ys) tl = go xs (append ys tl)
230+ go (Snoc xs x) tl = go xs (Cons x tl)
231+ go (Cons x xs) tl
228− | Just y <- checkMatches matches x = (rest, Just y)
232+ | Just y <- checkMatches matches x = (Append xs tl, Just y)
229 | otherwise = (Cons x rest, r)
233 | otherwise = (Cons x rest, r)
234+ where !(rest,r) = go xs tl
230
235
231 checkMatches :: [m -> Maybe a] -> m -> Maybe a
236 checkMatches :: [m -> Maybe a] -> m -> Maybe a
232 checkMatches [] _ = Nothing
237 checkMatches [] _ = Nothing