diff options
author | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2000-03-28 22:59:05 +0000 |
---|---|---|
committer | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2000-03-28 22:59:05 +0000 |
commit | a0db1468f6ffc39a6a43869ae28e9524062d9f8c (patch) | |
tree | 2a5ef441659e4361c32beba9da9c75ee5fd86639 | |
parent | ba6dde974fa3859de9d9b2b98dbfe6fc194e8ea4 (diff) | |
download | libapr-a0db1468f6ffc39a6a43869ae28e9524062d9f8c.tar.gz |
Tweaked APR initialization and termination so that the lifetime
of memory management mutexes is longer than the lifetime of
managed memory. APR apps must now call ap_terminate().
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@59746 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | aprlib.def | 1 | ||||
-rw-r--r-- | include/apr_general.h | 1 | ||||
-rw-r--r-- | include/apr_pools.h | 3 | ||||
-rw-r--r-- | lib/apr_pools.c | 38 | ||||
-rw-r--r-- | libapr.def | 1 | ||||
-rw-r--r-- | memory/unix/apr_pools.c | 38 | ||||
-rw-r--r-- | misc/beos/start.c | 13 | ||||
-rw-r--r-- | misc/unix/start.c | 18 | ||||
-rw-r--r-- | misc/win32/start.c | 11 |
9 files changed, 74 insertions, 50 deletions
diff --git a/aprlib.def b/aprlib.def index 1f51e7323..7a723b440 100644 --- a/aprlib.def +++ b/aprlib.def @@ -236,4 +236,5 @@ EXPORTS ap_set_remote_port @215 ap_open_stderr @216 ap_set_pipe_timeout @217 + ap_terminate @218 diff --git a/include/apr_general.h b/include/apr_general.h index 9a9e60dc5..24676d467 100644 --- a/include/apr_general.h +++ b/include/apr_general.h @@ -228,6 +228,7 @@ ap_status_t ap_set_userdata(void *data, char *key, ap_context_t *cont); ap_status_t ap_get_userdata(void **, char *key, ap_context_t *cont); ap_status_t ap_initialize(void); +void ap_terminate(void); ap_status_t ap_set_abort(int (*apr_abort)(int retcode), ap_context_t *cont); #ifdef __cplusplus diff --git a/include/apr_pools.h b/include/apr_pools.h index 1219e332c..6782283a2 100644 --- a/include/apr_pools.h +++ b/include/apr_pools.h @@ -135,7 +135,8 @@ struct ap_table_t { * currently being used... */ -ap_pool_t *ap_init_alloc(void); /* Set up everything */ +ap_status_t ap_init_alloc(void); /* Set up everything */ +void ap_term_alloc(void); /* Tear down everything */ /* used to guarantee to the pool debugging code that the sub pool will not be * destroyed before the parent pool diff --git a/lib/apr_pools.c b/lib/apr_pools.c index c1cbbc911..f2928f2c8 100644 --- a/lib/apr_pools.c +++ b/lib/apr_pools.c @@ -528,6 +528,9 @@ API_EXPORT(ap_pool_t *) ap_make_sub_pool(ap_pool_t *p, int (*apr_abort)(int retc } p->sub_pools = new_pool; } + else { + permanent_pool = p; + } #if APR_HAS_THREADS ap_unlock(alloc_mutex); @@ -580,6 +583,7 @@ struct cleanup { static void * ap_pool_palloc(ap_pool_t *a, int reqsize, int (*apr_abort)(int retcode)); +#if 0 static void ap_register_pool_cleanup(struct ap_pool_t *p, void *data, ap_status_t (*plain_cleanup) (void *), ap_status_t (*child_cleanup) (void *)) @@ -595,6 +599,7 @@ static void ap_register_pool_cleanup(struct ap_pool_t *p, void *data, p->cleanups = c; } } +#endif API_EXPORT(void) ap_register_cleanup(struct context_t *p, void *data, ap_status_t (*plain_cleanup) (void *), @@ -692,13 +697,7 @@ API_EXPORT_NONSTD(ap_status_t) ap_null_cleanup(void *data) return APR_SUCCESS; } -static ap_status_t cleanup_locks(void *data) -{ - ap_lock_t *thelock = (ap_lock_t *)data; - return ap_destroy_lock(thelock); -} - -ap_pool_t *ap_init_alloc(void) +ap_status_t ap_init_alloc(void) { ap_status_t status; #ifdef POOL_DEBUG @@ -712,32 +711,29 @@ ap_pool_t *ap_init_alloc(void) NULL, NULL); if (status != APR_SUCCESS) { ap_destroy_lock(alloc_mutex); - return NULL; + return status; } status = ap_create_lock(&spawn_mutex, APR_MUTEX, APR_INTRAPROCESS, NULL, NULL); if (status != APR_SUCCESS) { ap_destroy_lock(spawn_mutex); - return NULL; + return status; } #endif - permanent_pool = ap_make_sub_pool(NULL, NULL); - -#if APR_HAS_THREADS - ap_register_pool_cleanup(permanent_pool, (void *)alloc_mutex, - cleanup_locks, - ap_null_cleanup); - ap_register_pool_cleanup(permanent_pool, spawn_mutex, - cleanup_locks, - ap_null_cleanup); -#endif - #ifdef ALLOC_STATS atexit(dump_stats); #endif - return permanent_pool; + return APR_SUCCESS; +} + +void ap_term_alloc(void) +{ +#if APR_HAS_THREADS + ap_destroy_lock(alloc_mutex); + ap_destroy_lock(spawn_mutex); +#endif } void ap_destroy_real_pool(ap_pool_t *); diff --git a/libapr.def b/libapr.def index 1f51e7323..7a723b440 100644 --- a/libapr.def +++ b/libapr.def @@ -236,4 +236,5 @@ EXPORTS ap_set_remote_port @215 ap_open_stderr @216 ap_set_pipe_timeout @217 + ap_terminate @218 diff --git a/memory/unix/apr_pools.c b/memory/unix/apr_pools.c index c1cbbc911..f2928f2c8 100644 --- a/memory/unix/apr_pools.c +++ b/memory/unix/apr_pools.c @@ -528,6 +528,9 @@ API_EXPORT(ap_pool_t *) ap_make_sub_pool(ap_pool_t *p, int (*apr_abort)(int retc } p->sub_pools = new_pool; } + else { + permanent_pool = p; + } #if APR_HAS_THREADS ap_unlock(alloc_mutex); @@ -580,6 +583,7 @@ struct cleanup { static void * ap_pool_palloc(ap_pool_t *a, int reqsize, int (*apr_abort)(int retcode)); +#if 0 static void ap_register_pool_cleanup(struct ap_pool_t *p, void *data, ap_status_t (*plain_cleanup) (void *), ap_status_t (*child_cleanup) (void *)) @@ -595,6 +599,7 @@ static void ap_register_pool_cleanup(struct ap_pool_t *p, void *data, p->cleanups = c; } } +#endif API_EXPORT(void) ap_register_cleanup(struct context_t *p, void *data, ap_status_t (*plain_cleanup) (void *), @@ -692,13 +697,7 @@ API_EXPORT_NONSTD(ap_status_t) ap_null_cleanup(void *data) return APR_SUCCESS; } -static ap_status_t cleanup_locks(void *data) -{ - ap_lock_t *thelock = (ap_lock_t *)data; - return ap_destroy_lock(thelock); -} - -ap_pool_t *ap_init_alloc(void) +ap_status_t ap_init_alloc(void) { ap_status_t status; #ifdef POOL_DEBUG @@ -712,32 +711,29 @@ ap_pool_t *ap_init_alloc(void) NULL, NULL); if (status != APR_SUCCESS) { ap_destroy_lock(alloc_mutex); - return NULL; + return status; } status = ap_create_lock(&spawn_mutex, APR_MUTEX, APR_INTRAPROCESS, NULL, NULL); if (status != APR_SUCCESS) { ap_destroy_lock(spawn_mutex); - return NULL; + return status; } #endif - permanent_pool = ap_make_sub_pool(NULL, NULL); - -#if APR_HAS_THREADS - ap_register_pool_cleanup(permanent_pool, (void *)alloc_mutex, - cleanup_locks, - ap_null_cleanup); - ap_register_pool_cleanup(permanent_pool, spawn_mutex, - cleanup_locks, - ap_null_cleanup); -#endif - #ifdef ALLOC_STATS atexit(dump_stats); #endif - return permanent_pool; + return APR_SUCCESS; +} + +void ap_term_alloc(void) +{ +#if APR_HAS_THREADS + ap_destroy_lock(alloc_mutex); + ap_destroy_lock(spawn_mutex); +#endif } void ap_destroy_real_pool(ap_pool_t *); diff --git a/misc/beos/start.c b/misc/beos/start.c index e28ca3e6e..55c9b2f58 100644 --- a/misc/beos/start.c +++ b/misc/beos/start.c @@ -64,7 +64,7 @@ ap_status_t ap_create_context(struct context_t **newcont, struct context_t *cont pool = ap_make_sub_pool(cont->pool, cont->apr_abort); } else { - pool = ap_init_alloc();; + pool = ap_make_sub_pool(NULL, NULL); } if (pool == NULL) { @@ -142,6 +142,13 @@ ap_status_t ap_get_userdata(void **data, char *key, struct context_t *cont) ap_status_t ap_initialize(void) { - return APR_SUCCESS; + ap_status_t status; + status = ap_init_alloc(); + return status; } - + +void ap_terminate(void) +{ + ap_term_alloc(); +} + diff --git a/misc/unix/start.c b/misc/unix/start.c index 01e8bb163..aed981a14 100644 --- a/misc/unix/start.c +++ b/misc/unix/start.c @@ -74,7 +74,7 @@ ap_status_t ap_create_context(struct context_t **newcont, struct context_t *cont pool = ap_make_sub_pool(cont->pool, cont->apr_abort); } else { - pool = ap_init_alloc();; + pool = ap_make_sub_pool(NULL, NULL); } if (pool == NULL) { @@ -188,8 +188,22 @@ ap_status_t ap_get_userdata(void **data, char *key, struct context_t *cont) */ ap_status_t ap_initialize(void) { + ap_status_t status; setup_lock(); - return APR_SUCCESS; + status = ap_init_alloc(); + return status; +} + +/* ***APRDOC******************************************************* + * void ap_terminate(void) + * Tear down any APR internal data structures which aren't + * torn down automatically. An APR program must call this + * function at termination once it has stopped using APR + * services. + */ +void ap_terminate(void) +{ + ap_term_alloc(); } /* ***APRDOC******************************************************** diff --git a/misc/win32/start.c b/misc/win32/start.c index 070308798..d3d61c6fc 100644 --- a/misc/win32/start.c +++ b/misc/win32/start.c @@ -81,7 +81,7 @@ ap_status_t ap_create_context(ap_context_t **newcont, ap_context_t *cont) pool = ap_make_sub_pool(cont->pool, cont->apr_abort); } else { - pool = ap_init_alloc();; + pool = ap_make_sub_pool(NULL, NULL); } if (pool == NULL) { @@ -200,6 +200,7 @@ ap_status_t ap_get_userdata(void **data, char *key, struct context_t *cont) /* This puts one thread in a Listen for signals mode */ ap_status_t ap_initialize(void) { + ap_status_t status; #if 0 unsigned tid; @@ -211,5 +212,11 @@ ap_status_t ap_initialize(void) sleep(1); } #endif - return APR_SUCCESS; + status = ap_init_alloc(); + return status; +} + +void ap_terminate(void) +{ + ap_term_alloc(); } |