final int currentState = getState(); final int currentHolds = exclusiveCount(currentState); final int currentWriteSharedHolds = writeSharedCount(currentState); final int currentReadHolds = readSharedCount(currentState); if (currentReadHolds > 0) { if (compareAndSetState(currentState, newState)) { break; if (compareAndSetState(currentState, currentState + EXCLUSIVE_ONE)) { break;
return this.sync.tryAcquire(WRITE_EXCLUSIVE_MODE, id); if (this.sync.tryAcquireNanos(WRITE_EXCLUSIVE_MODE, id, TimeUnit.MILLISECONDS.toNanos(timeoutMillis))) { res = true; res = this.sync.tryAcquireNanos(WRITE_EXCLUSIVE_MODE, null, TimeUnit.MILLISECONDS.toNanos(msecs));
return sync.tryAcquireShared(sharedMode, id) >= 0; if (sync.tryAcquireSharedNanos(sharedMode, id, TimeUnit.MILLISECONDS .toNanos(timeoutMillis))) { res = true; res = sync.tryAcquireSharedNanos(sharedMode, null, TimeUnit.MILLISECONDS .toNanos(msecs));
final int currentState = getState(); if ((arg & MODE_MASK) == WRITE_SHARED_MODE) { assert id != null; final int writeSharedCount = writeSharedCount(currentState); if (writeSharedCount == 0) { throw new IllegalMonitorStateException(); newState = currentState - WRITE_SHARE_ONE; if (compareAndSetState(currentState, newState)) { return true; final int readCount = readSharedCount(currentState); if (readCount == 0) { throw new IllegalMonitorStateException(); newState = currentState - 1; if (compareAndSetState(currentState, newState)) { return true;
final int currentState = getState(); final int currentHolds = exclusiveCount(currentState); final int currentWriteSharedHolds = writeSharedCount(currentState); final int currentReadHolds = readSharedCount(currentState); throw new InternalGemFireError("Maximum read lock count exceeded!"); if (compareAndSetState(currentState, currentState + 1)) { if (compareAndSetState(currentState, currentState + WRITE_SHARE_ONE)) { if (currentWriteSharedHolds + 1 == MAX_WRITE_SHARED_COUNT) { this.ownerId = id;
protected boolean tryRelease(int arg, Object id) { assert ((arg & MODE_MASK) == WRITE_EXCLUSIVE_MODE); assert id != null; if (!id.equals(this.ownerId)) { throw new InternalGemFireError( "an attempt to release lock by a non owner"); } final boolean releaseAll = (arg & RELEASE_ALL_MASK) == RELEASE_ALL_MASK; for (;;) { final int currentState = getState(); final int writeExclusiveCount = exclusiveCount(currentState); if (writeExclusiveCount == 0) { throw new IllegalMonitorStateException(); } int newState; if (releaseAll) { newState = currentState & ~WRITE_EXCLUSIVE_MASK; } else { newState = currentState - EXCLUSIVE_ONE; } if (compareAndSetState(currentState, newState)) { return true; } } }
public ReentrantReadWriteWriteShareLock(boolean allowLockUpgrade) { this.sync = new CASSync(allowLockUpgrade); }
public void releaseReadLock(boolean releaseAll) { this.sync.releaseShared(releaseAll ? READ_MODE | RELEASE_ALL_MASK : READ_MODE, null); }
public void releaseWriteExclusiveLock(boolean releaseAll, Object id) { // Neeraj: log this.sync.release(releaseAll ? WRITE_EXCLUSIVE_MODE | RELEASE_ALL_MASK : WRITE_EXCLUSIVE_MODE, id); }
public void releaseWriteShareLock(boolean releaseAll, Object id) { // Neeraj: log this.sync.releaseShared(releaseAll ? WRITE_SHARED_MODE | RELEASE_ALL_MASK : WRITE_SHARED_MODE, id); }