From b3cd0cc6ba4e5b9e2ae0abd9c8b2ec32475e09d2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 4 Jun 2021 14:56:31 -0400 Subject: [PATCH] minor optimisation Avoid a second mvar access. Sponsored-by: Jochen Bartl on Patreon --- CmdLine/Action.hs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/CmdLine/Action.hs b/CmdLine/Action.hs index 1e18490193..008e8fc993 100644 --- a/CmdLine/Action.hs +++ b/CmdLine/Action.hs @@ -55,19 +55,20 @@ commandActions = mapM_ commandAction - This should only be run in the seek stage. -} commandAction :: CommandStart -> Annex () -commandAction start = getConcurrency >>= \case - NonConcurrent -> runnonconcurrent - Concurrent n - | n > 1 -> runconcurrent - | otherwise -> runnonconcurrent - ConcurrentPerCpu -> runconcurrent +commandAction start = do + st <- Annex.getState id + case getConcurrency' (Annex.concurrency st) of + NonConcurrent -> runnonconcurrent + Concurrent n + | n > 1 -> runconcurrent (Annex.workers st) + | otherwise -> runnonconcurrent + ConcurrentPerCpu -> runconcurrent (Annex.workers st) where runnonconcurrent = void $ includeCommandAction start - runconcurrent = Annex.getState Annex.workers >>= \case - Nothing -> runnonconcurrent - Just tv -> - liftIO (atomically (waitStartWorkerSlot tv)) >>= - maybe runnonconcurrent (runconcurrent' tv) + runconcurrent Nothing = runnonconcurrent + runconcurrent (Just tv) = + liftIO (atomically (waitStartWorkerSlot tv)) >>= + maybe runnonconcurrent (runconcurrent' tv) runconcurrent' tv (workerstrd, workerstage) = do aid <- liftIO $ async $ snd <$> Annex.run workerstrd