@Nullable E awaitMatch(int start){
  for (int step=0, totalSpins=0; (step < ARENA_LENGTH) && (totalSpins < SPINS); step++) {
    int index=(start + step) & ARENA_MASK;
    AtomicReference<Object> slot=arena[index];
    Object found=slot.get();
    if (found == FREE) {
      if (slot.compareAndSet(FREE,WAITER)) {
        int slotSpins=0;
        for (; ; ) {
          found=slot.get();
          if ((found != WAITER) && slot.compareAndSet(found,FREE)) {
            @SuppressWarnings("unchecked") E e=(E)found;
            return e;
          }
 else           if ((slotSpins >= SPINS_PER_STEP) && (found == WAITER) && (slot.compareAndSet(WAITER,FREE))) {
            totalSpins+=slotSpins;
            break;
          }
          slotSpins++;
        }
      }
    }
 else     if ((found != WAITER) && slot.compareAndSet(found,FREE)) {
      @SuppressWarnings("unchecked") E e=(E)found;
      return e;
    }
  }
  return null;
}

@ Nullable E awaitMatch ( int start ) { for ( int step = 0 , totalSpins = 0 ; ( step < ARENA_LENGTH ) && ( totalSpins < SPINS ) ; step ++ ) { int index = ( start + step ) & ARENA_MASK ; AtomicReference < Object > slot = arena [ index ] ; Object found = slot . get ( ) ; if ( found == FREE ) { if ( slot . compareAndSet ( FREE , WAITER ) ) { int slotSpins = 0 ; for ( ; ; ) { found = slot . get ( ) ; if ( ( found != WAITER ) && slot . compareAndSet ( found , FREE ) ) { @ SuppressWarnings ( "unchecked" ) E e = ( E ) found ; return e ; } else if ( ( slotSpins >= SPINS_PER_STEP ) && ( found == WAITER ) && ( slot . compareAndSet ( WAITER , FREE ) ) ) { totalSpins += slotSpins ; break ; } slotSpins ++ ; } } } else if ( ( found != WAITER ) && slot . compareAndSet ( found , FREE ) ) { @ SuppressWarnings ( "unchecked" ) E e = ( E ) found ; return e ; } } return null ; }
waits for ( by spinning ) to have an element transfered from another thread . a marker is filled into an empty slot in the arena and spun on until it is replaced with an element or a per - slot spin limit is reached . this search and wait strategy is repeated by selecting another slot until a total spin limit is reached .
