< prev index next >

src/jdk.sctp/unix/classes/sun/nio/ch/sctp/SctpChannelImpl.java

Print this page
*** 82,13 ***
  
      private final FileDescriptor fd;
  
      private final int fdVal;
  
!     /* IDs of native threads doing send and receive, for signalling */
!     private volatile long receiverThread;
!     private volatile long senderThread;
  
      /* Lock held by current receiving or connecting thread */
      private final Object receiveLock = new Object();
  
      /* Lock held by current sending or connecting thread */
--- 82,13 ---
  
      private final FileDescriptor fd;
  
      private final int fdVal;
  
!     /* Threads doing send and receive, for signalling */
!     private volatile Thread receiverThread;
!     private volatile Thread senderThread;
  
      /* Lock held by current receiving or connecting thread */
      private final Object receiveLock = new Object();
  
      /* Lock held by current sending or connecting thread */

*** 324,19 ***
          }
      }
  
      private void receiverCleanup() throws IOException {
          synchronized (stateLock) {
!             receiverThread = 0;
              if (state == ChannelState.KILLPENDING)
                  kill();
          }
      }
  
      private void senderCleanup() throws IOException {
          synchronized (stateLock) {
!             senderThread = 0;
              if (state == ChannelState.KILLPENDING)
                  kill();
          }
      }
  
--- 324,19 ---
          }
      }
  
      private void receiverCleanup() throws IOException {
          synchronized (stateLock) {
!             receiverThread = null;
              if (state == ChannelState.KILLPENDING)
                  kill();
          }
      }
  
      private void senderCleanup() throws IOException {
          synchronized (stateLock) {
!             senderThread = null;
              if (state == ChannelState.KILLPENDING)
                  kill();
          }
      }
  

*** 365,11 ***
                              begin();
                              synchronized (stateLock) {
                                  if (!isOpen()) {
                                      return false;
                                  }
!                                 receiverThread = NativeThread.current();
                              }
                              for (;;) {
                                  InetAddress ia = isa.getAddress();
                                  if (ia.isAnyLocalAddress())
                                      ia = InetAddress.getLocalHost();
--- 365,11 ---
                              begin();
                              synchronized (stateLock) {
                                  if (!isOpen()) {
                                      return false;
                                  }
!                                 receiverThread = NativeThread.threadToSignal();
                              }
                              for (;;) {
                                  InetAddress ia = isa.getAddress();
                                  if (ia.isAnyLocalAddress())
                                      ia = InetAddress.getLocalHost();

*** 470,11 ***
                          synchronized (blockingLock()) {
                              synchronized (stateLock) {
                                  if (!isOpen()) {
                                      return false;
                                  }
!                                 receiverThread = NativeThread.current();
                              }
                              if (!isBlocking()) {
                                  connected = Net.pollConnect(fd, 0);
                              } else {
                                  do {
--- 470,11 ---
                          synchronized (blockingLock()) {
                              synchronized (stateLock) {
                                  if (!isOpen()) {
                                      return false;
                                  }
!                                 receiverThread = NativeThread.threadToSignal();
                              }
                              if (!isBlocking()) {
                                  connected = Net.pollConnect(fd, 0);
                              } else {
                                  do {

*** 482,11 ***
                                  } while (!connected && isOpen());
                              }
                          }
                      } finally {
                          synchronized (stateLock) {
!                             receiverThread = 0;
                              if (state == ChannelState.KILLPENDING) {
                                  kill();
                                  connected = false;
                              }
                          }
--- 482,11 ---
                                  } while (!connected && isOpen());
                              }
                          }
                      } finally {
                          synchronized (stateLock) {
!                             receiverThread = null;
                              if (state == ChannelState.KILLPENDING) {
                                  kill();
                                  connected = false;
                              }
                          }

*** 539,14 ***
      public void implCloseSelectableChannel() throws IOException {
          synchronized (stateLock) {
              if (state != ChannelState.KILLED)
                  SctpNet.preClose(fdVal);
  
!             if (receiverThread != 0)
                  NativeThread.signal(receiverThread);
  
!             if (senderThread != 0)
                  NativeThread.signal(senderThread);
  
              if (!isRegistered())
                  kill();
          }
--- 539,14 ---
      public void implCloseSelectableChannel() throws IOException {
          synchronized (stateLock) {
              if (state != ChannelState.KILLED)
                  SctpNet.preClose(fdVal);
  
!             if (receiverThread != null)
                  NativeThread.signal(receiverThread);
  
!             if (senderThread != null)
                  NativeThread.signal(senderThread);
  
              if (!isRegistered())
                  kill();
          }

*** 642,11 ***
              }
              assert !isOpen() && !isRegistered();
  
              /* Postpone the kill if there is a waiting reader
               * or writer thread. */
!             if (receiverThread == 0 && senderThread == 0) {
                  state = ChannelState.KILLED;
                  SctpNet.close(fdVal);
              } else {
                  state = ChannelState.KILLPENDING;
              }
--- 642,11 ---
              }
              assert !isOpen() && !isRegistered();
  
              /* Postpone the kill if there is a waiting reader
               * or writer thread. */
!             if (receiverThread == null && senderThread == null) {
                  state = ChannelState.KILLED;
                  SctpNet.close(fdVal);
              } else {
                  state = ChannelState.KILLPENDING;
              }

*** 741,11 ***
                          begin();
  
                          synchronized (stateLock) {
                              if(!isOpen())
                                  return null;
!                             receiverThread = NativeThread.current();
                          }
  
                          do {
                              n = receive(fdVal, buffer, resultContainer, fromConnect);
                          } while ((n == IOStatus.INTERRUPTED) && isOpen());
--- 741,11 ---
                          begin();
  
                          synchronized (stateLock) {
                              if(!isOpen())
                                  return null;
!                             receiverThread = NativeThread.threadToSignal();
                          }
  
                          do {
                              n = receive(fdVal, buffer, resultContainer, fromConnect);
                          } while ((n == IOStatus.INTERRUPTED) && isOpen());

*** 934,11 ***
                  begin();
  
                  synchronized (stateLock) {
                      if(!isOpen())
                          return 0;
!                     senderThread = NativeThread.current();
                  }
  
                  do {
                      n = send(fdVal, buffer, messageInfo);
                  } while ((n == IOStatus.INTERRUPTED) && isOpen());
--- 934,11 ---
                  begin();
  
                  synchronized (stateLock) {
                      if(!isOpen())
                          return 0;
!                     senderThread = NativeThread.threadToSignal();
                  }
  
                  do {
                      n = send(fdVal, buffer, messageInfo);
                  } while ((n == IOStatus.INTERRUPTED) && isOpen());

*** 1029,11 ***
              if (isShutdown)
                  return this;
  
              ensureSendOpen();
              SctpNet.shutdown(fdVal, -1);
!             if (senderThread != 0)
                  NativeThread.signal(senderThread);
              isShutdown = true;
          }
          return this;
      }
--- 1029,11 ---
              if (isShutdown)
                  return this;
  
              ensureSendOpen();
              SctpNet.shutdown(fdVal, -1);
!             if (senderThread != null)
                  NativeThread.signal(senderThread);
              isShutdown = true;
          }
          return this;
      }
< prev index next >