/** * Creates a {@code LinkedTransferQueue} * initially containing the elements of the given collection, * added in traversal order of the collection's iterator. * * @param c the collection of elements to initially contain * @throws NullPointerException if the specified collection or any * of its elements are null */ public LinkedTransferQueue(Collection<? extends E> c) { this(); addAll(c); }
for (Node q = p; q != h; ) { if (head == h && casHead(h, n == null ? q : n)) { h.forgetNext(); break; return LinkedTransferQueue.<E>cast(item); if (s == null) s = new Node(e, haveData); Node pred = tryAppend(s, haveData); if (pred == null) continue retry; // lost race vs opposite mode if (how != ASYNC) return awaitMatch(s, pred, e, (how == TIMED), nanos);
if (hn == null) return; // now empty if (hn != h && casHead(h, hn)) int v = sweepVotes; if (v < SWEEP_THRESHOLD) { if (casSweepVotes(v, v + 1)) break; } else if (casSweepVotes(v, 0)) { sweep(); break;
/** * Returns the item in the first unmatched node with isData; or * null if none. Used by peek. */ private E firstDataItem() { for (Node p = head; p != null; p = succ(p)) { Object item = p.item; if (p.isData) { if (item != null && item != p) return LinkedTransferQueue.<E>cast(item); } else if (item == null) return null; } return null; }
public int getWaitingConsumerCount() { return countOfMode(false); }
public boolean hasWaitingConsumer() { return firstOfMode(false) != null; }
public E peek() { return firstDataItem(); }
/** * Removes a single instance of the specified element from this queue, * if it is present. More formally, removes an element {@code e} such * that {@code o.equals(e)}, if this queue contains one or more such * elements. * Returns {@code true} if this queue contained the specified element * (or equivalently, if this queue changed as a result of the call). * * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ public boolean remove(Object o) { return findAndRemove(o); }
/** * Returns the item in the first unmatched node with isData; or * null if none. Used by peek. */ private E firstDataItem() { for (Node p = head; p != null; p = succ(p)) { Object item = p.item; if (p.isData) { if (item != null && item != p) return LinkedTransferQueue.<E>cast(item); } else if (item == null) return null; } return null; }
public int getWaitingConsumerCount() { return countOfMode(false); }
public boolean hasWaitingConsumer() { return firstOfMode(false) != null; }
public E peek() { return firstDataItem(); }
/** * Removes a single instance of the specified element from this queue, * if it is present. More formally, removes an element {@code e} such * that {@code o.equals(e)}, if this queue contains one or more such * elements. * Returns {@code true} if this queue contained the specified element * (or equivalently, if this queue changed as a result of the call). * * @param o element to be removed from this queue, if present * @return {@code true} if this queue changed as a result of the call */ public boolean remove(Object o) { return findAndRemove(o); }
for (Node q = p; q != h; ) { if (head == h && casHead(h, n == null ? q : n)) { h.forgetNext(); break; return LinkedTransferQueue.<E>cast(item); if (s == null) s = new Node(e, haveData); Node pred = tryAppend(s, haveData); if (pred == null) continue retry; // lost race vs opposite mode if (how != ASYNC) return awaitMatch(s, pred, e, (how == TIMED), nanos);
if (hn == null) return; // now empty if (hn != h && casHead(h, hn)) int v = sweepVotes; if (v < SWEEP_THRESHOLD) { if (casSweepVotes(v, v + 1)) break; } else if (casSweepVotes(v, 0)) { sweep(); break;