* some other strand(s) concurrently performed setHead in
* between some of our reads. We try this twice before
* resorting to traversal.
*/
Node h, s;
Strand st;
if (((h = head) != null && (s = h.next) != null &&
s.prev == head && (st = s.strand) != null) ||
((h = head) != null && (s = h.next) != null &&
s.prev == head && (st = s.strand) != null))
return st;
/*
* Head's next field might not have been set yet, or may have
* been unset after setHead. So we must check to see if tail
* is actually first node. If not, we continue on, safely
* traversing from tail back to head to find first,
* guaranteeing termination.
*/
Node t = tail;
Strand firstStrand = null;
while (t != null && t != head) {
Strand tt = t.strand;
if (tt != null)
firstStrand = tt;
t = t.prev;
}
return firstStrand;