You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bo...@apache.org on 2009/06/11 01:54:42 UTC
svn commit: r783581 - in /apr/apr-util/branches/1.4.x: CHANGES dbd/apr_dbd.c
dbm/apr_dbm.c misc/apu_dso.c
Author: bojan
Date: Wed Jun 10 23:54:42 2009
New Revision: 783581
URL: http://svn.apache.org/viewvc?rev=783581&view=rev
Log:
Backport r783580 from the trunk.
Fix race conditions in initialisation of DBD, DBM and DSO.
Modified:
apr/apr-util/branches/1.4.x/CHANGES
apr/apr-util/branches/1.4.x/dbd/apr_dbd.c
apr/apr-util/branches/1.4.x/dbm/apr_dbm.c
apr/apr-util/branches/1.4.x/misc/apu_dso.c
Modified: apr/apr-util/branches/1.4.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.4.x/CHANGES?rev=783581&r1=783580&r2=783581&view=diff
==============================================================================
--- apr/apr-util/branches/1.4.x/CHANGES [utf-8] (original)
+++ apr/apr-util/branches/1.4.x/CHANGES [utf-8] Wed Jun 10 23:54:42 2009
@@ -1,6 +1,9 @@
-*- coding: utf-8 -*-
Changes with APR-util 1.4.0
+ *) Fix race conditions in initialisation of DBD, DBM and DSO.
+ [Bojan Smojver]
+
*) Expose DBM libs in apu-1-config by default. To avoid that, use
apu-1-config --avoid-dbm --libs. To get just DBM libs, use
apu-1-config --dbm-libs.
Modified: apr/apr-util/branches/1.4.x/dbd/apr_dbd.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.4.x/dbd/apr_dbd.c?rev=783581&r1=783580&r2=783581&view=diff
==============================================================================
--- apr/apr-util/branches/1.4.x/dbd/apr_dbd.c (original)
+++ apr/apr-util/branches/1.4.x/dbd/apr_dbd.c Wed Jun 10 23:54:42 2009
@@ -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;
}
Modified: apr/apr-util/branches/1.4.x/dbm/apr_dbm.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.4.x/dbm/apr_dbm.c?rev=783581&r1=783580&r2=783581&view=diff
==============================================================================
--- apr/apr-util/branches/1.4.x/dbm/apr_dbm.c (original)
+++ apr/apr-util/branches/1.4.x/dbm/apr_dbm.c Wed Jun 10 23:54:42 2009
@@ -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();
Modified: apr/apr-util/branches/1.4.x/misc/apu_dso.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.4.x/misc/apu_dso.c?rev=783581&r1=783580&r2=783581&view=diff
==============================================================================
--- apr/apr-util/branches/1.4.x/misc/apu_dso.c (original)
+++ apr/apr-util/branches/1.4.x/misc/apu_dso.c Wed Jun 10 23:54:42 2009
@@ -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;
}