From dev-return-20816-apmail-apr-dev-archive=apr.apache.org@apr.apache.org Mon Jul 21 12:07:02 2008 Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 37122 invoked from network); 21 Jul 2008 12:07:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Jul 2008 12:07:01 -0000 Received: (qmail 97675 invoked by uid 500); 21 Jul 2008 12:07:00 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 97638 invoked by uid 500); 21 Jul 2008 12:07:00 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 97627 invoked by uid 99); 21 Jul 2008 12:07:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Jul 2008 05:07:00 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of bojan@rexursive.com designates 203.171.74.242 as permitted sender) Received: from [203.171.74.242] (HELO beauty.rexursive.com) (203.171.74.242) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Jul 2008 12:06:07 +0000 Received: from [10.1.120.24] (shrek.rexursive.com [10.1.120.24]) by beauty.rexursive.com (Postfix) with ESMTP id 78A7D40330 for ; Mon, 21 Jul 2008 22:06:00 +1000 (EST) Subject: Re: Changing the order of cleanup for some core objects From: Bojan Smojver To: dev@apr.apache.org In-Reply-To: <20080721211653.15551u9ecvjep1y8@www.rexursive.com> References: <48843999.1010804@apache.org> <20080721093425.GA13566@redhat.com> <4884671A.8070401@apache.org> <20080721211653.15551u9ecvjep1y8@www.rexursive.com> Content-Type: multipart/mixed; boundary="=-QgWBwogS2ZLa7ZCEZ1Fe" Date: Mon, 21 Jul 2008 22:05:57 +1000 Message-Id: <1216641957.2754.93.camel@shrek.rexursive.com> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 (2.22.3.1-1.fc9) X-Virus-Checked: Checked by ClamAV on apache.org --=-QgWBwogS2ZLa7ZCEZ1Fe Content-Type: text/plain Content-Transfer-Encoding: 7bit On Mon, 2008-07-21 at 21:16 +1000, Bojan Smojver wrote: > How about we have apr_pool_destroy_safe(). We give it two arguments: For example... Don't mind the details, especially locks - they are most likely all screwed up. -- Bojan --=-QgWBwogS2ZLa7ZCEZ1Fe Content-Disposition: attachment; filename=apr-pool_destroy_safe.patch Content-Type: text/x-patch; name=apr-pool_destroy_safe.patch; charset=utf-8 Content-Transfer-Encoding: 7bit Index: memory/unix/apr_pools.c =================================================================== --- memory/unix/apr_pools.c (revision 678146) +++ memory/unix/apr_pools.c (working copy) @@ -825,6 +825,62 @@ } } +static apr_status_t find_pool(apr_pool_t *root, apr_pool_t *pool) +{ + apr_status_t rv; + apr_pool_t *p; + + for (p = root; p; p = p->sibling) { + if (p == pool) { + return APR_SUCCESS; + } + else { +#if APR_HAS_THREADS + apr_thread_mutex_t *mutex; + + if ((mutex = apr_allocator_mutex_get(p->allocator)) != NULL) + apr_thread_mutex_lock(mutex); +#endif /* APR_HAS_THREADS */ + + rv = find_pool (p->child, pool); + +#if APR_HAS_THREADS + if (mutex) + apr_thread_mutex_unlock(mutex); +#endif /* APR_HAS_THREADS */ + + if (rv == APR_SUCCESS) { + return rv; + } + } + } + + return APR_EGENERAL; +} + +APR_DECLARE(void) apr_pool_destroy_safe(apr_pool_t *pool,apr_pool_t *root) +{ + apr_status_t rv; +#if APR_HAS_THREADS + apr_thread_mutex_t *mutex; + + if (root == NULL) + root = global_pool; + + if ((mutex = apr_allocator_mutex_get(root->allocator)) != NULL) + apr_thread_mutex_lock(mutex); +#endif /* APR_HAS_THREADS */ + + rv = find_pool(root->child, pool); + if (rv == APR_SUCCESS) + apr_pool_destroy(pool); + +#if APR_HAS_THREADS + if (mutex) + apr_thread_mutex_unlock(mutex); +#endif /* APR_HAS_THREADS */ +} + APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool, apr_pool_t *parent, apr_abortfunc_t abort_fn, --=-QgWBwogS2ZLa7ZCEZ1Fe--