diff options
Diffstat (limited to 'tools/multigcc.pl')
-rwxr-xr-x | tools/multigcc.pl | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/tools/multigcc.pl b/tools/multigcc.pl index 5222f61b49..9be9978bd4 100755 --- a/tools/multigcc.pl +++ b/tools/multigcc.pl | |||
@@ -46,27 +46,25 @@ switch($^O) { | |||
46 | } | 46 | } |
47 | } | 47 | } |
48 | 48 | ||
49 | # don't run empty children | ||
50 | if (scalar @files <= $cores) | ||
51 | { | ||
52 | $cores = 1; | ||
53 | } | ||
54 | |||
55 | # fork children | 49 | # fork children |
56 | my @pids; | 50 | my @pids; |
57 | my $slice = int((scalar @files + $cores) / $cores); | 51 | my $slice = int((scalar @files + $cores) / $cores); |
58 | for my $i (0 .. $cores-1) | 52 | |
53 | # reset $cores to 0 so we can count the number of actually used cores | ||
54 | $cores=0; | ||
55 | |||
56 | for (my $i=0;$i<scalar @files;$i += $slice) | ||
59 | { | 57 | { |
60 | my $pid = fork; | 58 | my $pid = fork; |
61 | if ($pid) | 59 | if ($pid) |
62 | { | 60 | { |
63 | # mother | 61 | # mother |
64 | $pids[$i] = $pid; | 62 | $pids[$cores++] = $pid; |
65 | } | 63 | } |
66 | else | 64 | else |
67 | { | 65 | { |
68 | # get my slice of the files | 66 | # get my slice of the files |
69 | my @list = @files[$i * $slice .. $i * $slice + $slice - 1]; | 67 | my @list = @files[$i .. $i + $slice - 1]; |
70 | 68 | ||
71 | # run command | 69 | # run command |
72 | system("$command @list > $tempfile.$$"); | 70 | system("$command @list > $tempfile.$$"); |