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

final boolean tryReadLock ( ) { Thread current = Thread . currentThread ( ) ; for ( ; ; ) { int c = getState ( ) ; if ( exclusiveCount ( c ) != 0 && getExclusiveOwnerThread ( ) != current ) return false ; int r = sharedCount ( c ) ; if ( r == MAX_COUNT ) throw new Error ( "Maximum lock count exceeded" ) ; if ( compareAndSetState ( c , c + SHARED_UNIT ) ) { if ( r == 0 ) { firstReader = current ; firstReaderHoldCount = 1 ; } else if ( firstReader == current ) { firstReaderHoldCount ++ ; } else { HoldCounter rh = cachedHoldCounter ; if ( rh == null || rh . tid != current . getId ( ) ) cachedHoldCounter = rh = readHolds . get ( ) ; else if ( rh . count == 0 ) readHolds . set ( rh ) ; rh . count ++ ; } return true ; } } }
performs trylock for read , enabling barging in both modes . this is identical in effect to tryacquireshared except for lack of calls to readershouldblock .
