diff options
author | Bojan Smojver <bojan@apache.org> | 2009-06-10 23:54:00 +0000 |
---|---|---|
committer | Bojan Smojver <bojan@apache.org> | 2009-06-10 23:54:00 +0000 |
commit | 2cb686f67a983ec062fa74bb249a879658b0c81a (patch) | |
tree | a4275d98814788cd168ee23dd2c5b62a8761edb0 /dbm | |
parent | e4e3109c8b6d7443a86c297dccf7eefd54e49777 (diff) | |
download | apr-2cb686f67a983ec062fa74bb249a879658b0c81a.tar.gz |
Fix race conditions in initialisation of DBD, DBM and DSO.
For 2.0, this is just a temporary solution, until this is re-engineered.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@783580 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'dbm')
-rw-r--r-- | dbm/apr_dbm.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/dbm/apr_dbm.c b/dbm/apr_dbm.c index 8484fa0c1..bbe937d81 100644 --- a/dbm/apr_dbm.c +++ b/dbm/apr_dbm.c @@ -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 @@ static apr_status_t dbm_open_type(apr_dbm_type_t const* * vtable, } 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 @@ static apr_status_t dbm_open_type(apr_dbm_type_t const* * vtable, apr_pool_cleanup_register(pool, NULL, dbm_term, apr_pool_cleanup_null); + + apr_atomic_dec32(&in_init); } rv = apu_dso_mutex_lock(); |