src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
equal
deleted
inserted
replaced
798 while (pred.waitStatus > 0) |
798 while (pred.waitStatus > 0) |
799 node.prev = pred = pred.prev; |
799 node.prev = pred = pred.prev; |
800 |
800 |
801 // predNext is the apparent node to unsplice. CASes below will |
801 // predNext is the apparent node to unsplice. CASes below will |
802 // fail if not, in which case, we lost race vs another cancel |
802 // fail if not, in which case, we lost race vs another cancel |
803 // or signal, so no further action is necessary. |
803 // or signal, so no further action is necessary, although with |
|
804 // a possibility that a cancelled node may transiently remain |
|
805 // reachable. |
804 Node predNext = pred.next; |
806 Node predNext = pred.next; |
805 |
807 |
806 // Can use unconditional write instead of CAS here. |
808 // Can use unconditional write instead of CAS here. |
807 // After this atomic step, other Nodes can skip past us. |
809 // After this atomic step, other Nodes can skip past us. |
808 // Before, we are free of interference from other threads. |
810 // Before, we are free of interference from other threads. |
1390 * Queries whether any threads are waiting to acquire. Note that |
1392 * Queries whether any threads are waiting to acquire. Note that |
1391 * because cancellations due to interrupts and timeouts may occur |
1393 * because cancellations due to interrupts and timeouts may occur |
1392 * at any time, a {@code true} return does not guarantee that any |
1394 * at any time, a {@code true} return does not guarantee that any |
1393 * other thread will ever acquire. |
1395 * other thread will ever acquire. |
1394 * |
1396 * |
1395 * <p>In this implementation, this operation returns in |
|
1396 * constant time. |
|
1397 * |
|
1398 * @return {@code true} if there may be other threads waiting to acquire |
1397 * @return {@code true} if there may be other threads waiting to acquire |
1399 */ |
1398 */ |
1400 public final boolean hasQueuedThreads() { |
1399 public final boolean hasQueuedThreads() { |
1401 return head != tail; |
1400 for (Node p = tail, h = head; p != h && p != null; p = p.prev) |
|
1401 if (p.waitStatus <= 0) |
|
1402 return true; |
|
1403 return false; |
1402 } |
1404 } |
1403 |
1405 |
1404 /** |
1406 /** |
1405 * Queries whether any threads have ever contended to acquire this |
1407 * Queries whether any threads have ever contended to acquire this |
1406 * synchronizer; that is, if an acquire method has ever blocked. |
1408 * synchronizer; that is, if an acquire method has ever blocked. |
1545 * current thread, and {@code false} if the current thread |
1547 * current thread, and {@code false} if the current thread |
1546 * is at the head of the queue or the queue is empty |
1548 * is at the head of the queue or the queue is empty |
1547 * @since 1.7 |
1549 * @since 1.7 |
1548 */ |
1550 */ |
1549 public final boolean hasQueuedPredecessors() { |
1551 public final boolean hasQueuedPredecessors() { |
1550 // The correctness of this depends on head being initialized |
1552 Node h, s; |
1551 // before tail and on head.next being accurate if the current |
1553 if ((h = head) != null) { |
1552 // thread is first in queue. |
1554 if ((s = h.next) == null || s.waitStatus > 0) { |
1553 Node t = tail; // Read fields in reverse initialization order |
1555 s = null; // traverse in case of concurrent cancellation |
1554 Node h = head; |
1556 for (Node p = tail; p != h && p != null; p = p.prev) { |
1555 Node s; |
1557 if (p.waitStatus <= 0) |
1556 return h != t && |
1558 s = p; |
1557 ((s = h.next) == null || s.thread != Thread.currentThread()); |
1559 } |
1558 } |
1560 } |
1559 |
1561 if (s != null && s.thread != Thread.currentThread()) |
|
1562 return true; |
|
1563 } |
|
1564 return false; |
|
1565 } |
1560 |
1566 |
1561 // Instrumentation and monitoring methods |
1567 // Instrumentation and monitoring methods |
1562 |
1568 |
1563 /** |
1569 /** |
1564 * Returns an estimate of the number of threads waiting to |
1570 * Returns an estimate of the number of threads waiting to |