@@ -43,7 +43,6 @@ import Control.Distributed.Process.Internal.StrictList
4343 , append
4444 )
4545import Data.Maybe (fromJust)
46−import Data.Foldable (traverse_)
4746import GHC.MVar (MVar(MVar))
4847import GHC.IO (IO(IO))
4948import GHC.Prim (mkWeak#)
@@ -110,7 +109,7 @@ dequeue :: forall m a.
110109 -> BlockSpec -- ^ Blocking behaviour
111110 -> [MatchOn m a] -- ^ List of matches
112111 -> IO (Maybe a) -- ^ 'Nothing' only on timeout
113−dequeue (CQueue arrived incoming size) blockSpec matchons = mask_ $ checkDecrement $
112+dequeue (CQueue arrived incoming size) blockSpec matchons = mask_ $ decrementJust $
114113 case blockSpec of
115114 Timeout n -> timeout n $ fmap fromJust run
116115 _other ->
@@ -122,9 +121,14 @@ dequeue (CQueue arrived incoming size) blockSpec matchons = mask_ $ checkDecreme
122121 -- no onException needed
123122 _other -> run
124123 where
125− checkDecrement f = do
124+ -- Decrement counter is smth is returned from the queue,
125+ -- this is safe to use as method is called under a mask
126+ -- and there is no 'unmasked' operation inside
127+ decrementJust f = do
126128 mx <- f
127− mask_ $ traverse_ (const $ atomically $ modifyTVar' size pred) mx
129+ case mx of
130+ Just{} -> atomically $ modifyTVar' size pred
131+ Nothing -> return ()
128132 return mx
129133
130134 chunks = chunkMatches matchons