/** * Returns {@code true} if synchronization is held in exclusive-shared mode * with respect to the given owner. * * @param ownerId * The owner which will be used to check re-entrancy instead of * current Thread. * @param context * Any context object can be provided here (that will be passed to * methods like {@link #getOwnerId(Object)}). * * @return {@code true} if synchronization is held in exclusive-shared mode; * {@code false} otherwise */ public final boolean hasExclusiveSharedLock(final Object ownerId, final Object context) { final int currentState = super.get(); if (ownerId == null) { return (writeCount(currentState) > 0 && !isExclusive(currentState)); } else { return (writeCount(currentState) > 0 && !isExclusive(currentState) && ArrayUtils.objectEquals(ownerId, getOwnerId(context))); } }
/** * Get the "strongest" {@link LockMode} corresponding to the current * {@link ExclusiveSharedSynchronizer#getState()} of the object or null if no * lock is held. */ public static final LockMode getLockModeFromState(final int state) { if (writeCount(state) > 0) { return isExclusive(state) ? LockMode.EX : LockMode.EX_SH; } if (isRead(state)) { return isReadOnly(state) ? LockMode.READ_ONLY : LockMode.SH; } return null; }
"attempt to release exclusive lock by a non owner [" + ownerId + "], current owner [" + currentOwnerId + "] for " + this); if (writeCount(currentState) == 0) { final int currentWriteHolds = writeCount(currentState); if (currentWriteHolds == 0) { IllegalMonitorStateException imse = new IllegalMonitorStateException(
+ ownerId + "], current owner [" + currentOwnerId + "] for " + this); if (writeCount(currentState) == 0) { final int currentWriteHolds = writeCount(currentState); if (currentWriteHolds == 0) { IllegalMonitorStateException imse = new IllegalMonitorStateException(
final int currentWriteHolds = writeCount(currentState); if (currentWriteHolds > 0) { final boolean isEX = isExclusive(currentState);
currentWriteHolds = writeCount(currentState); assert requestedLockMode == WRITE_EXCLUSIVE_MODE: requestedLockMode; currentWriteHolds = writeCount(currentState); if (currentWriteHolds > 0) { final boolean isEX = isExclusive(currentState);
currentWriteHolds = writeCount(currentState);