code: private int getQueueIndex(Object[] queue, java.util.concurrent.atomic.AtomicInteger counter, boolean increment) {
  
          // fast path for single element array
          if (queue.length == 1) {
              return 0;
          } else if (increment) {
  
              // get the next long value from counter
              int i = counter.incrementAndGet();
  
              // rollover logic to make sure we stay within
              // the bounds of an integer. Not important that
              // this logic is highly accurate, ballpark is okay.
              if (i > MAX_COUNTER) {
                  if (counter.compareAndSet(i, 0)) {
                      System.out.println("BoundedBuffer: reset counter to 0");
                  }
              }
              return i % queue.length;
          } else {
              return counter.get() % queue.length;
          }
      }
docs: has waited.