From dev-return-21844-apmail-apr-dev-archive=apr.apache.org@apr.apache.org Wed Jun 10 02:20:18 2009 Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 29551 invoked from network); 10 Jun 2009 02:20:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Jun 2009 02:20:18 -0000 Received: (qmail 83879 invoked by uid 500); 10 Jun 2009 02:20:29 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 83769 invoked by uid 500); 10 Jun 2009 02:20:29 -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 83761 invoked by uid 99); 10 Jun 2009 02:20:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jun 2009 02:20:29 +0000 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 150.101.121.179 as permitted sender) Received: from [150.101.121.179] (HELO beauty.rexursive.com) (150.101.121.179) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jun 2009 02:20:21 +0000 Received: from [10.1.120.24] (shrek.rexursive.com [10.1.120.24]) by beauty.rexursive.com (Postfix) with ESMTP id 8B6108C012; Wed, 10 Jun 2009 12:19:59 +1000 (EST) Subject: Re: [MAINTAINER] devel/apr-gdbm-db42: apr-util 1.3.7 breaks dbd support From: Bojan Smojver To: "William A. Rowe, Jr." Cc: dev@apr.apache.org In-Reply-To: <1244597651.25532.154.camel@shrek.rexursive.com> References: <200906090316.n593GCYQ075516@frieza.p6m7g8.net> <1244520824.25532.88.camel@shrek.rexursive.com> <4A2DF79D.709@rowe-clan.net> <4A2E001E.4020806@p6m7g8.com> <1244531713.25532.95.camel@shrek.rexursive.com> <4A2E0CB8.1090701@p6m7g8.com> <1244532560.25532.103.camel@shrek.rexursive.com> <1244534466.25532.113.camel@shrek.rexursive.com> <4A2E6BA4.7040305@rowe-clan.net> <20090609152157.GA15723@redhat.com> <4A2E86A0.5080005@rowe-clan.net> <1244595226.25532.146.camel@shrek.rexursive.com> <1244596384.25532.150.camel@shrek.rexursive.com> <1244597651.25532.154.camel@shrek.rexursive.com> Content-Type: multipart/mixed; boundary="=-2+vI9/2C4aStnTVjPLh4" Date: Wed, 10 Jun 2009 12:19:59 +1000 Message-Id: <1244600399.25532.156.camel@shrek.rexursive.com> Mime-Version: 1.0 X-Mailer: Evolution 2.26.2 (2.26.2-1.fc11) X-Virus-Checked: Checked by ClamAV on apache.org --=-2+vI9/2C4aStnTVjPLh4 Content-Type: text/plain Content-Transfer-Encoding: 7bit On Wed, 2009-06-10 at 11:34 +1000, Bojan Smojver wrote: > Or, maybe even this. Compiles and passes make check (surprisingly!). Here is a go-crazy patch. Deals with LDAP, DBD, DBM and DSO init itself. -- Bojan --=-2+vI9/2C4aStnTVjPLh4 Content-Disposition: attachment; filename="apu-dso-init-atomic.patch" Content-Type: text/x-patch; name="apu-dso-init-atomic.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit Index: ldap/apr_ldap_stub.c =================================================================== --- ldap/apr_ldap_stub.c (revision 783165) +++ ldap/apr_ldap_stub.c (working copy) @@ -23,6 +23,7 @@ #include "apr_errno.h" #include "apr_pools.h" #include "apr_strings.h" +#include "apr_atomic.h" #include "apu_version.h" #if APR_HAS_LDAP @@ -30,6 +31,7 @@ #if APU_DSO_BUILD static struct apr__ldap_dso_fntable *lfn = NULL; +static apr_uint32_t initialised = 0, in_init = 1; static apr_status_t load_ldap(apr_pool_t *pool) { @@ -37,11 +39,21 @@ apr_dso_handle_sym_t symbol; apr_status_t rv; + if (apr_atomic_inc32(&initialised)) { + apr_atomic_set32(&initialised, 1); /* prevent wrap-around */ + + while (apr_atomic_read32(&in_init)) /* wait until we get fully inited */ + ; + + return APR_SUCCESS; + } + /* deprecate in 2.0 - permit implicit initialization */ apu_dso_init(pool); rv = apu_dso_mutex_lock(); if (rv) { + apr_atomic_dec32(&in_init); return rv; } @@ -56,6 +68,8 @@ } apu_dso_mutex_unlock(); + apr_atomic_dec32(&in_init); + return rv; } Index: dbd/apr_dbd.c =================================================================== --- dbd/apr_dbd.c (revision 783165) +++ dbd/apr_dbd.c (working copy) @@ -26,6 +26,7 @@ #include "apr_hash.h" #include "apr_thread_mutex.h" #include "apr_lib.h" +#include "apr_atomic.h" #include "apu_internal.h" #include "apr_dbd_internal.h" @@ -33,6 +34,7 @@ #include "apu_version.h" static apr_hash_t *drivers = NULL; +static apr_uint32_t initialised = 0, in_init = 1; #define CLEANUP_CAST (apr_status_t (*)(void*)) @@ -90,7 +92,12 @@ apr_status_t ret = APR_SUCCESS; apr_pool_t *parent; - if (drivers != NULL) { + if (apr_atomic_inc32(&initialised)) { + apr_atomic_set32(&initialised, 1); /* prevent wrap-around */ + + while (apr_atomic_read32(&in_init)) /* wait until we get fully inited */ + ; + return APR_SUCCESS; } @@ -141,6 +148,8 @@ apr_pool_cleanup_register(pool, NULL, apr_dbd_term, apr_pool_cleanup_null); + apr_atomic_dec32(&in_init); + return ret; } Index: misc/apu_dso.c =================================================================== --- misc/apu_dso.c (revision 783165) +++ misc/apu_dso.c (working copy) @@ -27,6 +27,7 @@ #include "apr_hash.h" #include "apr_file_io.h" #include "apr_env.h" +#include "apr_atomic.h" #include "apu_internal.h" #include "apu_version.h" @@ -37,6 +38,7 @@ static apr_thread_mutex_t* mutex = NULL; #endif static apr_hash_t *dsos = NULL; +static apr_uint32_t initialised = 0, in_init = 1; #if APR_HAS_THREADS apr_status_t apu_dso_mutex_lock() @@ -76,7 +78,12 @@ apr_pool_t *global; apr_pool_t *parent; - if (dsos != NULL) { + if (apr_atomic_inc32(&initialised)) { + apr_atomic_set32(&initialised, 1); /* prevent wrap-around */ + + while (apr_atomic_read32(&in_init)) /* wait until we get fully inited */ + ; + return APR_SUCCESS; } @@ -94,6 +101,8 @@ apr_pool_cleanup_register(global, NULL, apu_dso_term, apr_pool_cleanup_null); + apr_atomic_dec32(&in_init); + return ret; } Index: dbm/apr_dbm.c =================================================================== --- dbm/apr_dbm.c (revision 783165) +++ dbm/apr_dbm.c (working copy) @@ -24,6 +24,7 @@ #define APR_WANT_STRFUNC #include "apr_want.h" #include "apr_general.h" +#include "apr_atomic.h" #include "apu_config.h" #include "apu.h" @@ -59,6 +60,7 @@ #if APU_DSO_BUILD static apr_hash_t *drivers = NULL; +static apr_uint32_t initialised = 0, in_init = 1; static apr_status_t dbm_term(void *ptr) { @@ -117,8 +119,13 @@ } else usertype = 1; - if (!drivers) - { + if (apr_atomic_inc32(&initialised)) { + apr_atomic_set32(&initialised, 1); /* prevent wrap-around */ + + while (apr_atomic_read32(&in_init)) /* wait until we get fully inited */ + ; + } + else { apr_pool_t *parent; /* Top level pool scope, need process-scope lifetime */ @@ -133,6 +140,8 @@ apr_pool_cleanup_register(pool, NULL, dbm_term, apr_pool_cleanup_null); + + apr_atomic_dec32(&in_init); } rv = apu_dso_mutex_lock(); --=-2+vI9/2C4aStnTVjPLh4--