1 21 22 package org.apache.derby.impl.services.locks; 23 24 import org.apache.derby.iapi.services.locks.Lockable; 25 import org.apache.derby.iapi.services.locks.C_LockFactory; 26 27 import org.apache.derby.iapi.error.StandardException; 28 import org.apache.derby.iapi.services.context.ContextService; 29 import org.apache.derby.iapi.services.context.ContextManager; 30 import org.apache.derby.iapi.services.sanity.SanityManager; 31 32 33 39 40 public final class ActiveLock extends Lock { 41 42 46 byte wakeUpNow; 47 48 53 boolean potentiallyGranted; 54 55 61 protected boolean canSkip; 62 63 69 protected ActiveLock(Object space, Lockable ref, Object qualifier) { 70 super(space, ref, qualifier); 71 } 72 73 79 protected boolean setPotentiallyGranted() { 80 if (!potentiallyGranted) { 81 potentiallyGranted = true; 82 return true; 83 } 84 return false; 85 } 86 87 92 protected void clearPotentiallyGranted() { 93 potentiallyGranted = false; 94 } 95 96 107 protected synchronized byte waitForGrant(int timeout) 108 throws StandardException 109 { 110 111 if (wakeUpNow == Constants.WAITING_LOCK_IN_WAIT) { 112 113 try { 114 115 116 if (timeout == C_LockFactory.WAIT_FOREVER) { 117 wait(); 118 } 119 else if (timeout > 0) { 120 wait(timeout); 121 } 122 123 } catch (InterruptedException ie) { 124 throw StandardException.interrupt(ie); 125 } 126 } 127 128 byte why = wakeUpNow; 129 wakeUpNow = Constants.WAITING_LOCK_IN_WAIT; 130 return why; 131 } 132 133 138 protected synchronized void wakeUp(byte why) { 139 if (wakeUpNow != Constants.WAITING_LOCK_DEADLOCK) 142 wakeUpNow = why; 143 notify(); 144 } 145 } 146 147 | Popular Tags |