> From: Jeff Trawick
> 
> Cliff Woolley wrote:
> > 
> > Is it really correct to return APR_EAGAIN regardless of the return 
> > value of apr_thread_cond_timedwait()?  Or is that a bug caused by a 
> > lack of {}'s?  This is why we tend to say that you should 
> always use 
> > {}'s, even if the conditional block is only one line long.
>

That was the bug.

> if not returning whatever apr_thread_cond_timedwait() 
> returned, why not return APR_TIMEUP instead of APR_EAGAIN?  
> but like Cliff said I wonder why the retval of 
> apr_thread_cond_timewait() isn't appropriate?
> 

The fixed patch uses the returning value from apr_thread_cond_timedwait().
Also changed to apr_reslist_timeout_set.

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   9 Dec 2003 15:31:26 -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_timeout_set(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   9 Dec 2003 15:33:31 -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,7 +344,15 @@
      * a new one, or something becomes free. */
     else while (reslist->ntotal >= reslist->hmax
                 && reslist->nidle <= 0) {
-        apr_thread_cond_wait(reslist->avail, reslist->listlock);
+        if (reslist->timeout) {
+            if ((rv = apr_thread_cond_timedwait(reslist->avail, 
+                reslist->listlock, reslist->timeout)) != APR_SUCCESS) {
+                apr_thread_mutex_unlock(reslist->listlock);
+                return rv;
+            }
+        }
+        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. */
@@ -382,6 +391,12 @@
     apr_thread_mutex_unlock(reslist->listlock);
 
     return reslist_maint(reslist);
+}
+
+APU_DECLARE(void) apr_reslist_timeout_set(apr_reslist_t *reslist,
+                                          apr_interval_time_t timeout)
+{
+    reslist->timeout = timeout;
 }
 
 #endif  /* APR_HAS_THREADS */

Reply via email to