apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r653953 - in /apr/apr/trunk: CHANGES poll/unix/port.c
Date Tue, 06 May 2008 23:47:35 GMT
Author: niq
Date: Tue May  6 16:47:35 2008
New Revision: 653953

URL: http://svn.apache.org/viewvc?rev=653953&view=rev
Log:
Fix poll failure on Solaris - PR 43000
Patch by Henry Jen

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/poll/unix/port.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=653953&r1=653952&r2=653953&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Tue May  6 16:47:35 2008
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 1.4.0
 
+  *) Fix Solaris poll failure.  PR 43000
+     [Henry Jen <henryjen ztune.net>]
+
   *) Introduce apr_pollset_wakeup() for interrupting
      the blocking apr_pollset_poll call.
      [Mladen Turk]

Modified: apr/apr/trunk/poll/unix/port.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/port.c?rev=653953&r1=653952&r2=653953&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/port.c (original)
+++ apr/apr/trunk/poll/unix/port.c Tue May  6 16:47:35 2008
@@ -15,6 +15,7 @@
  */
 
 #include "apr_arch_poll_private.h"
+#include "apr_atomic.h"
 
 #ifdef POLLSET_USES_PORT
 
@@ -82,6 +83,8 @@
     /* A ring of pollfd_t where rings that have been _remove'd but
        might still be inside a _poll */
     APR_RING_HEAD(pfd_dead_ring_t, pfd_elem_t) dead_ring;
+    /* number of threads in poll */
+    volatile apr_uint32_t waiting;
 };
 
 static apr_status_t backend_cleanup(void *p_)
@@ -164,6 +167,7 @@
         /* Add room for wakeup descriptor */
         size++;
     }
+    (*pollset)->waiting = 0;
     (*pollset)->nelts = 0;
     (*pollset)->nalloc = size;
     (*pollset)->flags = flags;
@@ -230,16 +234,22 @@
         fd = descriptor->desc.f->filedes;
     }
 
-    res = port_associate(pollset->port_fd, PORT_SOURCE_FD, fd, 
-                         get_event(descriptor->reqevents), (void *)elem);
-
-    if (res < 0) {
-        rv = APR_ENOMEM;
-        APR_RING_INSERT_TAIL(&(pollset->free_ring), elem, pfd_elem_t, link);
-    }
+    if (apr_atomic_read32(&pollset->waiting)) {
+        res = port_associate(pollset->port_fd, PORT_SOURCE_FD, fd, 
+                             get_event(descriptor->reqevents), (void *)elem);
+
+        if (res < 0) {
+            rv = APR_ENOMEM;
+            APR_RING_INSERT_TAIL(&(pollset->free_ring), elem, pfd_elem_t, link);
+        }
+        else {
+            pollset->nelts++;
+            APR_RING_INSERT_TAIL(&(pollset->query_ring), elem, pfd_elem_t, link);
+        }
+    } 
     else {
         pollset->nelts++;
-        APR_RING_INSERT_TAIL(&(pollset->query_ring), elem, pfd_elem_t, link);
+        APR_RING_INSERT_TAIL(&(pollset->add_ring), elem, pfd_elem_t, link);
     }
 
     pollset_unlock_rings();
@@ -254,6 +264,7 @@
     pfd_elem_t *ep;
     apr_status_t rv = APR_SUCCESS;
     int res;
+    int err;
 
     pollset_lock_rings();
 
@@ -267,6 +278,7 @@
     res = port_dissociate(pollset->port_fd, PORT_SOURCE_FD, fd);
 
     if (res < 0) {
+        err = errno;
         rv = APR_NOTFOUND;
     }
 
@@ -280,6 +292,9 @@
                 APR_RING_REMOVE(ep, link);
                 APR_RING_INSERT_TAIL(&(pollset->dead_ring),
                                      ep, pfd_elem_t, link);
+                if (ENOENT == err) {
+                    rv = APR_SUCCESS;
+                }
                 break;
             }
         }
@@ -331,6 +346,8 @@
 
     pollset_lock_rings();
 
+    apr_atomic_inc32(&pollset->waiting);
+
     while (!APR_RING_EMPTY(&(pollset->add_ring), pfd_elem_t, link)) {
         ep = APR_RING_FIRST(&(pollset->add_ring));
         APR_RING_REMOVE(ep, link);
@@ -354,6 +371,9 @@
     ret = port_getn(pollset->port_fd, pollset->port_set, pollset->nalloc,
                     &nget, tvptr);
 
+    /* decrease the waiting ASAP to reduce the window for calling 
+       port_associate within apr_pollset_add() */
+    apr_atomic_dec32(&pollset->waiting);
     (*num) = nget;
 
     if (ret == -1) {
@@ -539,6 +559,7 @@
             if (rv) {
                 return rv;
             }
+            rv = apr_pollcb_add(pollcb, pollfd);
         }
     }
 



Mime
View raw message