public final boolean tryLockForRead ( L locker ) { int state = mState ; if ( state >= 0 ) { // no write lock is held if ( isReadWriteFirst ( ) || isReadLockHeld ( locker ) ) { do { if ( incrementReadLocks ( state ) ) { adjustReadLockCount ( locker , 1 ) ; return true ; } // keep looping on CAS failure if a reader or upgrader mucked with the state } while ( ( state = mState ) >= 0 ) ; } } else if ( mOwner == locker ) { // keep looping on CAS failure if a reader or upgrader mucked with the state while ( ! incrementReadLocks ( state ) ) { state = mState ; } adjustReadLockCount ( locker , 1 ) ; return true ; } return false ; }
Attempt to immediately acquire a shared read lock .