core/src/main/java/com/orientechnologies/common/concur/lock/OReadersWriterSpinLock.java
public boolean tryAcquireReadLock(long timeout) {
    final OModifiableInteger lHolds = lockHolds.get();

    final int holds = lHolds.intValue();
    if (holds > 0) {
      // we have already acquire read lock
      lHolds.increment();
      return true;
    } else if (holds < 0) {
      // write lock is acquired before, do nothing
      return true;
    }

    distributedCounter.increment();

    WNode wNode = tail.get();

    final long start = System.nanoTime();
    while (wNode.locked) {
      distributedCounter.decrement();

      while (wNode.locked && wNode == tail.get()) {
        wNode.waitingReaders.put(Thread.currentThread(), Boolean.TRUE);

        if (wNode.locked && wNode == tail.get()) {
          final long parkTimeout = timeout - (System.nanoTime() - start);
          if (parkTimeout > 0) {
            LockSupport.parkNanos(this, parkTimeout);
          } else {
            return false;
          }
        }

        wNode = tail.get();

        if (System.nanoTime() - start > timeout) {
          return false;
        }
      }

      distributedCounter.increment();

      wNode = tail.get();
      if (System.nanoTime() - start > timeout) {
        distributedCounter.decrement();

        return false;
      }
    }

    lHolds.increment();
    assert lHolds.intValue() == 1;

    return true;
  }
public boolean tryAcquireReadLock(long timeout) {
    final OModifiableInteger lHolds = lockHolds.get();

    final int holds = lHolds.intValue();
    if (holds > 0) {
      // we have already acquire read lock
      lHolds.increment();
      return true;
    } else if (holds < 0) {
      // write lock is acquired before, do nothing
      return true;
    }

    distributedCounter.increment();

    WNode wNode = tail.get();

    final long start = System.nanoTime();
    while (wNode.locked) {
      distributedCounter.decrement();

      while (wNode.locked && wNode == tail.get()) {
        wNode.waitingReaders.put(Thread.currentThread(), Boolean.TRUE);

        if (wNode.locked && wNode == tail.get()) {
          final long parkTimeout = timeout - (System.nanoTime() - start);
          if (parkTimeout > 0) {
            LockSupport.parkNanos(this, parkTimeout);
          } else {
            return false;
          }
        }

        wNode = tail.get();

        if (System.nanoTime() - start > timeout) {
          return false;
        }
      }

      distributedCounter.increment();

      wNode = tail.get();
      if (System.nanoTime() - start > timeout) {
        distributedCounter.decrement();

        return false;
      }
    }

    lHolds.increment();
    assert lHolds.intValue() == 1;

    return true;
  }
Tries to acquire lock during provided interval of time and returns either if provided time interval was passed or
if lock was acquired.

@param timeout Timeout during of which we should wait for read lock.

@return <code>true</code> if read lock was acquired.