summaryrefslogtreecommitdiff
path: root/util-misc
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2018-06-21 17:37:31 +0000
committerYann Ylavic <ylavic@apache.org>2018-06-21 17:37:31 +0000
commit3b184bb1f97b973487e13e95e8ab54fdb02e3e24 (patch)
treede1738f654826bfc84a4f84c8779fe02ae98add6 /util-misc
parent22d813ce8f45111bd9bf2aee56295ccbba186d96 (diff)
downloadapr-3b184bb1f97b973487e13e95e8ab54fdb02e3e24.tar.gz
apr_reslist: add apr_reslist_acquire_ex().
Allows to control acquire order, either LIFO (default and current behaviour) or FIFO. Associated test upcoming... git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1834034 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'util-misc')
-rw-r--r--util-misc/apr_reslist.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/util-misc/apr_reslist.c b/util-misc/apr_reslist.c
index 7b6ff3507..dadc3529a 100644
--- a/util-misc/apr_reslist.c
+++ b/util-misc/apr_reslist.c
@@ -61,13 +61,18 @@ struct apr_reslist_t {
};
/**
- * Grab a resource from the front of the resource list.
+ * Grab a resource from the resource list, latest or oldest depending on fifo.
* Assumes: that the reslist is locked.
*/
-static apr_res_t *pop_resource(apr_reslist_t *reslist)
+static apr_res_t *pop_resource(apr_reslist_t *reslist, int fifo)
{
apr_res_t *res;
- res = APR_RING_FIRST(&reslist->avail_list);
+ if (fifo) {
+ res = APR_RING_LAST(&reslist->avail_list);
+ }
+ else {
+ res = APR_RING_FIRST(&reslist->avail_list);
+ }
APR_RING_REMOVE(res, link);
reslist->nidle--;
return res;
@@ -150,7 +155,7 @@ static apr_status_t reslist_cleanup(void *data_)
while (rl->nidle > 0) {
apr_status_t rv1;
- res = pop_resource(rl);
+ res = pop_resource(rl, 0);
rl->ntotal--;
rv1 = destroy_resource(rl, res);
if (rv1 != APR_SUCCESS) {
@@ -329,11 +334,17 @@ APR_DECLARE(apr_status_t) apr_reslist_destroy(apr_reslist_t *reslist)
return apr_pool_cleanup_run(reslist->pool, reslist, reslist_cleanup);
}
-APR_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist,
- void **resource)
+static apr_status_t reslist_acquire(apr_reslist_t *reslist,
+ void **resource, int flags)
{
apr_status_t rv;
apr_res_t *res;
+ int fifo;
+
+ if (flags & ~APR_RESLIST_ACQUIRE_MASK) {
+ return APR_EINVAL;
+ }
+ fifo = flags & APR_RESLIST_ACQUIRE_FIFO;
#if APR_HAS_THREADS
apr_thread_mutex_lock(reslist->listlock);
@@ -367,7 +378,7 @@ APR_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist,
}
/* If there is still an idle resource, use it right away */
if (reslist->nidle > 0) {
- res = pop_resource(reslist);
+ res = pop_resource(reslist, fifo);
*resource = res->opaque;
free_container(reslist, res);
#if APR_HAS_THREADS
@@ -396,7 +407,7 @@ APR_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist,
/* If we popped out of the loop, first try to see if there
* are new resources available for immediate use. */
if (reslist->nidle > 0) {
- res = pop_resource(reslist);
+ res = pop_resource(reslist, fifo);
*resource = res->opaque;
free_container(reslist, res);
#if APR_HAS_THREADS
@@ -421,6 +432,18 @@ APR_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist,
}
}
+APR_DECLARE(apr_status_t) apr_reslist_acquire_ex(apr_reslist_t *reslist,
+ void **resource, int flags)
+{
+ return reslist_acquire(reslist, resource, flags);
+}
+
+APR_DECLARE(apr_status_t) apr_reslist_acquire(apr_reslist_t *reslist,
+ void **resource)
+{
+ return reslist_acquire(reslist, resource, 0);
+}
+
APR_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist,
void *resource)
{