You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by rp...@apache.org on 2008/05/26 17:44:41 UTC

svn commit: r660219 - in /apr/apr-util/branches/1.3.x: CHANGES misc/apr_reslist.c

Author: rpluem
Date: Mon May 26 08:44:40 2008
New Revision: 660219

URL: http://svn.apache.org/viewvc?rev=660219&view=rev
Log:
Merge r659802, r659961 from trunk:

Enforce ttl (where used) on individual resources in an apr_reslist

Correction to r659802: apr_reslist fix to enforce ttl on idle resources

PR: 42841
Submitted by: niq, tdonovan, rpluem
Reviewed by: rpluem

Modified:
    apr/apr-util/branches/1.3.x/CHANGES
    apr/apr-util/branches/1.3.x/misc/apr_reslist.c

Modified: apr/apr-util/branches/1.3.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.3.x/CHANGES?rev=660219&r1=660218&r2=660219&view=diff
==============================================================================
--- apr/apr-util/branches/1.3.x/CHANGES [utf-8] (original)
+++ apr/apr-util/branches/1.3.x/CHANGES [utf-8] Mon May 26 08:44:40 2008
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes with APR-util 1.3.0
 
+  *) Amend apr_reslist to expire resources whose idle time exceeds ttl.
+     PR 42841 [Tom Donovan, Nick Kew, Ruediger Pluem]
+
   *) Modularize ldap's stub with the dbd dso modular structure, and teach
      the apu dso's to respect the system specific shared lib path var.
      To link to an application without ldap libs, query 

Modified: apr/apr-util/branches/1.3.x/misc/apr_reslist.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.3.x/misc/apr_reslist.c?rev=660219&r1=660218&r2=660219&view=diff
==============================================================================
--- apr/apr-util/branches/1.3.x/misc/apr_reslist.c (original)
+++ apr/apr-util/branches/1.3.x/misc/apr_reslist.c Mon May 26 08:44:40 2008
@@ -292,13 +292,26 @@
 {
     apr_status_t rv;
     apr_res_t *res;
+    apr_time_t now;
 
     apr_thread_mutex_lock(reslist->listlock);
     /* If there are idle resources on the available list, use
      * them right away. */
-    if (reslist->nidle > 0) {
+    now = apr_time_now();
+    while (reslist->nidle > 0) {
         /* Pop off the first resource */
         res = pop_resource(reslist);
+        if (reslist->ttl && (now - res->freed >= reslist->ttl)) {
+            /* this res is expired - kill it */
+            reslist->ntotal--;
+            rv = destroy_resource(reslist, res);
+            free_container(reslist, res);
+            if (rv != APR_SUCCESS) {
+                apr_thread_mutex_unlock(reslist->listlock);
+                return rv;  /* FIXME: this might cause unnecessary fails */
+            }
+            continue;
+        }
         *resource = res->opaque;
         free_container(reslist, res);
         apr_thread_mutex_unlock(reslist->listlock);
@@ -306,8 +319,7 @@
     }
     /* If we've hit our max, block until we're allowed to create
      * a new one, or something becomes free. */
-    else while (reslist->ntotal >= reslist->hmax
-                && reslist->nidle <= 0) {
+    while (reslist->ntotal >= reslist->hmax && reslist->nidle <= 0) {
         if (reslist->timeout) {
             if ((rv = apr_thread_cond_timedwait(reslist->avail, 
                 reslist->listlock, reslist->timeout)) != APR_SUCCESS) {
@@ -315,8 +327,9 @@
                 return rv;
             }
         }
-        else
+        else {
             apr_thread_cond_wait(reslist->avail, reslist->listlock);
+        }
     }
     /* If we popped out of the loop, first try to see if there
      * are new resources available for immediate use. */