17 |
|
static final int POOL_MASK = POOL_SIZE-1; |
18 |
|
static final Integer[] intPool = new Integer[POOL_SIZE]; |
19 |
|
static { |
20 |
< |
for (int i = 0; i < POOL_SIZE; ++i) |
20 |
> |
for (int i = 0; i < POOL_SIZE; ++i) |
21 |
|
intPool[i] = Integer.valueOf(i); |
22 |
|
} |
23 |
|
|
43 |
|
int maxPairs = NCPUS * 3 / 2; |
44 |
|
int iters = 1000000; |
45 |
|
|
46 |
< |
if (args.length > 0) |
46 |
> |
if (args.length > 0) |
47 |
|
maxPairs = Integer.parseInt(args[0]); |
48 |
|
|
49 |
|
print = true; |
55 |
|
if (i == k) { |
56 |
|
k = i << 1; |
57 |
|
i = i + (i >>> 1); |
58 |
< |
} |
59 |
< |
else |
58 |
> |
} |
59 |
> |
else |
60 |
|
i = k; |
61 |
|
} |
62 |
|
pool.shutdown(); |
104 |
|
oneRun(new ArrayBlockingQueue<Integer>(POOL_SIZE, true), n, iters/16); |
105 |
|
|
106 |
|
} |
107 |
< |
|
107 |
> |
|
108 |
|
static abstract class Stage implements Runnable { |
109 |
|
final int iters; |
110 |
|
final BlockingQueue<Integer> queue; |
111 |
|
final CyclicBarrier barrier; |
112 |
|
Stage (BlockingQueue<Integer> q, CyclicBarrier b, int iters) { |
113 |
< |
queue = q; |
113 |
> |
queue = q; |
114 |
|
barrier = b; |
115 |
|
this.iters = iters; |
116 |
|
} |
143 |
|
addProducerSum(s); |
144 |
|
barrier.await(); |
145 |
|
} |
146 |
< |
catch (Exception ie) { |
147 |
< |
ie.printStackTrace(); |
148 |
< |
return; |
146 |
> |
catch (Exception ie) { |
147 |
> |
ie.printStackTrace(); |
148 |
> |
return; |
149 |
|
} |
150 |
|
} |
151 |
|
} |
152 |
|
|
153 |
|
static class Consumer extends Stage { |
154 |
< |
Consumer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) { |
154 |
> |
Consumer(BlockingQueue<Integer> q, CyclicBarrier b, int iters) { |
155 |
|
super(q, b, iters); |
156 |
|
} |
157 |
|
|
163 |
|
int i = 0; |
164 |
|
long timeout = 1000; |
165 |
|
while (i < iters) { |
166 |
< |
Integer e = queue.poll(timeout, |
166 |
> |
Integer e = queue.poll(timeout, |
167 |
|
TimeUnit.NANOSECONDS); |
168 |
|
if (e != null) { |
169 |
|
l = LoopHelpers.compute4(e.intValue()); |
178 |
|
addConsumerSum(s); |
179 |
|
barrier.await(); |
180 |
|
} |
181 |
< |
catch (Exception ie) { |
182 |
< |
ie.printStackTrace(); |
183 |
< |
return; |
181 |
> |
catch (Exception ie) { |
182 |
> |
ie.printStackTrace(); |
183 |
> |
return; |
184 |
|
} |
185 |
|
} |
186 |
|
|
205 |
|
static final class LTQasSQ<T> extends LinkedTransferQueue<T> { |
206 |
|
LTQasSQ() { super(); } |
207 |
|
public void put(T x) { |
208 |
< |
try { super.transfer(x); |
208 |
> |
try { super.transfer(x); |
209 |
|
} catch (InterruptedException ex) { throw new Error(); } |
210 |
|
} |
211 |
|
|
212 |
|
public boolean offer(T x, long timeout, TimeUnit unit) { |
213 |
< |
return super.offer(x, timeout, unit); |
213 |
> |
return super.offer(x, timeout, unit); |
214 |
|
} |
215 |
|
|
216 |
|
} |