521 Object x;
522 return d != haveData && (x = item) != this && (x != null) == d;
523 }
524
525 /**
526 * Tries to artificially match a data node -- used by remove.
527 */
528 final boolean tryMatchData() {
529 // assert isData;
530 Object x = item;
531 if (x != null && x != this && casItem(x, null)) {
532 LockSupport.unpark(waiter);
533 return true;
534 }
535 return false;
536 }
537
538 private static final long serialVersionUID = -3375979862319811754L;
539
540 // Unsafe mechanics
541 private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
542 private static final long ITEM;
543 private static final long NEXT;
544 private static final long WAITER;
545 static {
546 try {
547 ITEM = U.objectFieldOffset
548 (Node.class.getDeclaredField("item"));
549 NEXT = U.objectFieldOffset
550 (Node.class.getDeclaredField("next"));
551 WAITER = U.objectFieldOffset
552 (Node.class.getDeclaredField("waiter"));
553 } catch (ReflectiveOperationException e) {
554 throw new Error(e);
555 }
556 }
557 }
558
559 /** head of the queue; null until first enqueue */
560 transient volatile Node head;
561
1547 * @param s the stream
1548 * @throws ClassNotFoundException if the class of a serialized object
1549 * could not be found
1550 * @throws java.io.IOException if an I/O error occurs
1551 */
1552 private void readObject(java.io.ObjectInputStream s)
1553 throws java.io.IOException, ClassNotFoundException {
1554 s.defaultReadObject();
1555 for (;;) {
1556 @SuppressWarnings("unchecked")
1557 E item = (E) s.readObject();
1558 if (item == null)
1559 break;
1560 else
1561 offer(item);
1562 }
1563 }
1564
1565 // Unsafe mechanics
1566
1567 private static final sun.misc.Unsafe U = sun.misc.Unsafe.getUnsafe();
1568 private static final long HEAD;
1569 private static final long TAIL;
1570 private static final long SWEEPVOTES;
1571 static {
1572 try {
1573 HEAD = U.objectFieldOffset
1574 (LinkedTransferQueue.class.getDeclaredField("head"));
1575 TAIL = U.objectFieldOffset
1576 (LinkedTransferQueue.class.getDeclaredField("tail"));
1577 SWEEPVOTES = U.objectFieldOffset
1578 (LinkedTransferQueue.class.getDeclaredField("sweepVotes"));
1579 } catch (ReflectiveOperationException e) {
1580 throw new Error(e);
1581 }
1582
1583 // Reduce the risk of rare disastrous classloading in first call to
1584 // LockSupport.park: https://bugs.openjdk.java.net/browse/JDK-8074773
1585 Class<?> ensureLoaded = LockSupport.class;
1586 }
1587 }
|
521 Object x;
522 return d != haveData && (x = item) != this && (x != null) == d;
523 }
524
525 /**
526 * Tries to artificially match a data node -- used by remove.
527 */
528 final boolean tryMatchData() {
529 // assert isData;
530 Object x = item;
531 if (x != null && x != this && casItem(x, null)) {
532 LockSupport.unpark(waiter);
533 return true;
534 }
535 return false;
536 }
537
538 private static final long serialVersionUID = -3375979862319811754L;
539
540 // Unsafe mechanics
541 private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
542 private static final long ITEM;
543 private static final long NEXT;
544 private static final long WAITER;
545 static {
546 try {
547 ITEM = U.objectFieldOffset
548 (Node.class.getDeclaredField("item"));
549 NEXT = U.objectFieldOffset
550 (Node.class.getDeclaredField("next"));
551 WAITER = U.objectFieldOffset
552 (Node.class.getDeclaredField("waiter"));
553 } catch (ReflectiveOperationException e) {
554 throw new Error(e);
555 }
556 }
557 }
558
559 /** head of the queue; null until first enqueue */
560 transient volatile Node head;
561
1547 * @param s the stream
1548 * @throws ClassNotFoundException if the class of a serialized object
1549 * could not be found
1550 * @throws java.io.IOException if an I/O error occurs
1551 */
1552 private void readObject(java.io.ObjectInputStream s)
1553 throws java.io.IOException, ClassNotFoundException {
1554 s.defaultReadObject();
1555 for (;;) {
1556 @SuppressWarnings("unchecked")
1557 E item = (E) s.readObject();
1558 if (item == null)
1559 break;
1560 else
1561 offer(item);
1562 }
1563 }
1564
1565 // Unsafe mechanics
1566
1567 private static final jdk.internal.misc.Unsafe U = jdk.internal.misc.Unsafe.getUnsafe();
1568 private static final long HEAD;
1569 private static final long TAIL;
1570 private static final long SWEEPVOTES;
1571 static {
1572 try {
1573 HEAD = U.objectFieldOffset
1574 (LinkedTransferQueue.class.getDeclaredField("head"));
1575 TAIL = U.objectFieldOffset
1576 (LinkedTransferQueue.class.getDeclaredField("tail"));
1577 SWEEPVOTES = U.objectFieldOffset
1578 (LinkedTransferQueue.class.getDeclaredField("sweepVotes"));
1579 } catch (ReflectiveOperationException e) {
1580 throw new Error(e);
1581 }
1582
1583 // Reduce the risk of rare disastrous classloading in first call to
1584 // LockSupport.park: https://bugs.openjdk.java.net/browse/JDK-8074773
1585 Class<?> ensureLoaded = LockSupport.class;
1586 }
1587 }
|