core/src/main/java/com/orientechnologies/common/concur/lock/ScalableRWLock.java
public void sharedLock() {
    ReadersEntry localEntry = entry.get();
    // Initialize a new Reader-state for this thread if needed
    if (localEntry == null) {
      localEntry = addState();
    }

    final AtomicInteger currentReadersState = localEntry.state;
    // The "optimistic" code path takes only two synchronized calls:
    // a set() on a cache line that should be held in exclusive mode
    // by the current thread, and a get() on a cache line that is shared.
    while (true) {
      currentReadersState.set(SRWL_STATE_READING);
      if (!stampedLock.isWriteLocked()) {
        // Acquired lock in read-only mode
        return;
      } else {
        // Go back to SRWL_STATE_NOT_READING to avoid blocking a Writer
        currentReadersState.set(SRWL_STATE_NOT_READING);
        // Some (other) thread is holding the write-lock, we must wait
        while (stampedLock.isWriteLocked()) {
          Thread.yield();
        }
      }
    }
  }
public void sharedLock() {
    ReadersEntry localEntry = entry.get();
    // Initialize a new Reader-state for this thread if needed
    if (localEntry == null) {
      localEntry = addState();
    }

    final AtomicInteger currentReadersState = localEntry.state;
    // The "optimistic" code path takes only two synchronized calls:
    // a set() on a cache line that should be held in exclusive mode
    // by the current thread, and a get() on a cache line that is shared.
    while (true) {
      currentReadersState.set(SRWL_STATE_READING);
      if (!stampedLock.isWriteLocked()) {
        // Acquired lock in read-only mode
        return;
      } else {
        // Go back to SRWL_STATE_NOT_READING to avoid blocking a Writer
        currentReadersState.set(SRWL_STATE_NOT_READING);
        // Some (other) thread is holding the write-lock, we must wait
        while (stampedLock.isWriteLocked()) {
          Thread.yield();
        }
      }
    }
  }
public void sharedLock ( ) { ReadersEntry localEntry = entry . get ( ) ; // Initialize a new Reader-state for this thread if needed if ( localEntry == null ) { localEntry = addState ( ) ; } final AtomicInteger currentReadersState = localEntry . state ; // The "optimistic" code path takes only two synchronized calls: // a set() on a cache line that should be held in exclusive mode // by the current thread, and a get() on a cache line that is shared. while ( true ) { currentReadersState . set ( SRWL_STATE_READING ) ; if ( ! stampedLock . isWriteLocked ( ) ) { // Acquired lock in read-only mode return ; } else { // Go back to SRWL_STATE_NOT_READING to avoid blocking a Writer currentReadersState . set ( SRWL_STATE_NOT_READING ) ; // Some (other) thread is holding the write-lock, we must wait while ( stampedLock . isWriteLocked ( ) ) { Thread . yield ( ) ; } } } }
Acquires the read lock.
<p>Acquires the read lock if the write lock is not held by
another thread and returns immediately.
<p>If the write lock is held by another thread then
the current thread yields until the write lock is released.
Acquires the read lock . <p > Acquires the read lock if the write lock is not held by another thread and returns immediately . <p > If the write lock is held by another thread then the current thread yields until the write lock is released .