23 |
|
static int tasksPerPhaser = Math.max(NCPUS / 8, 4); |
24 |
|
|
25 |
|
static void build(Runnable[] actions, int sz, int lo, int hi, Phaser b) { |
26 |
< |
int step = (hi - lo) / tasksPerPhaser; |
27 |
< |
if (step > 1) { |
28 |
< |
int i = lo; |
29 |
< |
while (i < hi) { |
30 |
< |
int r = Math.min(i + step, hi); |
31 |
< |
build(actions, sz, i, r, new Phaser(b)); |
32 |
< |
i = r; |
26 |
> |
if (hi - lo > tasksPerPhaser) { |
27 |
> |
for (int i = lo; i < hi; i += tasksPerPhaser) { |
28 |
> |
int j = Math.min(i + tasksPerPhaser, hi); |
29 |
> |
build(actions, sz, i, j, new Phaser(b)); |
30 |
|
} |
31 |
< |
} |
35 |
< |
else { |
31 |
> |
} else { |
32 |
|
for (int i = lo; i < hi; ++i) |
33 |
|
actions[i] = new PhaserAction(i, b, sz); |
34 |
|
} |
35 |
|
} |
36 |
|
|
37 |
+ |
|
38 |
|
static final class PhaserAction implements Runnable { |
39 |
|
final int id; |
40 |
|
final int size; |