/** * 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() { ArrayList<Thread> list = new ArrayList<Thread>(); for (Node p = tail; p != null; p = p.prev) { if (p.isShared()) { 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() { ArrayList<Thread> list = new ArrayList<Thread>(); for (Node p = tail; p != null; p = p.prev) { if (!p.isShared()) { Thread t = p.thread; if (t != null) list.add(t); } } return list; }
/** * Sets head of queue, and checks if successor may be waiting in shared mode, * if so propagating if propagate > 0. * * @param node * the node * @param propagate * the return value from a tryAcquireShared */ private void setHeadAndPropagate(Node node, int propagate) { setHead(node); if (propagate > 0 && node.waitStatus != 0) { /* * Don't bother fully figuring out successor. If it * looks null, call unparkSuccessor anyway to be safe. */ Node s = node.next; if (s == null || s.isShared()) unparkSuccessor(node); } }