if (isUnlocked())
return true;
boolean grantLock = false;
Lockable lref = ref;
List lgranted = granted;
{
// Check to see if the only locks on the granted queue that
// we are incompatible with are locks we own.
boolean selfCompatible = lref.lockerAlwaysCompatible();
int index = 0;
int endIndex = firstGrant == null ? lgranted.size() : 0;
do {
Lock gl = firstGrant == null ? (Lock) lgranted.get(index) : firstGrant;
boolean sameSpace =
(gl.getCompatabilitySpace() == compatibilitySpace);
if (sameSpace && selfCompatible)
{
// if it's one of our locks and we are always compatible
// with our own locks then yes, we can be granted.
grantLock = true;
continue;
}
else if (!lref.requestCompatible(qualifier, gl.getQualifier()))
{
// If we are not compatible with some already granted lock
// then we can't be granted, give up right away.
grantLock = false;