< prev index next > src/java.base/unix/classes/sun/nio/ch/SinkChannelImpl.java
Print this page
private static final int ST_CLOSING = 1;
private static final int ST_CLOSED = 2;
private int state;
// ID of native thread doing write, for signalling
! private long thread;
// True if the channel's socket has been forced into non-blocking mode
// by a virtual thread. It cannot be reset. When the channel is in
// blocking mode and the channel's socket is in non-blocking mode then
// operations that don't complete immediately will poll the socket and
private static final int ST_CLOSING = 1;
private static final int ST_CLOSED = 2;
private int state;
// ID of native thread doing write, for signalling
! private NativeThread writer;
// True if the channel's socket has been forced into non-blocking mode
// by a virtual thread. It cannot be reset. When the channel is in
// blocking mode and the channel's socket is in non-blocking mode then
// operations that don't complete immediately will poll the socket and
* Closes the write end of the pipe if there are no write operation in
* progress and the channel is not registered with a Selector.
*/
private boolean tryClose() throws IOException {
assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
! if (thread == 0 && !isRegistered()) {
state = ST_CLOSED;
nd.close(fd);
return true;
} else {
return false;
* Closes the write end of the pipe if there are no write operation in
* progress and the channel is not registered with a Selector.
*/
private boolean tryClose() throws IOException {
assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
! if (writer == null && !isRegistered()) {
state = ST_CLOSED;
nd.close(fd);
return true;
} else {
return false;
private void implCloseBlockingMode() throws IOException {
synchronized (stateLock) {
assert state < ST_CLOSING;
state = ST_CLOSING;
if (!tryClose()) {
! nd.preClose(fd, thread, 0);
}
}
}
/**
private void implCloseBlockingMode() throws IOException {
synchronized (stateLock) {
assert state < ST_CLOSING;
state = ST_CLOSING;
if (!tryClose()) {
! nd.preClose(fd, null, writer);
}
}
}
/**
begin();
}
synchronized (stateLock) {
ensureOpen();
if (blocking)
! thread = NativeThread.current();
}
}
/**
* Marks the end of a write operation that may have blocked.
begin();
}
synchronized (stateLock) {
ensureOpen();
if (blocking)
! writer = NativeThread.current();
}
}
/**
* Marks the end of a write operation that may have blocked.
private void endWrite(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! thread = 0;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
// remove hook for Thread.interrupt
private void endWrite(boolean blocking, boolean completed)
throws AsynchronousCloseException
{
if (blocking) {
synchronized (stateLock) {
! writer = null;
if (state == ST_CLOSING) {
tryFinishClose();
}
}
// remove hook for Thread.interrupt
< prev index next >