[mtouch] Don't use nested Parallel.ForEach loops. (#888)

The nested Parallel.ForEach loops don't take into account the outer
MaxDegreeOfParallelism value, causing us to spawn more concurrent tasks than
we want to.

So refactor the code to have one static list of tasks, which each subtask adds
to.
This commit is contained in:
Rolf Bjarne Kvinge 2016-09-23 22:03:23 +02:00 коммит произвёл Sebastien Pouliot
Родитель fa18df5710
Коммит 85cead2337
1 изменённых файлов: 16 добавлений и 5 удалений

Просмотреть файл

@ -1694,19 +1694,30 @@ namespace Xamarin.Bundler {
public class BuildTasks : List<BuildTask>
{
static void Execute (BuildTask v)
static void Execute (List<BuildTask> added, BuildTask v)
{
var next = v.Execute ();
if (next != null)
Parallel.ForEach (next, new ParallelOptions () { MaxDegreeOfParallelism = Driver.Concurrency }, Execute);
if (next != null) {
lock (added)
added.AddRange (next);
}
}
public void ExecuteInParallel ()
{
if (Count == 0)
return;
Parallel.ForEach (this, new ParallelOptions () { MaxDegreeOfParallelism = Driver.Concurrency }, Execute);
var build_list = new List<BuildTask> (this);
var added = new List<BuildTask> ();
while (build_list.Count > 0) {
added.Clear ();
Parallel.ForEach (build_list, new ParallelOptions () { MaxDegreeOfParallelism = Driver.Concurrency }, (v) => {
Execute (added, v);
});
build_list.Clear ();
build_list.AddRange (added);
}
Clear ();
}