ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/TimeoutProducerConsumerLoops.java
(Generate patch)

Comparing jsr166/src/test/loops/TimeoutProducerConsumerLoops.java (file contents):
Revision 1.3 by dl, Fri Oct 23 19:57:07 2009 UTC vs.
Revision 1.4 by jsr166, Thu Oct 29 23:09:08 2009 UTC

# Line 17 | Line 17 | public class TimeoutProducerConsumerLoop
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  
# Line 43 | Line 43 | public class TimeoutProducerConsumerLoop
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;
# Line 55 | Line 55 | public class TimeoutProducerConsumerLoop
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();
# Line 104 | Line 104 | public class TimeoutProducerConsumerLoop
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          }
# Line 143 | Line 143 | public class TimeoutProducerConsumerLoop
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  
# Line 163 | Line 163 | public class TimeoutProducerConsumerLoop
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());
# Line 178 | Line 178 | public class TimeoutProducerConsumerLoop
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  
# Line 205 | Line 205 | public class TimeoutProducerConsumerLoop
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      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines