diff options
author | Stefan Fritsch <sf@apache.org> | 2013-03-23 16:12:52 +0000 |
---|---|---|
committer | Stefan Fritsch <sf@apache.org> | 2013-03-23 16:12:52 +0000 |
commit | 829e2a12c2258cfaebb26ef311ed2d41ab5a553a (patch) | |
tree | 220f885a41cbfadc4209330e9de78869a00c85cf /util-misc | |
parent | 5c100ea811811cc92bd8fbcaedcbcf58e3c7599c (diff) | |
download | apr-829e2a12c2258cfaebb26ef311ed2d41ab5a553a.tar.gz |
thread_pool/reslist: take ownership of the pool when we lock the mutex
(except in cases where there is no chance that the pool is used)
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1460183 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'util-misc')
-rw-r--r-- | util-misc/apr_reslist.c | 6 | ||||
-rw-r--r-- | util-misc/apr_thread_pool.c | 8 |
2 files changed, 14 insertions, 0 deletions
diff --git a/util-misc/apr_reslist.c b/util-misc/apr_reslist.c index f44484935..ecc17a7d4 100644 --- a/util-misc/apr_reslist.c +++ b/util-misc/apr_reslist.c @@ -143,6 +143,7 @@ static apr_status_t reslist_cleanup(void *data_) #if APR_HAS_THREADS apr_thread_mutex_lock(rl->listlock); + apr_pool_owner_set(rl->pool, 0); #endif while (rl->nidle > 0) { @@ -182,6 +183,7 @@ APR_DECLARE(apr_status_t) apr_reslist_maintain(apr_reslist_t *reslist) #if APR_HAS_THREADS apr_thread_mutex_lock(reslist->listlock); + apr_pool_owner_set(reslist->pool, 0); #endif /* Check if we need to create more resources, and if we are allowed to. */ @@ -332,6 +334,7 @@ APR_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist, #if APR_HAS_THREADS apr_thread_mutex_lock(reslist->listlock); + apr_pool_owner_set(reslist->pool, 0); #endif /* If there are idle resources on the available list, use * them right away. */ @@ -412,6 +415,7 @@ APR_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist, #if APR_HAS_THREADS apr_thread_mutex_lock(reslist->listlock); + apr_pool_owner_set(reslist->pool, 0); #endif res = get_container(reslist); res->opaque = resource; @@ -436,6 +440,7 @@ APR_DECLARE(apr_uint32_t) apr_reslist_acquired_count(apr_reslist_t *reslist) #if APR_HAS_THREADS apr_thread_mutex_lock(reslist->listlock); + apr_pool_owner_set(reslist->pool, 0); #endif count = reslist->ntotal - reslist->nidle; #if APR_HAS_THREADS @@ -451,6 +456,7 @@ APR_DECLARE(apr_status_t) apr_reslist_invalidate(apr_reslist_t *reslist, apr_status_t ret; #if APR_HAS_THREADS apr_thread_mutex_lock(reslist->listlock); + apr_pool_owner_set(reslist->pool, 0); #endif ret = reslist->destructor(resource, reslist->params, reslist->pool); reslist->ntotal--; diff --git a/util-misc/apr_thread_pool.c b/util-misc/apr_thread_pool.c index e8a245b26..4c19482fb 100644 --- a/util-misc/apr_thread_pool.c +++ b/util-misc/apr_thread_pool.c @@ -243,6 +243,7 @@ static void *APR_THREAD_FUNC thread_pool_func(apr_thread_t * t, void *param) struct apr_thread_list_elt *elt; apr_thread_mutex_lock(me->lock); + apr_pool_owner_set(me->pool, 0); elt = elt_new(me, t); if (!elt) { apr_thread_mutex_unlock(me->lock); @@ -265,6 +266,7 @@ static void *APR_THREAD_FUNC thread_pool_func(apr_thread_t * t, void *param) apr_thread_data_set(task, "apr_thread_pool_task", NULL, t); task->func(t, task->param); apr_thread_mutex_lock(me->lock); + apr_pool_owner_set(me->pool, 0); APR_RING_INSERT_TAIL(me->recycled_tasks, task, apr_thread_pool_task, link); elt->current_owner = NULL; @@ -335,6 +337,7 @@ static apr_status_t thread_pool_cleanup(void *me) while (_myself->thd_cnt) { apr_sleep(20 * 1000); /* spin lock with 20 ms */ } + apr_pool_owner_set(_myself->pool, 0); apr_thread_mutex_destroy(_myself->lock); apr_thread_cond_destroy(_myself->cond); return APR_SUCCESS; @@ -372,6 +375,7 @@ APR_DECLARE(apr_status_t) apr_thread_pool_create(apr_thread_pool_t ** me, * initial threads to create. */ apr_thread_mutex_lock(tp->lock); + apr_pool_owner_set(tp->pool, 0); rv = apr_thread_create(&t, NULL, thread_pool_func, tp, tp->pool); apr_thread_mutex_unlock(tp->lock); if (APR_SUCCESS != rv) { @@ -485,6 +489,7 @@ static apr_status_t schedule_task(apr_thread_pool_t *me, apr_thread_t *thd; apr_status_t rv = APR_SUCCESS; apr_thread_mutex_lock(me->lock); + apr_pool_owner_set(me->pool, 0); t = task_new(me, func, param, 0, owner, time); if (NULL == t) { @@ -535,6 +540,7 @@ static apr_status_t add_task(apr_thread_pool_t *me, apr_thread_start_t func, apr_status_t rv = APR_SUCCESS; apr_thread_mutex_lock(me->lock); + apr_pool_owner_set(me->pool, 0); t = task_new(me, func, param, priority, owner, 0); if (NULL == t) { @@ -696,6 +702,7 @@ APR_DECLARE(apr_status_t) apr_thread_pool_tasks_cancel(apr_thread_pool_t *me, apr_status_t rv = APR_SUCCESS; apr_thread_mutex_lock(me->lock); + apr_pool_owner_set(me->pool, 0); if (me->task_cnt > 0) { rv = remove_tasks(me, owner); } @@ -783,6 +790,7 @@ static struct apr_thread_list_elt *trim_threads(apr_thread_pool_t *me, struct apr_thread_list_elt *head, *tail, *elt; apr_thread_mutex_lock(me->lock); + apr_pool_owner_set(me->pool, 0); if (idle) { thds = me->idle_thds; n = me->idle_cnt; |