private _LockManager(_LocalDatabase db, LockUpgradeRule lockUpgradeRule, long timeoutNanos, int numHashTables) { mDatabaseRef = db == null ? null : new WeakReference<>(db); if (lockUpgradeRule == null) { lockUpgradeRule = LockUpgradeRule.STRICT; } mDefaultLockUpgradeRule = lockUpgradeRule; mDefaultTimeoutNanos = timeoutNanos; numHashTables = Utils.roundUpPower2(Math.max(2, numHashTables)); mHashTables = new LockHT[numHashTables]; for (int i=0; i<numHashTables; i++) { mHashTables[i] = new LockHT(); } mHashTableShift = Integer.numberOfLeadingZeros(numHashTables - 1); mLocalLockerRef = new ThreadLocal<>(); }
ht.remove(this); } else if (queueU != null) { if (queueU == null) { ht.remove(this); } else { ht.releaseExclusive(); return; ht.remove(this); ht.releaseExclusive();
ht.remove(this); } else if (queueU != null) { if (queueU == null) { ht.remove(this); } else { ht.releaseExclusive(); return; ht.remove(this); ht.releaseExclusive();
lockEx: { lockNonEx: { acquireExclusive(); try { _Lock[] entries = mEntries; entries = rehash(entries); index = hash & (entries.length - 1); releaseExclusive();
lockEx: { lockNonEx: { acquireExclusive(); try { _Lock[] entries = mEntries; mSize++; } finally { releaseExclusive();
lockEx: { lockNonEx: { acquireExclusive(); try { _Lock[] entries = mEntries; entries = rehash(entries); index = hash & (entries.length - 1); releaseExclusive();
if (manager != null) { _LockManager.LockHT ht = manager.getLockHT(mHashCode); ht.acquireShared(); try { return findOwnerAttachment(null, lockType); } finally { ht.releaseShared();
if (manager != null) { _LockManager.LockHT ht = manager.getLockHT(mHashCode); ht.acquireShared(); try { return findOwnerAttachment(null, lockType); } finally { ht.releaseShared();
if (manager != null) { _LockManager.LockHT ht = manager.getLockHT(hash); ht.acquireShared(); try { return findOwnerAttachment(null, lockType, hash); } finally { ht.releaseShared();
LockResult result; lockEx: { acquireExclusive(); try { _Lock[] entries = mEntries; mSize++; } finally { releaseExclusive();
void close(_LockOwner locker) { acquireExclusive(); try { if (mSize > 0) { releaseExclusive();
void close(_LockOwner locker) { acquireExclusive(); try { if (mSize > 0) { releaseExclusive();
LockResult result; lockEx: { acquireExclusive(); try { _Lock[] entries = mEntries; entries = rehash(entries); index = hash & (entries.length - 1); releaseExclusive();
LockResult result; lockEx: { acquireExclusive(); try { _Lock[] entries = mEntries; entries = rehash(entries); index = hash & (entries.length - 1); releaseExclusive();
void close(_LockOwner locker) { acquireExclusive(); try { if (mSize > 0) { releaseExclusive();
ht.releaseExclusive(); } else {
ht.remove(this);
ht.releaseExclusive(); } else {
/** * Returns true if a shared lock can be granted for the given key. Caller must hold the * node latch which contains the key. * * @param locker optional locker */ boolean isAvailable(_LockOwner locker, long indexId, byte[] key, int hash) { // Optimistically find the lock. int stamp = mStamp; if (stamp >= 0) { _Lock lock = lockFor(indexId, key, hash); if (lock != null) { return lock.isAvailable(locker); } if (stamp == mStamp) { return true; } } _Lock lock; acquireShared(); try { lock = lockFor(indexId, key, hash); } finally { releaseShared(); } return lock == null ? true : lock.isAvailable(locker); }
/** * NT == No Timeout or deadlock exception thrown * * @param lockType TYPE_SHARED, TYPE_UPGRADABLE, or TYPE_EXCLUSIVE * @return {@link LockResult#TIMED_OUT_LOCK TIMED_OUT_LOCK}, {@link * LockResult#ACQUIRED ACQUIRED}, {@link LockResult#OWNED_SHARED * OWNED_SHARED}, {@link LockResult#OWNED_UPGRADABLE OWNED_UPGRADABLE}, or * {@link LockResult#OWNED_EXCLUSIVE OWNED_EXCLUSIVE} */ @SuppressWarnings("incomplete-switch") final LockResult lockNT(int lockType, long indexId, byte[] key, int hash, long nanosTimeout) throws LockFailureException { LockResult result = manager().getLockHT(hash) .tryLock(lockType, this, indexId, key, hash, nanosTimeout); if (!result.isHeld()) { switch (result) { case ILLEGAL: throw new IllegalUpgradeException(); case INTERRUPTED: throw new LockInterruptedException(); } } return result; }