src/java.base/share/classes/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java
equal
deleted
inserted
replaced
318 while (pred.waitStatus > 0) |
318 while (pred.waitStatus > 0) |
319 node.prev = pred = pred.prev; |
319 node.prev = pred = pred.prev; |
320 |
320 |
321 // predNext is the apparent node to unsplice. CASes below will |
321 // predNext is the apparent node to unsplice. CASes below will |
322 // fail if not, in which case, we lost race vs another cancel |
322 // fail if not, in which case, we lost race vs another cancel |
323 // or signal, so no further action is necessary. |
323 // or signal, so no further action is necessary, although with |
|
324 // a possibility that a cancelled node may transiently remain |
|
325 // reachable. |
324 Node predNext = pred.next; |
326 Node predNext = pred.next; |
325 |
327 |
326 // Can use unconditional write instead of CAS here. |
328 // Can use unconditional write instead of CAS here. |
327 // After this atomic step, other Nodes can skip past us. |
329 // After this atomic step, other Nodes can skip past us. |
328 // Before, we are free of interference from other threads. |
330 // Before, we are free of interference from other threads. |
910 * Queries whether any threads are waiting to acquire. Note that |
912 * Queries whether any threads are waiting to acquire. Note that |
911 * because cancellations due to interrupts and timeouts may occur |
913 * because cancellations due to interrupts and timeouts may occur |
912 * at any time, a {@code true} return does not guarantee that any |
914 * at any time, a {@code true} return does not guarantee that any |
913 * other thread will ever acquire. |
915 * other thread will ever acquire. |
914 * |
916 * |
915 * <p>In this implementation, this operation returns in |
|
916 * constant time. |
|
917 * |
|
918 * @return {@code true} if there may be other threads waiting to acquire |
917 * @return {@code true} if there may be other threads waiting to acquire |
919 */ |
918 */ |
920 public final boolean hasQueuedThreads() { |
919 public final boolean hasQueuedThreads() { |
921 return head != tail; |
920 for (Node p = tail, h = head; p != h && p != null; p = p.prev) |
|
921 if (p.waitStatus <= 0) |
|
922 return true; |
|
923 return false; |
922 } |
924 } |
923 |
925 |
924 /** |
926 /** |
925 * Queries whether any threads have ever contended to acquire this |
927 * Queries whether any threads have ever contended to acquire this |
926 * synchronizer; that is, if an acquire method has ever blocked. |
928 * synchronizer; that is, if an acquire method has ever blocked. |
1065 * current thread, and {@code false} if the current thread |
1067 * current thread, and {@code false} if the current thread |
1066 * is at the head of the queue or the queue is empty |
1068 * is at the head of the queue or the queue is empty |
1067 * @since 1.7 |
1069 * @since 1.7 |
1068 */ |
1070 */ |
1069 public final boolean hasQueuedPredecessors() { |
1071 public final boolean hasQueuedPredecessors() { |
1070 // The correctness of this depends on head being initialized |
1072 Node h, s; |
1071 // before tail and on head.next being accurate if the current |
1073 if ((h = head) != null) { |
1072 // thread is first in queue. |
1074 if ((s = h.next) == null || s.waitStatus > 0) { |
1073 Node t = tail; // Read fields in reverse initialization order |
1075 s = null; // traverse in case of concurrent cancellation |
1074 Node h = head; |
1076 for (Node p = tail; p != h && p != null; p = p.prev) { |
1075 Node s; |
1077 if (p.waitStatus <= 0) |
1076 return h != t && |
1078 s = p; |
1077 ((s = h.next) == null || s.thread != Thread.currentThread()); |
1079 } |
1078 } |
1080 } |
1079 |
1081 if (s != null && s.thread != Thread.currentThread()) |
|
1082 return true; |
|
1083 } |
|
1084 return false; |
|
1085 } |
1080 |
1086 |
1081 // Instrumentation and monitoring methods |
1087 // Instrumentation and monitoring methods |
1082 |
1088 |
1083 /** |
1089 /** |
1084 * Returns an estimate of the number of threads waiting to |
1090 * Returns an estimate of the number of threads waiting to |