git.iko.soy/distributed-process
on master help sign in
Fix code style and remove unnessesary mask
ac24ea8Alexander Vershilov
src/Control/Distributed/Process/Internal/CQueue.hs+8−4
@@ -43,7 +43,6 @@ import Control.Distributed.Process.Internal.StrictList
43 , append
43 , append
44 )
44 )
45import Data.Maybe (fromJust)
45import Data.Maybe (fromJust)
46−import Data.Foldable (traverse_)
47import GHC.MVar (MVar(MVar))
46import GHC.MVar (MVar(MVar))
48import GHC.IO (IO(IO))
47import GHC.IO (IO(IO))
49import GHC.Prim (mkWeak#)
48import GHC.Prim (mkWeak#)
@@ -110,7 +109,7 @@ dequeue :: forall m a.
110 -> BlockSpec -- ^ Blocking behaviour
109 -> BlockSpec -- ^ Blocking behaviour
111 -> [MatchOn m a] -- ^ List of matches
110 -> [MatchOn m a] -- ^ List of matches
112 -> IO (Maybe a) -- ^ 'Nothing' only on timeout
111 -> 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 $
114 case blockSpec of
113 case blockSpec of
115 Timeout n -> timeout n $ fmap fromJust run
114 Timeout n -> timeout n $ fmap fromJust run
116 _other ->
115 _other ->
@@ -122,9 +121,14 @@ dequeue (CQueue arrived incoming size) blockSpec matchons = mask_ $ checkDecreme
122 -- no onException needed
121 -- no onException needed
123 _other -> run
122 _other -> run
124 where
123 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
126 mx <- f
128 mx <- f
129+ case mx of
127− mask_ $ traverse_ (const $ atomically $ modifyTVar' size pred) mx
130+ Just{} -> atomically $ modifyTVar' size pred
131+ Nothing -> return ()
128 return mx
132 return mx
129
133
130 chunks = chunkMatches matchons
134 chunks = chunkMatches matchons