On Wed, 2009-06-10 at 13:51 +1000, Bojan Smojver wrote:
> Actually, that LDAP thing is not required.
So, here are the two patches. One for trunk (for now, until this gets
fixed properly) and one for 1.3.x/1.4.x.
--
Bojan
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();
Index: util-misc/apu_dso.c
===================================================================
--- util-misc/apu_dso.c (revision 782823)
+++ util-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: dbd/apr_dbd.c
===================================================================
--- dbd/apr_dbd.c (revision 782823)
+++ 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: dbm/apr_dbm.c
===================================================================
--- dbm/apr_dbm.c (revision 782823)
+++ 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 APR_HAVE_MODULAR_DSO
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();