--- jsr166/src/jsr166y/LinkedTransferQueue.java 2010/09/01 21:43:08 1.74 +++ jsr166/src/jsr166y/LinkedTransferQueue.java 2010/09/09 16:52:49 1.78 @@ -344,18 +344,18 @@ public class LinkedTransferQueue exte * When these cases arise, rather than always retraversing the * entire list to find an actual predecessor to unlink (which * won't help for case (1) anyway), we record a conservative - * estimate of possible unsplice failures (in "sweepVotes"). We - * trigger a full sweep when the estimate exceeds a threshold - * indicating the maximum number of estimated removal failures to - * tolerate before sweeping through, unlinking cancelled nodes - * that were not unlinked upon initial removal. We perform sweeps - * by the thread hitting threshold (rather than background threads - * or by spreading work to other threads) because in the main - * contexts in which removal occurs, the caller is already - * timed-out, cancelled, or performing a potentially O(n) - * operation (i.e., remove(x)), none of which are time-critical - * enough to warrant the overhead that alternatives would impose - * on other threads. + * estimate of possible unsplice failures (in "sweepVotes"). + * We trigger a full sweep when the estimate exceeds a threshold + * ("SWEEP_THRESHOLD") indicating the maximum number of estimated + * removal failures to tolerate before sweeping through, unlinking + * cancelled nodes that were not unlinked upon initial removal. + * We perform sweeps by the thread hitting threshold (rather than + * background threads or by spreading work to other threads) + * because in the main contexts in which removal occurs, the + * caller is already timed-out, cancelled, or performing a + * potentially O(n) operation (e.g. remove(x)), none of which are + * time-critical enough to warrant the overhead that alternatives + * would impose on other threads. * * Because the sweepVotes estimate is conservative, and because * nodes become unlinked "naturally" as they fall off the head of @@ -428,8 +428,8 @@ public class LinkedTransferQueue exte } /** - * Creates a new node. Uses relaxed write because item can only - * be seen if followed by CAS. + * Constructs a new node. Uses relaxed write because item can + * only be seen after publication via casNext. */ Node(Object item, boolean isData) { UNSAFE.putObject(this, itemOffset, item); // relaxed write @@ -877,7 +877,8 @@ public class LinkedTransferQueue exte } /** - * Unlinks matched nodes encountered in a traversal from head. + * Unlinks matched (typically cancelled) nodes encountered in a + * traversal from head. */ private void sweep() { for (Node p = head, s, n; p != null && (s = p.next) != null; ) { @@ -885,7 +886,7 @@ public class LinkedTransferQueue exte p = head; else if (!s.isMatched()) p = s; - else if ((n = s.next) == null) // trailing node is pinned + else if ((n = s.next) == null || s == n) // trailing node is pinned break; else p.casNext(s, n);