summaryrefslogtreecommitdiff
path: root/util-misc
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2018-06-21 21:49:40 +0000
committerYann Ylavic <ylavic@apache.org>2018-06-21 21:49:40 +0000
commit2a935660953233f477351be519aefa269f434526 (patch)
treef30f590a3bac8c76f6cedc1f149dd877ef935436 /util-misc
parent39a80e2b33dbb97fb32ba5db57597a543b959f96 (diff)
downloadapr-2a935660953233f477351be519aefa269f434526.tar.gz
apr_reslist: don't release/re-acquire the mutex in apr_reslist_release().
We can hold the mutex for the whole release time by adding and using an unlocked reslist_maintain() helper, and ensure more fairness for the releaser. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1834061 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'util-misc')
-rw-r--r--util-misc/apr_reslist.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/util-misc/apr_reslist.c b/util-misc/apr_reslist.c
index dadc3529a..76e35c349 100644
--- a/util-misc/apr_reslist.c
+++ b/util-misc/apr_reslist.c
@@ -181,27 +181,19 @@ 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.
*/
-APR_DECLARE(apr_status_t) apr_reslist_maintain(apr_reslist_t *reslist)
+static apr_status_t 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);
- apr_pool_owner_set(reslist->pool, 0);
-#endif
-
/* Check if we need to create more resources, and if we are allowed to. */
while (reslist->nidle < reslist->min && reslist->ntotal < reslist->hmax) {
/* Create the resource */
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 */
@@ -212,7 +204,6 @@ APR_DECLARE(apr_status_t) apr_reslist_maintain(apr_reslist_t *reslist)
#if APR_HAS_THREADS
rv = apr_thread_cond_signal(reslist->avail);
if (rv != APR_SUCCESS) {
- apr_thread_mutex_unlock(reslist->listlock);
return rv;
}
#endif
@@ -223,9 +214,6 @@ APR_DECLARE(apr_status_t) apr_reslist_maintain(apr_reslist_t *reslist)
* nor need we check for expiry if no ttl is configure.
*/
if (created_one || !reslist->ttl) {
-#if APR_HAS_THREADS
- apr_thread_mutex_unlock(reslist->listlock);
-#endif
return APR_SUCCESS;
}
@@ -246,17 +234,26 @@ APR_DECLARE(apr_status_t) apr_reslist_maintain(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;
}
}
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_reslist_maintain(apr_reslist_t *reslist)
+{
+ apr_status_t rv;
+
+#if APR_HAS_THREADS
+ apr_thread_mutex_lock(reslist->listlock);
+ apr_pool_owner_set(reslist->pool, 0);
+#endif
+ rv = reslist_maintain(reslist);
#if APR_HAS_THREADS
apr_thread_mutex_unlock(reslist->listlock);
#endif
- return APR_SUCCESS;
+ return rv;
}
APR_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist,
@@ -313,7 +310,7 @@ APR_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist,
}
#endif
- rv = apr_reslist_maintain(rl);
+ rv = reslist_maintain(rl);
if (rv != APR_SUCCESS) {
/* Destroy what we've created so far.
*/
@@ -447,6 +444,7 @@ APR_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist,
APR_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist,
void *resource)
{
+ apr_status_t rv;
apr_res_t *res;
#if APR_HAS_THREADS
@@ -458,10 +456,12 @@ APR_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist,
push_resource(reslist, res);
#if APR_HAS_THREADS
apr_thread_cond_signal(reslist->avail);
+#endif
+ rv = reslist_maintain(reslist);
+#if APR_HAS_THREADS
apr_thread_mutex_unlock(reslist->listlock);
#endif
-
- return apr_reslist_maintain(reslist);
+ return rv;
}
APR_DECLARE(void) apr_reslist_timeout_set(apr_reslist_t *reslist,