summaryrefslogtreecommitdiff
path: root/Utility/Parallel.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-26 17:33:34 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-26 19:21:44 -0400
commit67c8ef7de25ad6f433db2fa5d5fc764dd515a5b2 (patch)
tree3666619b0752df6c336fdbac270e09dbd125bcec /Utility/Parallel.hs
parente0a65247aebb8a821f4f0b717d39a4a35136a2e6 (diff)
use a TMVar
SampleMVar won't work; between getting the current value and changing it, another thread could made a change, which would get lost. TMVar works well; this update situation is handled by atomic transactions.
Diffstat (limited to 'Utility/Parallel.hs')
-rw-r--r--Utility/Parallel.hs10
1 files changed, 6 insertions, 4 deletions
diff --git a/Utility/Parallel.hs b/Utility/Parallel.hs
index 6e4671c05..9df95ab2b 100644
--- a/Utility/Parallel.hs
+++ b/Utility/Parallel.hs
@@ -10,11 +10,13 @@ module Utility.Parallel where
import Common
{- Runs an action in parallel with a set of values.
- - Returns values that caused the action to fail. -}
-inParallel :: (v -> IO ()) -> [v] -> IO [v]
+ - Returns the values partitioned into ones with which the action succeeded,
+ - and ones with which it failed. -}
+inParallel :: (v -> IO ()) -> [v] -> IO ([v], [v])
inParallel a l = do
pids <- mapM (forkProcess . a) l
statuses <- mapM (getProcessStatus True False) pids
- return $ map fst $ filter (failed . snd) $ zip l statuses
+ return $ reduce $ partition (succeeded . snd) $ zip l statuses
where
- failed v = v /= Just (Exited ExitSuccess)
+ succeeded v = v == Just (Exited ExitSuccess)
+ reduce (x,y) = (map fst x, map fst y)