apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r750277 - /apr/apr/trunk/poll/unix/port.c
Date Thu, 05 Mar 2009 01:36:35 GMT
Author: trawick
Date: Thu Mar  5 01:36:34 2009
New Revision: 750277

URL: http://svn.apache.org/viewvc?rev=750277&view=rev
Log:
when removing a pollfd, don't search both the add ring
and the query ring; it can be on only one of them

reverse the search order of the two lists, so that we
search the (often) shorter/more likelier list first

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

Modified: apr/apr/trunk/poll/unix/port.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/port.c?rev=750277&r1=750276&r2=750277&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/port.c (original)
+++ apr/apr/trunk/poll/unix/port.c Thu Mar  5 01:36:34 2009
@@ -206,6 +206,7 @@
     apr_status_t rv = APR_SUCCESS;
     int res;
     int err = 0;
+    int found;
 
     pollset_lock_rings();
 
@@ -223,12 +224,21 @@
         rv = APR_NOTFOUND;
     }
 
-    for (ep = APR_RING_FIRST(&(pollset->p->query_ring));
-         ep != APR_RING_SENTINEL(&(pollset->p->query_ring),
+    /* Search the add ring first.  This ring is often shorter,
+     * and it often contains the descriptor being removed.  
+     * (For the common scenario where apr_pollset_poll() 
+     * returns activity for the descriptor and the descriptor
+     * is then removed from the pollset, it will have just 
+     * been moved to the add ring by apr_pollset_poll().)
+     */
+    found = 0;
+    for (ep = APR_RING_FIRST(&(pollset->p->add_ring));
+         ep != APR_RING_SENTINEL(&(pollset->p->add_ring),
                                  pfd_elem_t, link);
          ep = APR_RING_NEXT(ep, link)) {
 
         if (descriptor->desc.s == ep->pfd.desc.s) {
+            found = 1;
             APR_RING_REMOVE(ep, link);
             APR_RING_INSERT_TAIL(&(pollset->p->dead_ring),
                                  ep, pfd_elem_t, link);
@@ -239,19 +249,21 @@
         }
     }
 
-    for (ep = APR_RING_FIRST(&(pollset->p->add_ring));
-         ep != APR_RING_SENTINEL(&(pollset->p->add_ring),
-                                 pfd_elem_t, link);
-         ep = APR_RING_NEXT(ep, link)) {
-
-        if (descriptor->desc.s == ep->pfd.desc.s) {
-            APR_RING_REMOVE(ep, link);
-            APR_RING_INSERT_TAIL(&(pollset->p->dead_ring),
-                                 ep, pfd_elem_t, link);
-            if (ENOENT == err) {
-                rv = APR_SUCCESS;
+    if (!found) {
+        for (ep = APR_RING_FIRST(&(pollset->p->query_ring));
+             ep != APR_RING_SENTINEL(&(pollset->p->query_ring),
+                                     pfd_elem_t, link);
+             ep = APR_RING_NEXT(ep, link)) {
+
+            if (descriptor->desc.s == ep->pfd.desc.s) {
+                APR_RING_REMOVE(ep, link);
+                APR_RING_INSERT_TAIL(&(pollset->p->dead_ring),
+                                     ep, pfd_elem_t, link);
+                if (ENOENT == err) {
+                    rv = APR_SUCCESS;
+                }
+                break;
             }
-            break;
         }
     }
 



Mime
View raw message