/** * @return whether we should wake the procedures waiting on the lock here. */ public boolean releaseSharedLock() { // hasExclusiveLock could be true, it usually means we acquire shared lock while we or our // parent have held the xlock. And since there is still an exclusive lock, we do not need to // wake any procedures. return --sharedLock == 0 && !hasExclusiveLock(); }
/** * @return whether we have succesfully acquired the shared lock. */ public boolean trySharedLock(Procedure<?> proc) { if (hasExclusiveLock() && !hasLockAccess(proc)) { return false; } // If no one holds the xlock, then we are free to hold the sharedLock // If the parent proc or we have already held the xlock, then we return true here as // xlock is more powerful then shared lock. sharedLock++; return true; }
@Override public String toString() { return "exclusiveLockOwner=" + (hasExclusiveLock() ? getExclusiveLockProcIdOwner() : "NONE") + ", sharedLockCount=" + getSharedLockCount() + ", waitingProcCount=" + queue.size(); } }
private LockedResource createLockedResource(LockedResourceType resourceType, String resourceName, LockAndQueue queue) { LockType lockType; Procedure<?> exclusiveLockOwnerProcedure; int sharedLockCount; if (queue.hasExclusiveLock()) { lockType = LockType.EXCLUSIVE; exclusiveLockOwnerProcedure = queue.getExclusiveLockOwnerProcedure(); sharedLockCount = 0; } else { lockType = LockType.SHARED; exclusiveLockOwnerProcedure = null; sharedLockCount = queue.getSharedLockCount(); } List<Procedure<?>> waitingProcedures = new ArrayList<>(); queue.filterWaitingQueue(p -> p instanceof LockProcedure) .forEachOrdered(waitingProcedures::add); return new LockedResource(resourceType, resourceName, lockType, exclusiveLockOwnerProcedure, sharedLockCount, waitingProcedures); }
public boolean trySharedLock() { if (hasExclusiveLock()) return false; sharedLock++; return true; }
/** * @return whether we should wake the procedures waiting on the lock here. */ public boolean releaseSharedLock() { // hasExclusiveLock could be true, it usually means we acquire shared lock while we or our // parent have held the xlock. And since there is still an exclusive lock, we do not need to // wake any procedures. return --sharedLock == 0 && !hasExclusiveLock(); }
@Override public boolean isLocked() { return hasExclusiveLock() || sharedLock > 0; }
/** * @return whether we have succesfully acquired the shared lock. */ public boolean trySharedLock(Procedure<?> proc) { if (hasExclusiveLock() && !hasLockAccess(proc)) { return false; } // If no one holds the xlock, then we are free to hold the sharedLock // If the parent proc or we have already held the xlock, then we return true here as // xlock is more powerful then shared lock. sharedLock++; return true; }
@Override public String toString() { return "exclusiveLockOwner=" + (hasExclusiveLock()? getExclusiveLockProcIdOwner(): "NONE") + ", sharedLockCount=" + getSharedLockCount() + ", waitingProcCount=" + size(); } }
@Override public String toString() { return "exclusiveLockOwner=" + (hasExclusiveLock() ? getExclusiveLockProcIdOwner() : "NONE") + ", sharedLockCount=" + getSharedLockCount() + ", waitingProcCount=" + queue.size(); } }