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;
}
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;
}
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;
}
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();
}
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();
}
Aggregations