< prev index next >

src/java.base/share/classes/sun/nio/ch/SocketChannelImpl.java

Print this page
@@ -112,13 +112,13 @@
      private static final int ST_CONNECTED = 2;
      private static final int ST_CLOSING = 3;
      private static final int ST_CLOSED = 4;
      private volatile int state;  // need stateLock to change
  
-     // IDs of native threads doing reads and writes, for signalling
-     private long readerThread;
-     private long writerThread;
+     // Threads doing reads and writes, for signalling
+     private Thread readerThread;
+     private Thread writerThread;
  
      // Binding
      private SocketAddress localAddress;
      private SocketAddress remoteAddress;
  

@@ -367,11 +367,11 @@
              begin();
  
              synchronized (stateLock) {
                  ensureOpen();
                  // record thread so it can be signalled if needed
-                 readerThread = NativeThread.current();
+                 readerThread = NativeThread.threadToSignal();
              }
          }
      }
  
      /**

@@ -383,11 +383,11 @@
      private void endRead(boolean blocking, boolean completed)
          throws AsynchronousCloseException
      {
          if (blocking) {
              synchronized (stateLock) {
-                 readerThread = 0;
+                 readerThread = null;
                  if (state == ST_CLOSING) {
                      tryFinishClose();
                  }
              }
              // remove hook for Thread.interrupt

@@ -521,11 +521,11 @@
              synchronized (stateLock) {
                  ensureOpen();
                  if (isOutputClosed)
                      throw new ClosedChannelException();
                  // record thread so it can be signalled if needed
-                 writerThread = NativeThread.current();
+                 writerThread = NativeThread.threadToSignal();
              }
          }
      }
  
      /**

@@ -537,11 +537,11 @@
      private void endWrite(boolean blocking, boolean completed)
          throws AsynchronousCloseException
      {
          if (blocking) {
              synchronized (stateLock) {
-                 writerThread = 0;
+                 writerThread = null;
                  if (state == ST_CLOSING) {
                      tryFinishClose();
                  }
              }
              // remove hook for Thread.interrupt

@@ -672,11 +672,11 @@
          try {
              synchronized (stateLock) {
                  ensureOpenAndConnected();
                  if (isOutputClosed)
                      throw new ClosedChannelException();
-                 writerThread = NativeThread.current();
+                 writerThread = NativeThread.threadToSignal();
                  completed = true;
              }
          } finally {
              if (!completed) {
                  writeLock.unlock();

@@ -688,11 +688,11 @@
       * Marks the end of a transfer to this channel.
       * @throws AsynchronousCloseException if not completed and the channel is closed
       */
      void afterTransferTo(boolean completed) throws AsynchronousCloseException {
          synchronized (stateLock) {
-             writerThread = 0;
+             writerThread = null;
              if (state == ST_CLOSING) {
                  tryFinishClose();
              }
          }
          writeLock.unlock();

@@ -875,11 +875,11 @@
              }
              remoteAddress = sa;
  
              if (blocking) {
                  // record thread so it can be signalled if needed
-                 readerThread = NativeThread.current();
+                 readerThread = NativeThread.threadToSignal();
              }
          }
      }
  
      /**

@@ -994,11 +994,11 @@
              ensureOpen();
              if (state != ST_CONNECTIONPENDING)
                  throw new NoConnectionPendingException();
              if (blocking) {
                  // record thread so it can be signalled if needed
-                 readerThread = NativeThread.current();
+                 readerThread = NativeThread.threadToSignal();
              }
          }
      }
  
      /**

@@ -1073,11 +1073,11 @@
       * Closes the socket if there are no I/O operations in progress (or no I/O
       * operations tracked), and the channel is not registered with a Selector.
       */
      private boolean tryClose() throws IOException {
          assert Thread.holdsLock(stateLock) && state == ST_CLOSING;
-         if ((readerThread == 0) && (writerThread == 0) && !isRegistered()) {
+         if ((readerThread == null) && (writerThread == null) && !isRegistered()) {
              state = ST_CLOSED;
              nd.close(fd);
              return true;
          } else {
              return false;

@@ -1216,15 +1216,12 @@
              ensureOpen();
              if (!isConnected())
                  throw new NotYetConnectedException();
              if (!isInputClosed) {
                  Net.shutdown(fd, Net.SHUT_RD);
-                 long reader = readerThread;
-                 if (NativeThread.isVirtualThread(reader)) {
-                     Poller.stopPoll(fdVal, Net.POLLIN);
-                 } else if (NativeThread.isNativeThread(reader)) {
-                     NativeThread.signal(reader);
+                 if (readerThread != null && readerThread.isVirtual()) {
+                     Poller.stopPoll(readerThread);
                  }
                  isInputClosed = true;
              }
              return this;
          }

@@ -1236,15 +1233,12 @@
              ensureOpen();
              if (!isConnected())
                  throw new NotYetConnectedException();
              if (!isOutputClosed) {
                  Net.shutdown(fd, Net.SHUT_WR);
-                 long writer = writerThread;
-                 if (NativeThread.isVirtualThread(writer)) {
-                     Poller.stopPoll(fdVal, Net.POLLOUT);
-                 } else if (NativeThread.isNativeThread(writer)) {
-                     NativeThread.signal(writer);
+                 if (writerThread != null && writerThread.isVirtual()) {
+                     Poller.stopPoll(writerThread);
                  }
                  isOutputClosed = true;
              }
              return this;
          }
< prev index next >