Example #1
0
  /** Release one level of mutator locks if this thread holds at lease one. */
  public void releaseMutatorLock() {
    Long lockStateVal = lockState.get();
    if (lockStateVal == null) lockStateVal = zero;

    final long longVal = lockStateVal;

    if (longVal == 0)
      // No lock to release, return
      return;

    if (longVal == 1) {
      // Last one on stack release lock
      // Using read lock because we want a non-exclusive lock
      mutatorLock.readUnlock();
      lockStateVal = zero;
    } else {
      lockStateVal = longVal - 1;
    }

    lockState.set(lockStateVal);
  }