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

Comparing jsr166/src/jsr166y/LinkedTransferQueue.java (file contents):
Revision 1.84 by jsr166, Wed May 25 16:08:03 2011 UTC vs.
Revision 1.92 by jsr166, Wed Jan 9 02:51:37 2013 UTC

# Line 301 | Line 301 | public class LinkedTransferQueue<E> exte
301       *    of less-contended queues.  During spins threads check their
302       *    interrupt status and generate a thread-local random number
303       *    to decide to occasionally perform a Thread.yield. While
304 <     *    yield has underdefined specs, we assume that might it help,
305 <     *    and will not hurt in limiting impact of spinning on busy
304 >     *    yield has underdefined specs, we assume that it might help,
305 >     *    and will not hurt, in limiting impact of spinning on busy
306       *    systems.  We also use smaller (1/2) spins for nodes that are
307       *    not known to be front but whose predecessors have not
308       *    blocked -- these "chained" spins avoid artifacts of
# Line 513 | Line 513 | public class LinkedTransferQueue<E> exte
513          static {
514              try {
515                  UNSAFE = getUnsafe();
516 <                Class k = Node.class;
516 >                Class<?> k = Node.class;
517                  itemOffset = UNSAFE.objectFieldOffset
518                      (k.getDeclaredField("item"));
519                  nextOffset = UNSAFE.objectFieldOffset
# Line 598 | Line 598 | public class LinkedTransferQueue<E> exte
598                                  break;        // unless slack < 2
599                          }
600                          LockSupport.unpark(p.waiter);
601 <                        return this.<E>cast(item);
601 >                        return LinkedTransferQueue.<E>cast(item);
602                      }
603                  }
604                  Node n = p.next;
# Line 676 | Line 676 | public class LinkedTransferQueue<E> exte
676              if (item != e) {                  // matched
677                  // assert item != s;
678                  s.forgetContents();           // avoid garbage
679 <                return this.<E>cast(item);
679 >                return LinkedTransferQueue.<E>cast(item);
680              }
681              if ((w.isInterrupted() || (timed && nanos <= 0)) &&
682                      s.casItem(e, s)) {        // cancel
# Line 757 | Line 757 | public class LinkedTransferQueue<E> exte
757              Object item = p.item;
758              if (p.isData) {
759                  if (item != null && item != p)
760 <                    return this.<E>cast(item);
760 >                    return LinkedTransferQueue.<E>cast(item);
761              }
762              else if (item == null)
763                  return null;
# Line 1016 | Line 1016 | public class LinkedTransferQueue<E> exte
1016       * return {@code false}.
1017       *
1018       * @return {@code true} (as specified by
1019 <     *  {@link BlockingQueue#offer(Object,long,TimeUnit) BlockingQueue.offer})
1019 >     *  {@link java.util.concurrent.BlockingQueue#offer(Object,long,TimeUnit)
1020 >     *  BlockingQueue.offer})
1021       * @throws NullPointerException if the specified element is null
1022       */
1023      public boolean offer(E e, long timeout, TimeUnit unit) {
# Line 1133 | Line 1134 | public class LinkedTransferQueue<E> exte
1134          if (c == this)
1135              throw new IllegalArgumentException();
1136          int n = 0;
1137 <        E e;
1137 <        while ( (e = poll()) != null) {
1137 >        for (E e; (e = poll()) != null;) {
1138              c.add(e);
1139              ++n;
1140          }
# Line 1151 | Line 1151 | public class LinkedTransferQueue<E> exte
1151          if (c == this)
1152              throw new IllegalArgumentException();
1153          int n = 0;
1154 <        E e;
1155 <        while (n < maxElements && (e = poll()) != null) {
1154 >        for (E e; n < maxElements && (e = poll()) != null;) {
1155              c.add(e);
1156              ++n;
1157          }
# Line 1259 | Line 1258 | public class LinkedTransferQueue<E> exte
1258       * {@code LinkedTransferQueue} is not capacity constrained.
1259       *
1260       * @return {@code Integer.MAX_VALUE} (as specified by
1261 <     *         {@link BlockingQueue#remainingCapacity()})
1261 >     *         {@link java.util.concurrent.BlockingQueue#remainingCapacity()
1262 >     *         BlockingQueue.remainingCapacity})
1263       */
1264      public int remainingCapacity() {
1265          return Integer.MAX_VALUE;
# Line 1291 | Line 1291 | public class LinkedTransferQueue<E> exte
1291          throws java.io.IOException, ClassNotFoundException {
1292          s.defaultReadObject();
1293          for (;;) {
1294 <            @SuppressWarnings("unchecked") E item = (E) s.readObject();
1294 >            @SuppressWarnings("unchecked")
1295 >            E item = (E) s.readObject();
1296              if (item == null)
1297                  break;
1298              else
# Line 1308 | Line 1309 | public class LinkedTransferQueue<E> exte
1309      static {
1310          try {
1311              UNSAFE = getUnsafe();
1312 <            Class k = LinkedTransferQueue.class;
1312 >            Class<?> k = LinkedTransferQueue.class;
1313              headOffset = UNSAFE.objectFieldOffset
1314                  (k.getDeclaredField("head"));
1315              tailOffset = UNSAFE.objectFieldOffset
# Line 1330 | Line 1331 | public class LinkedTransferQueue<E> exte
1331      static sun.misc.Unsafe getUnsafe() {
1332          try {
1333              return sun.misc.Unsafe.getUnsafe();
1334 <        } catch (SecurityException se) {
1335 <            try {
1336 <                return java.security.AccessController.doPrivileged
1337 <                    (new java.security
1338 <                     .PrivilegedExceptionAction<sun.misc.Unsafe>() {
1339 <                        public sun.misc.Unsafe run() throws Exception {
1340 <                            java.lang.reflect.Field f = sun.misc
1341 <                                .Unsafe.class.getDeclaredField("theUnsafe");
1342 <                            f.setAccessible(true);
1343 <                            return (sun.misc.Unsafe) f.get(null);
1344 <                        }});
1345 <            } catch (java.security.PrivilegedActionException e) {
1346 <                throw new RuntimeException("Could not initialize intrinsics",
1347 <                                           e.getCause());
1348 <            }
1334 >        } catch (SecurityException tryReflectionInstead) {}
1335 >        try {
1336 >            return java.security.AccessController.doPrivileged
1337 >            (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
1338 >                public sun.misc.Unsafe run() throws Exception {
1339 >                    Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
1340 >                    for (java.lang.reflect.Field f : k.getDeclaredFields()) {
1341 >                        f.setAccessible(true);
1342 >                        Object x = f.get(null);
1343 >                        if (k.isInstance(x))
1344 >                            return k.cast(x);
1345 >                    }
1346 >                    throw new NoSuchFieldError("the Unsafe");
1347 >                }});
1348 >        } catch (java.security.PrivilegedActionException e) {
1349 >            throw new RuntimeException("Could not initialize intrinsics",
1350 >                                       e.getCause());
1351          }
1352      }
1350
1353   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines