--- jsr166/src/jsr166y/LinkedTransferQueue.java 2009/07/20 22:26:03 1.18 +++ jsr166/src/jsr166y/LinkedTransferQueue.java 2009/07/23 23:07:57 1.23 @@ -44,7 +44,6 @@ import java.lang.reflect.*; * @since 1.7 * @author Doug Lea * @param the type of elements held in this collection - * */ public class LinkedTransferQueue extends AbstractQueue implements TransferQueue, java.io.Serializable { @@ -81,7 +80,7 @@ public class LinkedTransferQueue exte * seems not to vary with number of CPUs (beyond 2) so is just * a constant. */ - static final int maxTimedSpins = (NCPUS < 2)? 0 : 32; + static final int maxTimedSpins = (NCPUS < 2) ? 0 : 32; /** * The number of times to spin before blocking in untimed waits. @@ -140,6 +139,7 @@ public class LinkedTransferQueue exte /** head of the queue */ private transient final PaddedAtomicReference head; + /** tail of the queue */ private transient final PaddedAtomicReference tail; @@ -203,7 +203,7 @@ public class LinkedTransferQueue exte Object x = first.get(); if (x != first && first.compareAndSet(x, e)) { LockSupport.unpark(first.waiter); - return isData? e : x; + return isData ? e : x; } } } @@ -241,7 +241,7 @@ public class LinkedTransferQueue exte Object x = first.get(); if (x != first && first.compareAndSet(x, e)) { LockSupport.unpark(first.waiter); - return isData? e : x; + return isData ? e : x; } } } @@ -264,7 +264,7 @@ public class LinkedTransferQueue exte if (mode == NOWAIT) return null; - long lastTime = (mode == TIMEOUT)? System.nanoTime() : 0; + long lastTime = (mode == TIMEOUT) ? System.nanoTime() : 0; Thread w = Thread.currentThread(); int spins = -1; // set to desired spin count below for (;;) { @@ -296,7 +296,7 @@ public class LinkedTransferQueue exte if (spins < 0) { QNode h = head.get(); // only spin if at head spins = ((h != null && h.next == s) ? - (mode == TIMEOUT? + ((mode == TIMEOUT) ? maxTimedSpins : maxUntimedSpins) : 0); } if (spins > 0) @@ -487,7 +487,7 @@ public class LinkedTransferQueue exte public E take() throws InterruptedException { Object e = xfer(null, WAIT, 0); if (e != null) - return (E)e; + return (E) e; Thread.interrupted(); throw new InterruptedException(); } @@ -495,12 +495,12 @@ public class LinkedTransferQueue exte public E poll(long timeout, TimeUnit unit) throws InterruptedException { Object e = xfer(null, TIMEOUT, unit.toNanos(timeout)); if (e != null || !Thread.interrupted()) - return (E)e; + return (E) e; throw new InterruptedException(); } public E poll() { - return (E)fulfill(null); + return (E) fulfill(null); } public int drainTo(Collection c) { @@ -603,7 +603,7 @@ public class LinkedTransferQueue exte Object x = q.get(); QNode s = q.next; if (x != null && q != x && q != s) { - nextItem = (E)x; + nextItem = (E) x; snext = s; pnext = pred; next = q; @@ -650,7 +650,7 @@ public class LinkedTransferQueue exte if (!p.isData) return null; if (x != null) - return (E)x; + return (E) x; } } } @@ -765,6 +765,7 @@ public class LinkedTransferQueue exte /** * Reconstitute the Queue instance from a stream (that is, * deserialize it). + * * @param s the stream */ private void readObject(java.io.ObjectInputStream s) @@ -772,7 +773,7 @@ public class LinkedTransferQueue exte s.defaultReadObject(); resetHeadAndTail(); for (;;) { - E item = (E)s.readObject(); + E item = (E) s.readObject(); if (item == null) break; else @@ -784,11 +785,11 @@ public class LinkedTransferQueue exte // Support for resetting head/tail while deserializing private void resetHeadAndTail() { QNode dummy = new QNode(null, false); - _unsafe.putObjectVolatile(this, headOffset, + UNSAFE.putObjectVolatile(this, headOffset, new PaddedAtomicReference(dummy)); - _unsafe.putObjectVolatile(this, tailOffset, + UNSAFE.putObjectVolatile(this, tailOffset, new PaddedAtomicReference(dummy)); - _unsafe.putObjectVolatile(this, cleanMeOffset, + UNSAFE.putObjectVolatile(this, cleanMeOffset, new PaddedAtomicReference(null)); } @@ -818,17 +819,17 @@ public class LinkedTransferQueue exte private static long fieldOffset(String fieldName) throws NoSuchFieldException { - return _unsafe.objectFieldOffset + return UNSAFE.objectFieldOffset (LinkedTransferQueue.class.getDeclaredField(fieldName)); } - private static final Unsafe _unsafe; + private static final Unsafe UNSAFE; private static final long headOffset; private static final long tailOffset; private static final long cleanMeOffset; static { try { - _unsafe = getUnsafe(); + UNSAFE = getUnsafe(); headOffset = fieldOffset("head"); tailOffset = fieldOffset("tail"); cleanMeOffset = fieldOffset("cleanMe");