code: private Object xfer(Object e, int mode, long nanos) {
      boolean isData = e != null;
      QNode s = null;
      final PaddedAtomicReference<QNode> head = this.head;
      final PaddedAtomicReference<QNode> tail = this.tail;
  
      for (;;) {
        QNode t = tail.get();
        QNode h = head.get();
  
        if (t != null && (t == h || t.isData == isData)) {
          if (s == null) {
            s = new QNode(e, isData);
          }
          QNode last = t.next;
          if (last != null) {
            if (t == tail.get()) {
              tail.compareAndSet(t, last);
            }
          } else if (t.casNext(null, s)) {
            tail.compareAndSet(t, s);
            return awaitFulfill(t, s, e, mode, nanos);
          }
        }
  
        else if (h != null) {
          QNode first = h.next;
          if (t == tail.get() && first != null && advanceHead(h, first)) {
            Object x = first.get();
            if (x != first && first.compareAndSet(x, e)) {
              LockSupport.unpark(first.waiter);
              return isData ? e : x;
            }
          }
        }
      }
    }
docs: Puts or takes an item. Used for most queue operations (except poll() and tryTransfer()). See
  the similar code in SynchronousQueue for detailed explanation.
  
  @param e the item or if null, signifies that this is a take
  @param mode the wait mode: NOWAIT, TIMEOUT, WAIT
  @param nanos timeout in nanosecs, used only if mode is TIMEOUT
  @return an item, or null on failure