private Node addWaiter ( Node mode ) { Node node = new Node ( mode ) ; for ( ; ; ) { Node oldTail = tail ; if ( oldTail != null ) { U . putObject ( node , Node . PREV , oldTail ) ; if ( compareAndSetTail ( oldTail , node ) ) { oldTail . next = node ; return node ; } } else { initializeSyncQueue ( ) ; } } }
Creates and enqueues node for current thread and given mode .