Return-Path: Delivered-To: apmail-apr-commits-archive@www.apache.org Received: (qmail 40695 invoked from network); 5 Mar 2009 01:36:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Mar 2009 01:36:59 -0000 Received: (qmail 94548 invoked by uid 500); 5 Mar 2009 01:36:59 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 94501 invoked by uid 500); 5 Mar 2009 01:36:59 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 94492 invoked by uid 99); 5 Mar 2009 01:36:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Mar 2009 17:36:59 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Mar 2009 01:36:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 26CFD23888A3; Thu, 5 Mar 2009 01:36:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r750277 - /apr/apr/trunk/poll/unix/port.c Date: Thu, 05 Mar 2009 01:36:35 -0000 To: commits@apr.apache.org From: trawick@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090305013636.26CFD23888A3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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; } }