Methods Summary |
---|
public void | lock()Acquire the lock for this synchronizer. Nested lock is supported.
If the mutex is already locked by another thread, the current thread will be put
into wait queue until the lock becomes available.
All user threads are served in FIFO order. Dispatch thread has higher priority.
Supposed to be used in Toolkit.lockAWT() only.
synchronized (this) {
Thread curThread = Thread.currentThread();
if (acquestCounter == 0) {
acquestCounter = 1;
owner = curThread;
} else {
if (owner == curThread) {
acquestCounter++;
} else {
if (curThread == dispatchThread) {
waitQueue.addFirst(curThread);
} else {
waitQueue.addLast(curThread);
}
try {
wait();
} catch (InterruptedException e) {
if (owner != curThread) {
waitQueue.remove(curThread);
// awt.1F=Waiting for resource access thread interrupted not from unlock method.
throw new RuntimeException(Messages
.getString("awt.1F")); //$NON-NLS-1$
}
}
}
}
}
|
public void | lockAndRestoreState()Locks this synchronizer and restores it's state.
Supposed to be used in Toolkit.unsafeInvokeAndWaitUnderAWTLock() only in pair with
storeStateAndFree().
Do not call it directly.
synchronized (this) {
Thread curThread = Thread.currentThread();
if (owner == curThread) {
// awt.24=Owner can't overwrite resource state. Lock operations may be lost.
throw new RuntimeException(
Messages.getString("awt.24")); //$NON-NLS-1$
}
if (!storedStates.containsKey(curThread)) {
// awt.25=No state stored for current thread.
throw new RuntimeException(Messages.getString("awt.25")); //$NON-NLS-1$
}
lock();
acquestCounter = storedStates.get(curThread).intValue();
storedStates.remove(curThread);
}
|
public void | setEnvironment(WTK wtk, java.lang.Thread dispatchThread)Sets references to WTK and event dispatch thread.
Called on toolkit startup.
synchronized (this) {
this.dispatchThread = dispatchThread;
}
|
public void | storeStateAndFree()Stores state of this synchronizer and frees it.
Supposed to be used in Toolkit.unsafeInvokeAndWaitUnderAWTLock() only in pair with
lockAndRestoreState().
Do not call it directly.
synchronized (this) {
Thread curThread = Thread.currentThread();
if (owner != curThread) {
// awt.22=Not owner can't free resource.
throw new RuntimeException(Messages.getString("awt.22")); //$NON-NLS-1$
}
if (storedStates.containsKey(curThread)) {
// awt.23=One thread can't store state several times in a row.
throw new RuntimeException(Messages.getString("awt.23")); //$NON-NLS-1$
}
storedStates.put(curThread, new Integer(acquestCounter));
acquestCounter = 1;
unlock();
}
|
public void | unlock()Release the lock for this synchronizer.
If wait queue is not empty the first waiting thread acquires the lock.
Supposed to be used in Toolkit.unlockAWT() only.
synchronized (this) {
if (acquestCounter == 0) {
// awt.20=Can't unlock not locked resource.
throw new RuntimeException(Messages.getString("awt.20")); //$NON-NLS-1$
}
if (owner != Thread.currentThread()) {
// awt.21=Not owner can't unlock resource.
throw new RuntimeException(Messages.getString("awt.21")); //$NON-NLS-1$
}
acquestCounter--;
if (acquestCounter == 0) {
if (waitQueue.size() > 0) {
acquestCounter = 1;
owner = waitQueue.removeFirst();
owner.interrupt();
} else {
owner = null;
}
}
}
|