/** * Returns a collection containing threads that may be waiting to acquire in * shared mode. This has the same properties as {@link #getQueuedThreads} * except that it only returns those threads waiting due to a shared acquire. * * @return the collection of threads */ public final Collection<Thread> getSharedQueuedThreads() { final ArrayList<Thread> list = new ArrayList<Thread>(); for (Node p = this.tail; p != null; p = p.prev) { if (p.isShared()) { final Thread t = p.thread; if (t != null) { list.add(t); } } } return list; }
/** * Returns a collection containing threads that may be waiting to acquire in * exclusive mode. This has the same properties as {@link #getQueuedThreads} * except that it only returns those threads waiting due to an exclusive * acquire. * * @return the collection of threads */ public final Collection<Thread> getExclusiveQueuedThreads() { final ArrayList<Thread> list = new ArrayList<Thread>(); for (Node p = this.tail; p != null; p = p.prev) { if (!p.isShared()) { final Thread t = p.thread; if (t != null) { list.add(t); } } } return list; }
if (s == null || s.isShared()) signalSharedWaiters();
/** * Returns {@code true} if the apparent first queued thread, if one * exists, is waiting in exclusive mode. If this method returns * {@code true}, and the current thread is attempting to acquire in * shared mode (that is, this method is invoked from {@link * TryLockObject#tryAcquireShared}) then it is guaranteed that the * current thread is not the first queued thread. Used only as a * heuristic in ReentrantReadWriteLock. */ public final boolean apparentlyFirstQueuedIsExclusive() { Node h, s; return (h = head) != null && (s = h.next) != null && !s.isShared() && s.thread != null; }