// jump past it.
boolean grantLock = false;
boolean otherWaiters = (firstWaiter() != null);
Lock lockItem = null;
Lockable lref = ref;
// If we haven't been able to grant the lock yet then see if we hold a
// lock already that we are compatible with and there are no granted
// incompatible locks. If the object appears unlocked (due to a just
// released lock, but the first waiter hasn't woken yet)
// then we obviously don't hold a lock, so just join the wait queue.
boolean spaceHasALock = false;
boolean noGrantAtAll = false;
if (!grantLock && !isUnlocked()) {
boolean selfCompatible = lref.lockerAlwaysCompatible();
int index = 0;
int endIndex = firstGrant == null ? granted.size() : 0;
do {
Lock gl = firstGrant == null ? (Lock) granted.get(index) : firstGrant;
boolean sameSpace = (gl.getCompatabilitySpace().equals(compatabilitySpace));
// if it's one of our locks and we are always compatible with
// our own locks then yes, we can be granted.
if (sameSpace && selfCompatible) {
spaceHasALock = true;
if (noGrantAtAll)
break;
if (qualifier == gl.getQualifier())
lockItem = gl;
grantLock = true;
continue;
}
// If we are not compatible with some already granted lock
// then we can't be granted, give up right away.
if (!lref.requestCompatible(qualifier, gl.getQualifier())) {
grantLock = false;
lockItem = null;
// we can't give up rightaway if spaceHasALock is false
// because we need to ensure that canSkip is set correctly