diff options
Diffstat (limited to 'srclib/apr-util/misc')
-rw-r--r-- | srclib/apr-util/misc/apr_reslist.c | 76 | ||||
-rw-r--r-- | srclib/apr-util/misc/apr_thread_pool.c | 20 | ||||
-rw-r--r-- | srclib/apr-util/misc/apu_dso.c | 11 |
3 files changed, 91 insertions, 16 deletions
diff --git a/srclib/apr-util/misc/apr_reslist.c b/srclib/apr-util/misc/apr_reslist.c index ed2d15b7..0c43e074 100644 --- a/srclib/apr-util/misc/apr_reslist.c +++ b/srclib/apr-util/misc/apr_reslist.c @@ -24,8 +24,6 @@ #include "apr_thread_cond.h" #include "apr_ring.h" -#if APR_HAS_THREADS - /** * A single resource element. */ @@ -56,8 +54,10 @@ struct apr_reslist_t { void *params; /* opaque data passed to constructor and destructor calls */ apr_resring_t avail_list; apr_resring_t free_list; +#if APR_HAS_THREADS apr_thread_mutex_t *listlock; apr_thread_cond_t *avail; +#endif }; /** @@ -141,7 +141,9 @@ static apr_status_t reslist_cleanup(void *data_) apr_reslist_t *rl = data_; apr_res_t *res; +#if APR_HAS_THREADS apr_thread_mutex_lock(rl->listlock); +#endif while (rl->nidle > 0) { apr_status_t rv1; @@ -158,9 +160,11 @@ static apr_status_t reslist_cleanup(void *data_) assert(rl->nidle == 0); assert(rl->ntotal == 0); +#if APR_HAS_THREADS apr_thread_mutex_unlock(rl->listlock); apr_thread_mutex_destroy(rl->listlock); apr_thread_cond_destroy(rl->avail); +#endif return rv; } @@ -169,14 +173,16 @@ static apr_status_t reslist_cleanup(void *data_) * Perform routine maintenance on the resource list. This call * may instantiate new resources or expire old resources. */ -static apr_status_t reslist_maint(apr_reslist_t *reslist) +APU_DECLARE(apr_status_t) apr_reslist_maintain(apr_reslist_t *reslist) { apr_time_t now; apr_status_t rv; apr_res_t *res; int created_one = 0; +#if APR_HAS_THREADS apr_thread_mutex_lock(reslist->listlock); +#endif /* Check if we need to create more resources, and if we are allowed to. */ while (reslist->nidle < reslist->min && reslist->ntotal < reslist->hmax) { @@ -184,7 +190,9 @@ static apr_status_t reslist_maint(apr_reslist_t *reslist) rv = create_resource(reslist, &res); if (rv != APR_SUCCESS) { free_container(reslist, res); +#if APR_HAS_THREADS apr_thread_mutex_unlock(reslist->listlock); +#endif return rv; } /* Add it to the list */ @@ -192,17 +200,21 @@ static apr_status_t reslist_maint(apr_reslist_t *reslist) /* Update our counters */ reslist->ntotal++; /* If someone is waiting on that guy, wake them up. */ +#if APR_HAS_THREADS rv = apr_thread_cond_signal(reslist->avail); if (rv != APR_SUCCESS) { apr_thread_mutex_unlock(reslist->listlock); return rv; } +#endif created_one++; } /* We don't need to see if we're over the max if we were under it before */ if (created_one) { +#if APR_HAS_THREADS apr_thread_mutex_unlock(reslist->listlock); +#endif return APR_SUCCESS; } @@ -223,12 +235,16 @@ static apr_status_t reslist_maint(apr_reslist_t *reslist) rv = destroy_resource(reslist, res); free_container(reslist, res); if (rv != APR_SUCCESS) { +#if APR_HAS_THREADS apr_thread_mutex_unlock(reslist->listlock); +#endif return rv; } } +#if APR_HAS_THREADS apr_thread_mutex_unlock(reslist->listlock); +#endif return APR_SUCCESS; } @@ -250,6 +266,17 @@ APU_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist, return APR_EINVAL; } +#if !APR_HAS_THREADS + /* There can be only one resource when we have no threads. */ + if (min > 0) { + min = 1; + } + if (smax > 0) { + smax = 1; + } + hmax = 1; +#endif + rl = apr_pcalloc(pool, sizeof(*rl)); rl->pool = pool; rl->min = min; @@ -263,6 +290,7 @@ APU_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist, APR_RING_INIT(&rl->avail_list, apr_res_t, link); APR_RING_INIT(&rl->free_list, apr_res_t, link); +#if APR_HAS_THREADS rv = apr_thread_mutex_create(&rl->listlock, APR_THREAD_MUTEX_DEFAULT, pool); if (rv != APR_SUCCESS) { @@ -272,8 +300,9 @@ APU_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist, if (rv != APR_SUCCESS) { return rv; } +#endif - rv = reslist_maint(rl); + rv = apr_reslist_maintain(rl); if (rv != APR_SUCCESS) { /* Destroy what we've created so far. */ @@ -301,7 +330,9 @@ APU_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist, apr_res_t *res; apr_time_t now; +#if APR_HAS_THREADS apr_thread_mutex_lock(reslist->listlock); +#endif /* If there are idle resources on the available list, use * them right away. */ now = apr_time_now(); @@ -314,19 +345,24 @@ APU_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist, rv = destroy_resource(reslist, res); free_container(reslist, res); if (rv != APR_SUCCESS) { +#if APR_HAS_THREADS apr_thread_mutex_unlock(reslist->listlock); +#endif return rv; /* FIXME: this might cause unnecessary fails */ } continue; } *resource = res->opaque; free_container(reslist, res); +#if APR_HAS_THREADS apr_thread_mutex_unlock(reslist->listlock); +#endif return APR_SUCCESS; } /* If we've hit our max, block until we're allowed to create * a new one, or something becomes free. */ while (reslist->ntotal >= reslist->hmax && reslist->nidle <= 0) { +#if APR_HAS_THREADS if (reslist->timeout) { if ((rv = apr_thread_cond_timedwait(reslist->avail, reslist->listlock, reslist->timeout)) != APR_SUCCESS) { @@ -337,6 +373,9 @@ APU_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist, else { apr_thread_cond_wait(reslist->avail, reslist->listlock); } +#else + return APR_EAGAIN; +#endif } /* If we popped out of the loop, first try to see if there * are new resources available for immediate use. */ @@ -344,7 +383,9 @@ APU_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist, res = pop_resource(reslist); *resource = res->opaque; free_container(reslist, res); +#if APR_HAS_THREADS apr_thread_mutex_unlock(reslist->listlock); +#endif return APR_SUCCESS; } /* Otherwise the reason we dropped out of the loop @@ -357,7 +398,9 @@ APU_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist, *resource = res->opaque; } free_container(reslist, res); +#if APR_HAS_THREADS apr_thread_mutex_unlock(reslist->listlock); +#endif return rv; } } @@ -367,14 +410,18 @@ APU_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist, { apr_res_t *res; +#if APR_HAS_THREADS apr_thread_mutex_lock(reslist->listlock); +#endif res = get_container(reslist); res->opaque = resource; push_resource(reslist, res); +#if APR_HAS_THREADS apr_thread_cond_signal(reslist->avail); apr_thread_mutex_unlock(reslist->listlock); +#endif - return reslist_maint(reslist); + return apr_reslist_maintain(reslist); } APU_DECLARE(void) apr_reslist_timeout_set(apr_reslist_t *reslist, @@ -387,9 +434,13 @@ APU_DECLARE(apr_uint32_t) apr_reslist_acquired_count(apr_reslist_t *reslist) { apr_uint32_t count; +#if APR_HAS_THREADS apr_thread_mutex_lock(reslist->listlock); +#endif count = reslist->ntotal - reslist->nidle; +#if APR_HAS_THREADS apr_thread_mutex_unlock(reslist->listlock); +#endif return count; } @@ -398,12 +449,25 @@ APU_DECLARE(apr_status_t) apr_reslist_invalidate(apr_reslist_t *reslist, void *resource) { apr_status_t ret; +#if APR_HAS_THREADS apr_thread_mutex_lock(reslist->listlock); +#endif ret = reslist->destructor(resource, reslist->params, reslist->pool); reslist->ntotal--; +#if APR_HAS_THREADS apr_thread_cond_signal(reslist->avail); apr_thread_mutex_unlock(reslist->listlock); +#endif return ret; } -#endif /* APR_HAS_THREADS */ +APU_DECLARE(void) apr_reslist_cleanup_order_set(apr_reslist_t *rl, + apr_uint32_t mode) +{ + apr_pool_cleanup_kill(rl->pool, rl, reslist_cleanup); + if (mode == APR_RESLIST_CLEANUP_FIRST) + apr_pool_pre_cleanup_register(rl->pool, rl, reslist_cleanup); + else + apr_pool_cleanup_register(rl->pool, rl, reslist_cleanup, + apr_pool_cleanup_null); +} diff --git a/srclib/apr-util/misc/apr_thread_pool.c b/srclib/apr-util/misc/apr_thread_pool.c index a53973f1..01c2e21d 100644 --- a/srclib/apr-util/misc/apr_thread_pool.c +++ b/srclib/apr-util/misc/apr_thread_pool.c @@ -237,7 +237,6 @@ static struct apr_thread_list_elt *elt_new(apr_thread_pool_t * me, */ static void *APR_THREAD_FUNC thread_pool_func(apr_thread_t * t, void *param) { - apr_status_t rv = APR_SUCCESS; apr_thread_pool_t *me = param; apr_thread_pool_task_t *task = NULL; apr_interval_time_t wait; @@ -313,10 +312,10 @@ static void *APR_THREAD_FUNC thread_pool_func(apr_thread_t * t, void *param) wait = -1; if (wait >= 0) { - rv = apr_thread_cond_timedwait(me->cond, me->lock, wait); + apr_thread_cond_timedwait(me->cond, me->lock, wait); } else { - rv = apr_thread_cond_wait(me->cond, me->lock); + apr_thread_cond_wait(me->cond, me->lock); } } @@ -353,13 +352,18 @@ APU_DECLARE(apr_status_t) apr_thread_pool_create(apr_thread_pool_t ** me, *me = NULL; tp = apr_pcalloc(pool, sizeof(apr_thread_pool_t)); - tp->pool = pool; - + /* + * This pool will be used by different threads. As we cannot ensure that + * our caller won't use the pool without acquiring the mutex, we must + * create a new sub pool. + */ + rv = apr_pool_create(&tp->pool, pool); + if (APR_SUCCESS != rv) + return rv; rv = thread_pool_construct(tp, init_threads, max_threads); - if (APR_SUCCESS != rv) { + if (APR_SUCCESS != rv) return rv; - } - apr_pool_cleanup_register(pool, tp, thread_pool_cleanup, + apr_pool_cleanup_register(tp->pool, tp, thread_pool_cleanup, apr_pool_cleanup_null); while (init_threads) { diff --git a/srclib/apr-util/misc/apu_dso.c b/srclib/apr-util/misc/apu_dso.c index 3ad72b56..639875dc 100644 --- a/srclib/apr-util/misc/apu_dso.c +++ b/srclib/apr-util/misc/apu_dso.c @@ -89,7 +89,7 @@ apr_status_t apu_dso_init(apr_pool_t *pool) /* Top level pool scope, need process-scope lifetime */ for (parent = global = pool; parent; parent = apr_pool_parent_get(global)) - global = parent; + global = parent; dsos = apr_hash_make(global); @@ -106,7 +106,8 @@ apr_status_t apu_dso_init(apr_pool_t *pool) return ret; } -apr_status_t apu_dso_load(apr_dso_handle_sym_t *dsoptr, +apr_status_t apu_dso_load(apr_dso_handle_t **dlhandleptr, + apr_dso_handle_sym_t *dsoptr, const char *module, const char *modsym, apr_pool_t *pool) @@ -161,6 +162,9 @@ apr_status_t apu_dso_load(apr_dso_handle_sym_t *dsoptr, apr_cpystrn(eos, module, sizeof(path) - (eos - path)); rv = apr_dso_load(&dlhandle, path, global); + if (dlhandleptr) { + *dlhandleptr = dlhandle; + } if (rv == APR_SUCCESS) { /* APR_EDSOOPEN */ break; } @@ -177,6 +181,9 @@ apr_status_t apu_dso_load(apr_dso_handle_sym_t *dsoptr, apr_cpystrn(eos, module, sizeof(path) - (eos - path)); rv = apr_dso_load(&dlhandle, path, global); + if (dlhandleptr) { + *dlhandleptr = dlhandle; + } if (rv == APR_SUCCESS) { /* APR_EDSOOPEN */ break; } |