/** set the given bit mask in the lock state */ protected final void setFlag(int currentState, final int flag) { InternalDistributedSystem sys = null; for (;;) { if (compareAndSetState(currentState, (currentState | flag))) { return; } // check if DS is disconnecting if (sys == null) { sys = getDistributedSystem(); } sys.getCancelCriterion().checkCancelInProgress(null); currentState = getState(); } }
/** clear the given bit mask from the lock state */ protected final void clearFlag(int currentState, final int flag) { InternalDistributedSystem sys = null; for (;;) { if (compareAndSetState(currentState, (currentState & ~flag))) { return; } // check if DS is disconnecting if (sys == null) { sys = getDistributedSystem(); } sys.getCancelCriterion().checkCancelInProgress(null); currentState = getState(); } }
if (compareAndSetState(currentState, newState)) { return true; if (compareAndSetState(currentState, newState)) { return true; newState = currentState - WRITE_ONE; if (compareAndSetState(currentState, newState)) { return true;
case READ_SHARED_MODE: if (currentState == 0) { if (compareAndSetState(0, 1)) { return 1; + " for " + this); if (compareAndSetState(currentState, currentState + 1)) { if (compareAndSetState(0, READ_ONLY_ONE)) { return 1; + "lock count exceeded " + MAX_READ_ONLY_COUNT + " for " + this); if (compareAndSetState(currentState, currentState + READ_ONLY_ONE)) { final int newState = allowReadOnly ? WRITE_ONE | WRITE_ALLOWS_READ_ONLY : WRITE_ONE; if (compareAndSetState(0, newState)) { setOwnerId(ownerId, context); return 1; if (compareAndSetState(currentState, newState)) { setOwnerId(ownerId, context); if (currentWriteHolds != MAX_WRITE_COUNT_1) {
newState = currentState - WRITE_ONE; if (compareAndSetState(currentState, newState)) { return true;
final int currentState = getState(); if (currentState == 0) { if (compareAndSetState(0, WRITE_ONE | WRITE_EXCLUSIVE_BIT)) { setOwnerId(ownerId, context); return 1; if (compareAndSetState(currentState, (currentState + WRITE_ONE) | WRITE_EXCLUSIVE_BIT)) { setOwnerId(ownerId, context);