core/src/main/java/com/orientechnologies/common/concur/lock/ScalableRWLock.java
public boolean sharedTryLockNanos(long nanosTimeout) {
    final long lastTime = System.nanoTime();
    ReadersEntry localEntry = entry.get();
    // Initialize a new Reader-state for this thread if needed
    if (localEntry == null) {
      localEntry = addState();
    }

    final AtomicInteger currentReadersState = localEntry.state;
    while (true) {
      currentReadersState.set(SRWL_STATE_READING);
      if (!stampedLock.isWriteLocked()) {
        // Acquired lock in read-only mode
        return true;
      } else {
        // Go back to SRWL_STATE_NOT_READING to avoid blocking a Writer
        // and then check if this is a downgrade.
        currentReadersState.set(SRWL_STATE_NOT_READING);

        if (nanosTimeout <= 0)
          return false;
        if (System.nanoTime() - lastTime < nanosTimeout) {
          Thread.yield();
        } else {
          return false;
        }
      }
    }
  }
public boolean sharedTryLockNanos(long nanosTimeout) {
    final long lastTime = System.nanoTime();
    ReadersEntry localEntry = entry.get();
    // Initialize a new Reader-state for this thread if needed
    if (localEntry == null) {
      localEntry = addState();
    }

    final AtomicInteger currentReadersState = localEntry.state;
    while (true) {
      currentReadersState.set(SRWL_STATE_READING);
      if (!stampedLock.isWriteLocked()) {
        // Acquired lock in read-only mode
        return true;
      } else {
        // Go back to SRWL_STATE_NOT_READING to avoid blocking a Writer
        // and then check if this is a downgrade.
        currentReadersState.set(SRWL_STATE_NOT_READING);

        if (nanosTimeout <= 0)
          return false;
        if (System.nanoTime() - lastTime < nanosTimeout) {
          Thread.yield();
        } else {
          return false;
        }
      }
    }
  }
Acquires the read lock if the write lock is not held by
another thread within the given waiting time.
<p>Acquires the read lock if the write lock is not held by
another thread and returns immediately with the value
{@code true}.
<p>If the write lock is held by another thread then the
current thread yields execution until one of two things happens:
<ul>
<li>The read lock is acquired by the current thread; or
<li>The specified waiting time elapses.
</ul>
<p>If the read lock is acquired then the value {@code true} is
returned.

@param nanosTimeout the time to wait for the read lock in nanoseconds

@return {@code true} if the read lock was acquired