[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:
Родитель
fa18df5710
Коммит
85cead2337
|
@ -1694,11 +1694,13 @@ 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 ()
|
||||
|
@ -1706,7 +1708,16 @@ namespace Xamarin.Bundler {
|
|||
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 ();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче