// operations do.
synchronized (director) {
if (_debugging) {
_debug("Resources available: " + _pool);
}
Token resource = RendezvousReceiver.getFromAny(
release.getReceivers(), director);
_pool.add(resource);
director.threadUnblocked(writeThread, null);
director.notifyAll();
}
}
} catch (TerminateProcessException ex) {
// OK, just exit
_postfireReturns = false;
} finally {
director.removeThread(_readThread);
}
}
};
director.addThread(_readThread);
_readThread.start();
} else if (release.getWidth() == 0 && _readThread != null) {
// A mutation has eliminated the sources.
_readThread.interrupt();
}
// Synchronize on the director since all read/write
// operations do.
synchronized (director) {
while (_pool.size() == 0) {
if (_stopRequested || !_postfireReturns) {
_postfireReturns = false;
return;
}
try {
director.threadBlocked(writeThread, null);
RendezvousReceiver.waitForChange(director);
} catch (TerminateProcessException ex) {
_postfireReturns = false;
return;
} finally {
director.threadUnblocked(writeThread, null);
}
}
// There is a token.
Token token = (Token) _pool.get(0);
// If this put blocks for any reason, it will block on
// a director.wait(), so the lock will not be held.
try {
RendezvousReceiver.putToAny(token, grant.getRemoteReceivers(),
director);