core/src/main/java/com/orientechnologies/common/concur/lock/ScalableRWLock.java
public void exclusiveLock() {
    // Try to acquire the lock in write-mode
    stampedLock.writeLock();

    // We can only do this after writerOwner has been set to the current thread
    AtomicInteger[] localReadersStateArray = readersStateArrayRef.get();
    if (localReadersStateArray == null) {
      // Set to dummyArray before scanning the readersStateList to impose
      // a linearizability condition
      readersStateArrayRef.set(dummyArray);
      // Copy readersStateList to an array
      localReadersStateArray = readersStateList.toArray(new AtomicInteger[readersStateList.size()]);
      readersStateArrayRef.compareAndSet(dummyArray, localReadersStateArray);
    }

    // Scan the array of Reader states
    for (AtomicInteger readerState : localReadersStateArray) {
      while (readerState != null && readerState.get() == SRWL_STATE_READING) {
        Thread.yield();
      }
    }
  }
public void exclusiveLock() {
    // Try to acquire the lock in write-mode
    stampedLock.writeLock();

    // We can only do this after writerOwner has been set to the current thread
    AtomicInteger[] localReadersStateArray = readersStateArrayRef.get();
    if (localReadersStateArray == null) {
      // Set to dummyArray before scanning the readersStateList to impose
      // a linearizability condition
      readersStateArrayRef.set(dummyArray);
      // Copy readersStateList to an array
      localReadersStateArray = readersStateList.toArray(new AtomicInteger[readersStateList.size()]);
      readersStateArrayRef.compareAndSet(dummyArray, localReadersStateArray);
    }

    // Scan the array of Reader states
    for (AtomicInteger readerState : localReadersStateArray) {
      while (readerState != null && readerState.get() == SRWL_STATE_READING) {
        Thread.yield();
      }
    }
  }
Acquires the write lock.
<p>Acquires the write lock if neither the read nor write lock
are held by another thread and returns immediately, setting
the write lock {@code reentrantWriterCount} to one.
<p>If the current thread already holds the write lock then the
{@code reentrantWriterCount} is incremented by one and the method
returns immediately.
<p>If the lock is held by another thread, then the current
thread yields and lies dormant until the write lock has been acquired,
at which time the {@code reentrantWriterCount} is set to one.