Пример #1
0
  public LockAttemptResult lock(
      LockType requestType,
      Locker locker,
      boolean nonBlockingRequest,
      MemoryBudget mb,
      int lockTableIndex)
      throws DatabaseException {

    if (this.locker != null && this.locker != locker) {
      /* Lock is already held by someone else so mutate. */
      Lock newLock = new LockImpl(new LockInfo(this.locker, this.lockType));
      return newLock.lock(requestType, locker, nonBlockingRequest, mb, lockTableIndex);
    }

    LockGrantType grant = null;
    if (this.locker == null) {
      this.locker = locker;
      this.lockType = requestType;
      grant = LockGrantType.NEW;
    } else {

      /* The requestor holds this lock.  Check for upgrades. */
      LockUpgrade upgrade = lockType.getUpgrade(requestType);
      if (upgrade.getUpgrade() == null) {
        grant = LockGrantType.EXISTING;
      } else {
        LockType upgradeType = upgrade.getUpgrade();
        assert upgradeType != null;
        this.lockType = upgradeType;
        grant = (upgrade.getPromotion() ? LockGrantType.PROMOTION : LockGrantType.EXISTING);
      }
    }
    return new LockAttemptResult(this, grant, false);
  }
Пример #2
0
  public boolean isOwner(Locker locker, LockType lockType) {

    if (locker == this.locker) {
      if (lockType == this.lockType) {
        return true;
      }

      if (this.lockType != null) {
        LockUpgrade upgrade = this.lockType.getUpgrade(lockType);
        if (!upgrade.getPromotion()) {
          return true;
        }
      }
    } else {
      return false;
    }
    return false;
  }