final int fullTryAcquireShared(Thread current){
  HoldCounter rh=null;
  for (; ; ) {
    int c=getState();
    if (exclusiveCount(c) != 0) {
      if (getExclusiveOwnerThread() != current)       return -1;
    }
 else     if (readerShouldBlock()) {
      if (firstReader == current) {
      }
 else {
        if (rh == null) {
          rh=cachedHoldCounter;
          if (rh == null || rh.tid != current.getId()) {
            rh=readHolds.get();
            if (rh.count == 0)             readHolds.remove();
          }
        }
        if (rh.count == 0)         return -1;
      }
    }
    if (sharedCount(c) == MAX_COUNT)     throw new Error("Maximum lock count exceeded");
    if (compareAndSetState(c,c + SHARED_UNIT)) {
      if (sharedCount(c) == 0) {
        firstReader=current;
        firstReaderHoldCount=1;
      }
 else       if (firstReader == current) {
        firstReaderHoldCount++;
      }
 else {
        if (rh == null)         rh=cachedHoldCounter;
        if (rh == null || rh.tid != current.getId())         rh=readHolds.get();
 else         if (rh.count == 0)         readHolds.set(rh);
        rh.count++;
        cachedHoldCounter=rh;
      }
      return 1;
    }
  }
}

final int fullTryAcquireShared ( Thread current ) { HoldCounter rh = null ; for ( ; ; ) { int c = getState ( ) ; if ( exclusiveCount ( c ) != 0 ) { if ( getExclusiveOwnerThread ( ) != current ) return - 1 ; } else if ( readerShouldBlock ( ) ) { if ( firstReader == current ) { } else { if ( rh == null ) { rh = cachedHoldCounter ; if ( rh == null || rh . tid != current . getId ( ) ) { rh = readHolds . get ( ) ; if ( rh . count == 0 ) readHolds . remove ( ) ; } } if ( rh . count == 0 ) return - 1 ; } } if ( sharedCount ( c ) == MAX_COUNT ) throw new Error ( "Maximum lock count exceeded" ) ; if ( compareAndSetState ( c , c + SHARED_UNIT ) ) { if ( sharedCount ( c ) == 0 ) { firstReader = current ; firstReaderHoldCount = 1 ; } else if ( firstReader == current ) { firstReaderHoldCount ++ ; } else { if ( rh == null ) rh = cachedHoldCounter ; if ( rh == null || rh . tid != current . getId ( ) ) rh = readHolds . get ( ) ; else if ( rh . count == 0 ) readHolds . set ( rh ) ; rh . count ++ ; cachedHoldCounter = rh ; } return 1 ; } } }
full version of acquire for reads , that handles cas misses and reentrant reads not dealt with in tryacquireshared .
