Exemplo n.º 1
0
  public void releaseExclusiveLock(final int value) {
    final int index = index(value);
    if (useSpinLock) {
      OReadersWriterSpinLock spinLock = spinLocks[index];
      spinLock.releaseWriteLock();
      return;
    }

    final ReadWriteLock rwLock = locks[index];
    rwLock.writeLock().unlock();
  }
Exemplo n.º 2
0
 public void unlockAllExclusive() {
   if (useSpinLock) {
     for (OReadersWriterSpinLock spinLock : spinLocks) {
       spinLock.releaseWriteLock();
     }
   } else {
     for (ReadWriteLock readWriteLock : locks) {
       readWriteLock.writeLock().unlock();
     }
   }
 }
Exemplo n.º 3
0
 public void lockAllExclusive() {
   if (useSpinLock) {
     for (OReadersWriterSpinLock spinLock : spinLocks) {
       spinLock.acquireWriteLock();
     }
   } else {
     for (ReadWriteLock readWriteLock : locks) {
       readWriteLock.writeLock().lock();
     }
   }
 }
Exemplo n.º 4
0
  public void releaseExclusiveLock(final long value) {
    final int hashCode = longHashCode(value);
    final int index = index(hashCode);

    if (useSpinLock) {
      OReadersWriterSpinLock spinLock = spinLocks[index];
      spinLock.releaseWriteLock();
      return;
    }

    final ReadWriteLock rwLock = locks[index];

    final Lock lock = rwLock.writeLock();
    lock.unlock();
  }
Exemplo n.º 5
0
  public void releaseExclusiveLock(final T value) {
    final int index;
    if (value == null) index = 0;
    else index = index(value.hashCode());

    if (useSpinLock) {
      OReadersWriterSpinLock spinLock = spinLocks[index];
      spinLock.releaseWriteLock();
      return;
    }

    final ReadWriteLock rwLock = locks[index];

    final Lock lock = rwLock.writeLock();
    lock.unlock();
  }
Exemplo n.º 6
0
  public Lock acquireSharedLock(int value) {
    final int index = index(value);

    if (useSpinLock) {
      OReadersWriterSpinLock spinLock = spinLocks[index];
      spinLock.acquireReadLock();

      return new SpinLockWrapper(true, spinLock);
    }

    final ReadWriteLock rwLock = locks[index];

    final Lock lock = rwLock.readLock();
    lock.lock();
    return lock;
  }
Exemplo n.º 7
0
  public Lock acquireExclusiveLock(int value) {
    final int index = index(value);

    if (useSpinLock) {
      OReadersWriterSpinLock spinLock = spinLocks[index];
      spinLock.acquireWriteLock();

      return new SpinLockWrapper(false, spinLock);
    }

    final ReadWriteLock rwLock = locks[index];

    final Lock lock = rwLock.writeLock();
    lock.lock();
    return lock;
  }
Exemplo n.º 8
0
  @Override
  public Lock acquireSharedLock(final T value) {
    final int index;
    if (value == null) index = 0;
    else index = index(value.hashCode());

    if (useSpinLock) {
      OReadersWriterSpinLock spinLock = spinLocks[index];
      spinLock.acquireReadLock();

      return new SpinLockWrapper(true, spinLock);
    }

    final ReadWriteLock rwLock = locks[index];

    final Lock lock = rwLock.readLock();
    lock.lock();
    return lock;
  }
Exemplo n.º 9
0
 @Override
 public void unlock() {
   if (readLock) spinLock.releaseReadLock();
   else spinLock.releaseWriteLock();
 }