diff options
author | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2000-12-31 18:04:59 +0000 |
---|---|---|
committer | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2000-12-31 18:04:59 +0000 |
commit | 5296d3a23c0d72e25babb5583022d967c6e25a1d (patch) | |
tree | 70826f2043746d9a69f5672a20916d48b9271b67 /lib | |
parent | 738306c3aec80624d3f511762b32176a17a23866 (diff) | |
download | libapr-5296d3a23c0d72e25babb5583022d967c6e25a1d.tar.gz |
Begin to remove the ability to allocate out of NULL pools. The first
problem to solve, is that we need an apr_lock in order to allocate
pools, so that we can lock things out when allocating. So, how do we
allocate locks without a pool to allocate from? The answer is to create
a global_apr_pool, which is a bootstrapping pool. There should NEVER
be a sub-pool off this pool, and it is static to an APR file. This is
only used to allow us to allocate the locks cleanly, without using the
NULL pool hack.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@60997 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'lib')
-rw-r--r-- | lib/apr_pools.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/lib/apr_pools.c b/lib/apr_pools.c index 5b2889fe7..867842d6a 100644 --- a/lib/apr_pools.c +++ b/lib/apr_pools.c @@ -469,7 +469,9 @@ APR_DECLARE(apr_pool_t *) apr_make_sub_pool(apr_pool_t *p, int (*apr_abort)(int #if APR_HAS_THREADS - apr_lock(alloc_mutex); + if (alloc_mutex) { + apr_lock(alloc_mutex); + } #endif blok = new_block(POOL_HDR_BYTES, apr_abort); @@ -496,7 +498,9 @@ APR_DECLARE(apr_pool_t *) apr_make_sub_pool(apr_pool_t *p, int (*apr_abort)(int } #if APR_HAS_THREADS - apr_unlock(alloc_mutex); + if (alloc_mutex) { + apr_unlock(alloc_mutex); + } #endif return new_pool; @@ -662,7 +666,7 @@ APR_DECLARE_NONSTD(apr_status_t) apr_null_cleanup(void *data) return APR_SUCCESS; } -apr_status_t apr_init_alloc(void) +apr_status_t apr_init_alloc(apr_pool_t *globalp) { #if APR_HAS_THREADS apr_status_t status; @@ -675,13 +679,13 @@ apr_status_t apr_init_alloc(void) #endif #if APR_HAS_THREADS status = apr_create_lock(&alloc_mutex, APR_MUTEX, APR_INTRAPROCESS, - NULL, NULL); + NULL, globalp); if (status != APR_SUCCESS) { apr_destroy_lock(alloc_mutex); return status; } status = apr_create_lock(&spawn_mutex, APR_MUTEX, APR_INTRAPROCESS, - NULL, NULL); + NULL, globalp); if (status != APR_SUCCESS) { apr_destroy_lock(spawn_mutex); return status; @@ -695,12 +699,13 @@ apr_status_t apr_init_alloc(void) return APR_SUCCESS; } -void apr_term_alloc(void) +void apr_term_alloc(apr_pool_t *globalp) { #if APR_HAS_THREADS apr_destroy_lock(alloc_mutex); apr_destroy_lock(spawn_mutex); #endif + apr_destroy_pool(globalp); } /* We only want to lock the mutex if we are being called from apr_clear_pool. @@ -748,7 +753,9 @@ APR_DECLARE(void) apr_destroy_pool(apr_pool_t *a) { apr_clear_pool(a); #if APR_HAS_THREADS - apr_lock(alloc_mutex); + if (alloc_mutex) { + apr_lock(alloc_mutex); + } #endif if (a->parent) { @@ -763,7 +770,9 @@ APR_DECLARE(void) apr_destroy_pool(apr_pool_t *a) } } #if APR_HAS_THREADS - apr_unlock(alloc_mutex); + if (alloc_mutex) { + apr_unlock(alloc_mutex); + } #endif free_blocks(a->first); } @@ -928,15 +937,15 @@ APR_DECLARE(void*) apr_palloc(apr_pool_t *a, apr_size_t reqsize) char *first_avail; char *new_first_avail; + nclicks = 1 + ((reqsize - 1) / CLICK_SZ); + size = nclicks * CLICK_SZ; + if (a == NULL) { return malloc(reqsize); } - nclicks = 1 + ((reqsize - 1) / CLICK_SZ); - size = nclicks * CLICK_SZ; - /* First, see if we have space in the block most recently * allocated to this pool */ @@ -961,7 +970,9 @@ APR_DECLARE(void*) apr_palloc(apr_pool_t *a, apr_size_t reqsize) /* Nope --- get a new one that's guaranteed to be big enough */ #if APR_HAS_THREADS - apr_lock(alloc_mutex); + if (alloc_mutex) { + apr_lock(alloc_mutex); + } #endif blok = new_block(size, a->apr_abort); @@ -972,7 +983,9 @@ APR_DECLARE(void*) apr_palloc(apr_pool_t *a, apr_size_t reqsize) #endif #if APR_HAS_THREADS - apr_unlock(alloc_mutex); + if (alloc_mutex) { + apr_unlock(alloc_mutex); + } #endif first_avail = blok->h.first_avail; |