Search in sources :

Example 6 with ReadWriteLock

use of java.util.concurrent.locks.ReadWriteLock in project orientdb by orientechnologies.

the class OPartitionedLockManager method acquireExclusiveLock.

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;
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 7 with ReadWriteLock

use of java.util.concurrent.locks.ReadWriteLock in project orientdb by orientechnologies.

the class OPartitionedLockManager method acquireSharedLock.

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;
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 8 with ReadWriteLock

use of java.util.concurrent.locks.ReadWriteLock in project orientdb by orientechnologies.

the class OPartitionedLockManager method acquireSharedLock.

public Lock acquireSharedLock(long value) {
    final int hashCode = longHashCode(value);
    final int index = index(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;
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 9 with ReadWriteLock

use of java.util.concurrent.locks.ReadWriteLock in project orientdb by orientechnologies.

the class OPartitionedLockManager method releaseExclusiveLock.

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();
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 10 with ReadWriteLock

use of java.util.concurrent.locks.ReadWriteLock in project orientdb by orientechnologies.

the class OPartitionedLockManager method releaseExclusiveLock.

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();
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Aggregations

ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)45 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)36 Lock (java.util.concurrent.locks.Lock)21 Test (org.junit.Test)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 Nullable (org.jetbrains.annotations.Nullable)4 ArrayList (java.util.ArrayList)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 Ignore (org.junit.Ignore)2 Member (cz.metacentrum.perun.core.api.Member)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Random (java.util.Random)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 Phaser (java.util.concurrent.Phaser)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1