Skip to content

Commit bd22ac3

Browse files
committed
hold lock as appropriate; less duplicate work
1 parent 9c28893 commit bd22ac3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

clash-lib/src/Clash/Normalize.hs

+9-6
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,15 @@ normalizeStep q binds = do
168168
res <- Monad.liftIO $ MS.tryPopR q
169169
case res of
170170
Just id' -> do
171-
(bound, _) <- MVar.readMVar binds
172-
unless (id' `elemVarSet` bound) $ do
173-
-- immediately mark this work as being done
174-
MVar.modifyMVar_ binds (pure . first (`extendVarSet` id'))
175-
pair <- normalize' id' q
176-
MVar.modifyMVar_ binds (pure . second (pair:))
171+
(bound, pairs) <- MVar.takeMVar binds
172+
if not (id' `elemVarSet` bound)
173+
then do
174+
-- mark that we are attempting to normalize id'
175+
MVar.putMVar binds (bound `extendVarSet` id', pairs)
176+
pair <- normalize' id' q
177+
MVar.modifyMVar_ binds (pure . second (pair:))
178+
else
179+
MVar.putMVar binds (bound, pairs)
177180
normalizeStep q binds
178181
Nothing -> pure ()
179182

0 commit comments

Comments
 (0)