minor optimisation

Avoid a second mvar access.

Sponsored-by: Jochen Bartl on Patreon
This commit is contained in:
Joey Hess 2021-06-04 14:56:31 -04:00
parent 4b6cb2b917
commit b3cd0cc6ba
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -55,17 +55,18 @@ commandActions = mapM_ commandAction
- This should only be run in the seek stage. - This should only be run in the seek stage.
-} -}
commandAction :: CommandStart -> Annex () commandAction :: CommandStart -> Annex ()
commandAction start = getConcurrency >>= \case commandAction start = do
st <- Annex.getState id
case getConcurrency' (Annex.concurrency st) of
NonConcurrent -> runnonconcurrent NonConcurrent -> runnonconcurrent
Concurrent n Concurrent n
| n > 1 -> runconcurrent | n > 1 -> runconcurrent (Annex.workers st)
| otherwise -> runnonconcurrent | otherwise -> runnonconcurrent
ConcurrentPerCpu -> runconcurrent ConcurrentPerCpu -> runconcurrent (Annex.workers st)
where where
runnonconcurrent = void $ includeCommandAction start runnonconcurrent = void $ includeCommandAction start
runconcurrent = Annex.getState Annex.workers >>= \case runconcurrent Nothing = runnonconcurrent
Nothing -> runnonconcurrent runconcurrent (Just tv) =
Just tv ->
liftIO (atomically (waitStartWorkerSlot tv)) >>= liftIO (atomically (waitStartWorkerSlot tv)) >>=
maybe runnonconcurrent (runconcurrent' tv) maybe runnonconcurrent (runconcurrent' tv)
runconcurrent' tv (workerstrd, workerstage) = do runconcurrent' tv (workerstrd, workerstage) = do