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 /util-misc | |
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 'util-misc')
-rw-r--r-- | util-misc/apu_dso.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/util-misc/apu_dso.c b/util-misc/apu_dso.c index 0a7a26ca2..d543b46d2 100644 --- a/util-misc/apu_dso.c +++ b/util-misc/apu_dso.c @@ -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_status_t apu_dso_init(apr_pool_t *pool) 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_status_t apu_dso_init(apr_pool_t *pool) apr_pool_cleanup_register(global, NULL, apu_dso_term, apr_pool_cleanup_null); + apr_atomic_dec32(&in_init); + return ret; } |