summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2018-04-04 17:43:46 +0000
committerYann Ylavic <ylavic@apache.org>2018-04-04 17:43:46 +0000
commit8276a99ce92d603d62c233059495b8d08f3c2c0f (patch)
tree4c48ccd2b4f27dc0b19f55eb2e9655dd7a2c37e9
parent6994e19acf72004cf17de9aede8aba6c728e9f6c (diff)
downloadapr-8276a99ce92d603d62c233059495b8d08f3c2c0f.tar.gz
reslist: follow up to r1828289: adjust maintenance top too.
Also, clarify in doxygen when apr_reslist_fifo_set() should be called. [Reverted by r1829102] git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1828369 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--include/apr_reslist.h6
-rw-r--r--util-misc/apr_reslist.c9
2 files changed, 13 insertions, 2 deletions
diff --git a/include/apr_reslist.h b/include/apr_reslist.h
index 291cc5593..d1947944a 100644
--- a/include/apr_reslist.h
+++ b/include/apr_reslist.h
@@ -134,11 +134,17 @@ APR_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist,
*/
APR_DECLARE(void) apr_reslist_timeout_set(apr_reslist_t *reslist,
apr_interval_time_t timeout);
+
/**
* Set whether the reslist reuses resources as FIFO (First In First Out) or
* LIFO (Last In First Out).
* @param reslist The resource list.
* @param fifo Set as FIFO (non zero) or LIFO (zero).
+ * @remark This function should be called before any resource is in the
+ * the reslist, otherwise maintenance optimizations based on the expiration
+ * time relative to the order of insertion (i.e. position in the list) won't
+ * work as expected.
+ *
*/
APR_DECLARE(void) apr_reslist_fifo_set(apr_reslist_t *reslist, int fifo);
diff --git a/util-misc/apr_reslist.c b/util-misc/apr_reslist.c
index 48c4d36ce..ddc9eb5ea 100644
--- a/util-misc/apr_reslist.c
+++ b/util-misc/apr_reslist.c
@@ -229,8 +229,13 @@ APR_DECLARE(apr_status_t) apr_reslist_maintain(apr_reslist_t *reslist)
/* Check if we need to expire old resources */
now = apr_time_now();
while (reslist->nidle > reslist->smax && reslist->nidle > 0) {
- /* Peak at the last resource in the list */
- res = APR_RING_LAST(&reslist->avail_list);
+ /* Peek at the next expiring resource in the list */
+ if (reslist->fifo) {
+ res = APR_RING_FIRST(&reslist->avail_list);
+ }
+ else {
+ res = APR_RING_LAST(&reslist->avail_list);
+ }
/* See if the oldest entry should be expired */
if (now - res->freed < reslist->ttl) {
/* If this entry is too young, none of the others