jdk/src/aix/native/java/net/aix_close.c
changeset 22605 dba3d6b22818
parent 22597 7515a991bb37
child 23015 73b21ab36615
equal deleted inserted replaced
22604:9b394795e216 22605:dba3d6b22818
   232      * Lock the fd to hold-off additional I/O on this fd.
   232      * Lock the fd to hold-off additional I/O on this fd.
   233      */
   233      */
   234     pthread_mutex_lock(&(fdEntry->lock));
   234     pthread_mutex_lock(&(fdEntry->lock));
   235 
   235 
   236     {
   236     {
       
   237         /* On fast machines we see that we enter dup2 before the
       
   238          * accepting thread had a chance to get and process the signal.
       
   239          * So in case we woke a thread up, give it some time to cope.
       
   240          * Also see https://bugs.openjdk.java.net/browse/JDK-8006395 */
       
   241         int num_woken = 0;
       
   242 
       
   243         /*
       
   244          * Send a wakeup signal to all threads blocked on this
       
   245          * file descriptor.
       
   246          */
       
   247         threadEntry_t *curr = fdEntry->threads;
       
   248         while (curr != NULL) {
       
   249             curr->intr = 1;
       
   250             pthread_kill( curr->thr, sigWakeup );
       
   251             num_woken ++;
       
   252             curr = curr->next;
       
   253         }
       
   254 
       
   255         if (num_woken > 0) {
       
   256           usleep(num_woken * 50);
       
   257         }
       
   258 
   237         /*
   259         /*
   238          * And close/dup the file descriptor
   260          * And close/dup the file descriptor
   239          * (restart if interrupted by signal)
   261          * (restart if interrupted by signal)
   240          */
   262          */
   241         do {
   263         do {
   243                 rv = close(fd2);
   265                 rv = close(fd2);
   244             } else {
   266             } else {
   245                 rv = dup2(fd1, fd2);
   267                 rv = dup2(fd1, fd2);
   246             }
   268             }
   247         } while (rv == -1 && errno == EINTR);
   269         } while (rv == -1 && errno == EINTR);
   248 
       
   249         /*
       
   250          * Send a wakeup signal to all threads blocked on this
       
   251          * file descriptor.
       
   252          */
       
   253         threadEntry_t *curr = fdEntry->threads;
       
   254         while (curr != NULL) {
       
   255             curr->intr = 1;
       
   256             pthread_kill( curr->thr, sigWakeup );
       
   257             curr = curr->next;
       
   258         }
       
   259     }
   270     }
   260 
   271 
   261     /*
   272     /*
   262      * Unlock without destroying errno
   273      * Unlock without destroying errno
   263      */
   274      */