private void doAdd(@NotNull T element, @Nullable ModalityState state, boolean atHead) {
    synchronized (myQueue) {
      Pair<T, ModalityState> pair = Pair.create(element, state);
      if (atHead) {
        myQueue.addFirst(pair);
      }
      else {
        myQueue.add(pair);
      }
      startProcessing();
    }
  }
private void doAdd(@NotNull T element, @Nullable ModalityState state, boolean atHead)