QNode traversalHead ( ) { for ( ; ; ) { QNode t = this . tail . get ( ) ; QNode h = this . head . get ( ) ; if ( h != null && t != null ) { QNode last = t . next ; QNode first = h . next ; if ( t == this . tail . get ( ) ) { if ( last != null ) { this . tail . compareAndSet ( t , last ) ; } else if ( first != null ) { Object x = first . get ( ) ; if ( x == first ) { advanceHead ( h , first ) ; } else { return h ; } } else { return h ; } } } } }
Return head after performing any outstanding helping steps