Hi,

Can someone review this patch and eventually respond if there are
any chances to get this patch committed to apr-util.
If not we'll make something different then.

Thanks,
MT.

> -----Original Message-----
> From: Mladen Turk
> Sent: 3. prosinac 2003 20:09
> To: dev@apr.apache.org
> Subject: [PATCH] add timeout to apr_reslist
> 
> 
> Hi,
> 
> The patch adds the timeout to apr_reslist.
> We would like to use that kind of a behavior for a JK2 
> connector's dynamic connection pool.
> The current implementation waits forever for the resource to 
> become available, but we need to return the 503 when the 
> maximum number of resources is reached.
> 
> The patch doesn't break any existing functionality or API, 
> just adds the extra function to set the timeout value.
> If the timeout value is nonzero the apr_thread_cond_timedwait 
> is used instead of apr_thread_cond_wait.
> 
> MT.
> 
Index: apr_reslist.h
===================================================================
RCS file: /home/cvspublic/apr-util/include/apr_reslist.h,v
retrieving revision 1.5
diff -u -r1.5 apr_reslist.h
--- apr_reslist.h       1 Jan 2003 00:02:20 -0000       1.5
+++ apr_reslist.h       3 Dec 2003 18:57:21 -0000
@@ -150,6 +150,15 @@
 APU_DECLARE(apr_status_t) apr_reslist_release(apr_reslist_t *reslist,
                                               void *resource);
 
+/**
+ * Set the timeout the acquire will wait for a free resource
+ * when the maximum number of resources is exceeded.
+ * @param reslist The resource list.
+ * @param timeout Timeout to wait. The zero waits forewer.
+ */
+APU_DECLARE(void) apr_reslist_set_timeout(apr_reslist_t *reslist,
+                                          apr_interval_time_t timeout);
+
 #ifdef __cplusplus
 }
 #endif

Index: apr_reslist.c
===================================================================
RCS file: /home/cvspublic/apr-util/misc/apr_reslist.c,v
retrieving revision 1.6
diff -u -r1.6 apr_reslist.c
--- apr_reslist.c       6 Oct 2003 20:34:30 -0000       1.6
+++ apr_reslist.c       3 Dec 2003 19:06:11 -0000
@@ -88,6 +88,7 @@
     int smax; /* soft maximum on the total number of resources */
     int hmax; /* hard maximum on the total number of resources */
     apr_interval_time_t ttl; /* TTL when we have too many resources */
+    apr_interval_time_t timeout; /* Timeout for waiting on resource */
     apr_reslist_constructor constructor;
     apr_reslist_destructor destructor;
     void *params; /* opaque data passed to constructor and destructor calls */
@@ -343,6 +344,13 @@
      * a new one, or something becomes free. */
     else while (reslist->ntotal >= reslist->hmax
                 && reslist->nidle <= 0) {
+        if (reslist->timeout) {
+            if (apr_thread_cond_timedwait(reslist->avail, 
+                reslist->listlock, reslist->timeout) != APR_SUCCESS)
+                apr_thread_mutex_unlock(reslist->listlock);
+                return APR_EAGAIN;
+        }
+        else
         apr_thread_cond_wait(reslist->avail, reslist->listlock);
     }
     /* If we popped out of the loop, first try to see if there
@@ -382,6 +390,12 @@
     apr_thread_mutex_unlock(reslist->listlock);
 
     return reslist_maint(reslist);
+}
+
+APU_DECLARE(void) apr_reslist_set_timeout(apr_reslist_t *reslist,
+                                          apr_interval_time_t timeout)
+{
+    reslist->timeout = timeout;
 }
 
 #endif  /* APR_HAS_THREADS */

Reply via email to