apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r680514 - in /apr/apr-util/trunk: CHANGES include/apr_reslist.h misc/apr_reslist.c
Date Mon, 28 Jul 2008 21:39:22 GMT
Author: bojan
Date: Mon Jul 28 14:39:20 2008
New Revision: 680514

URL: http://svn.apache.org/viewvc?rev=680514&view=rev
Log:
Implement resource list when threads are unavailable.

Modified:
    apr/apr-util/trunk/CHANGES
    apr/apr-util/trunk/include/apr_reslist.h
    apr/apr-util/trunk/misc/apr_reslist.c

Modified: apr/apr-util/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/CHANGES?rev=680514&r1=680513&r2=680514&view=diff
==============================================================================
--- apr/apr-util/trunk/CHANGES [utf-8] (original)
+++ apr/apr-util/trunk/CHANGES [utf-8] Mon Jul 28 14:39:20 2008
@@ -26,6 +26,9 @@
   *) Give MySQL DBD driver reconnect option. PR 45407
      [Bojan Smojver]
 
+  *) Implement resource list when threads are unavailable.
+     [Bojan Smojver]
+
 Changes with APR-util 1.3.0
 
   *) apr_reslist: destroy all resources in apr_cleanup.

Modified: apr/apr-util/trunk/include/apr_reslist.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/include/apr_reslist.h?rev=680514&r1=680513&r2=680514&view=diff
==============================================================================
--- apr/apr-util/trunk/include/apr_reslist.h (original)
+++ apr/apr-util/trunk/include/apr_reslist.h Mon Jul 28 14:39:20 2008
@@ -28,8 +28,6 @@
 #include "apr_errno.h"
 #include "apr_time.h"
 
-#if APR_HAS_THREADS
-
 /**
  * @defgroup APR_Util_RL Resource List Routines
  * @ingroup APR_Util
@@ -78,6 +76,9 @@
  * @param pool The pool from which to create this resoure list. Also the
  *             same pool that is passed to the constructor and destructor
  *             routines.
+ * @remark If APR has been compiled without thread support, hmax will be
+ *         automatically set to 1 and values of min and smax will be forced to
+ *         1 for any non-zero value.
  */
 APU_DECLARE(apr_status_t) apr_reslist_create(apr_reslist_t **reslist,
                                              int min, int smax, int hmax,
@@ -144,6 +145,4 @@
 
 /** @} */
 
-#endif  /* APR_HAS_THREADS */
-
 #endif  /* ! APR_RESLIST_H */

Modified: apr/apr-util/trunk/misc/apr_reslist.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/misc/apr_reslist.c?rev=680514&r1=680513&r2=680514&view=diff
==============================================================================
--- apr/apr-util/trunk/misc/apr_reslist.c (original)
+++ apr/apr-util/trunk/misc/apr_reslist.c Mon Jul 28 14:39:20 2008
@@ -24,8 +24,6 @@
 #include "apr_thread_cond.h"
 #include "apr_ring.h"
 
-#if APR_HAS_THREADS
-
 /**
  * A single resource element.
  */
@@ -56,8 +54,10 @@
     void *params; /* opaque data passed to constructor and destructor calls */
     apr_resring_t avail_list;
     apr_resring_t free_list;
+#if APR_HAS_THREADS
     apr_thread_mutex_t *listlock;
     apr_thread_cond_t *avail;
+#endif
 };
 
 /**
@@ -141,7 +141,9 @@
     apr_reslist_t *rl = data_;
     apr_res_t *res;
 
+#if APR_HAS_THREADS
     apr_thread_mutex_lock(rl->listlock);
+#endif
 
     while (rl->nidle > 0) {
         apr_status_t rv1;
@@ -158,9 +160,11 @@
     assert(rl->nidle == 0);
     assert(rl->ntotal == 0);
 
+#if APR_HAS_THREADS
     apr_thread_mutex_unlock(rl->listlock);
     apr_thread_mutex_destroy(rl->listlock);
     apr_thread_cond_destroy(rl->avail);
+#endif
 
     return rv;
 }
@@ -176,7 +180,9 @@
     apr_res_t *res;
     int created_one = 0;
 
+#if APR_HAS_THREADS
     apr_thread_mutex_lock(reslist->listlock);
+#endif
 
     /* Check if we need to create more resources, and if we are allowed to. */
     while (reslist->nidle < reslist->min && reslist->ntotal < reslist->hmax)
{
@@ -184,7 +190,9 @@
         rv = create_resource(reslist, &res);
         if (rv != APR_SUCCESS) {
             free_container(reslist, res);
+#if APR_HAS_THREADS
             apr_thread_mutex_unlock(reslist->listlock);
+#endif
             return rv;
         }
         /* Add it to the list */
@@ -192,17 +200,21 @@
         /* Update our counters */
         reslist->ntotal++;
         /* If someone is waiting on that guy, wake them up. */
+#if APR_HAS_THREADS
         rv = apr_thread_cond_signal(reslist->avail);
         if (rv != APR_SUCCESS) {
             apr_thread_mutex_unlock(reslist->listlock);
             return rv;
         }
+#endif
         created_one++;
     }
 
     /* We don't need to see if we're over the max if we were under it before */
     if (created_one) {
+#if APR_HAS_THREADS
         apr_thread_mutex_unlock(reslist->listlock);
+#endif
         return APR_SUCCESS;
     }
 
@@ -223,12 +235,16 @@
         rv = destroy_resource(reslist, res);
         free_container(reslist, res);
         if (rv != APR_SUCCESS) {
+#if APR_HAS_THREADS
             apr_thread_mutex_unlock(reslist->listlock);
+#endif
             return rv;
         }
     }
 
+#if APR_HAS_THREADS
     apr_thread_mutex_unlock(reslist->listlock);
+#endif
     return APR_SUCCESS;
 }
 
@@ -250,6 +266,17 @@
         return APR_EINVAL;
     }
 
+#if !APR_HAS_THREADS
+    /* There can be only one resource when we have no threads. */
+    if (min > 0) {
+        min = 1;
+    }
+    if (smax > 0) {
+        smax = 1;
+    }
+    hmax = 1;
+#endif
+
     rl = apr_pcalloc(pool, sizeof(*rl));
     rl->pool = pool;
     rl->min = min;
@@ -263,6 +290,7 @@
     APR_RING_INIT(&rl->avail_list, apr_res_t, link);
     APR_RING_INIT(&rl->free_list, apr_res_t, link);
 
+#if APR_HAS_THREADS
     rv = apr_thread_mutex_create(&rl->listlock, APR_THREAD_MUTEX_DEFAULT,
                                  pool);
     if (rv != APR_SUCCESS) {
@@ -272,6 +300,7 @@
     if (rv != APR_SUCCESS) {
         return rv;
     }
+#endif
 
     rv = reslist_maint(rl);
     if (rv != APR_SUCCESS) {
@@ -304,7 +333,9 @@
     apr_res_t *res;
     apr_time_t now;
 
+#if APR_HAS_THREADS
     apr_thread_mutex_lock(reslist->listlock);
+#endif
     /* If there are idle resources on the available list, use
      * them right away. */
     now = apr_time_now();
@@ -317,19 +348,24 @@
             rv = destroy_resource(reslist, res);
             free_container(reslist, res);
             if (rv != APR_SUCCESS) {
+#if APR_HAS_THREADS
                 apr_thread_mutex_unlock(reslist->listlock);
+#endif
                 return rv;  /* FIXME: this might cause unnecessary fails */
             }
             continue;
         }
         *resource = res->opaque;
         free_container(reslist, res);
+#if APR_HAS_THREADS
         apr_thread_mutex_unlock(reslist->listlock);
+#endif
         return APR_SUCCESS;
     }
     /* If we've hit our max, block until we're allowed to create
      * a new one, or something becomes free. */
     while (reslist->ntotal >= reslist->hmax && reslist->nidle <= 0)
{
+#if APR_HAS_THREADS
         if (reslist->timeout) {
             if ((rv = apr_thread_cond_timedwait(reslist->avail, 
                 reslist->listlock, reslist->timeout)) != APR_SUCCESS) {
@@ -340,6 +376,9 @@
         else {
             apr_thread_cond_wait(reslist->avail, reslist->listlock);
         }
+#else
+        return APR_EAGAIN;
+#endif
     }
     /* If we popped out of the loop, first try to see if there
      * are new resources available for immediate use. */
@@ -347,7 +386,9 @@
         res = pop_resource(reslist);
         *resource = res->opaque;
         free_container(reslist, res);
+#if APR_HAS_THREADS
         apr_thread_mutex_unlock(reslist->listlock);
+#endif
         return APR_SUCCESS;
     }
     /* Otherwise the reason we dropped out of the loop
@@ -360,7 +401,9 @@
             *resource = res->opaque;
         }
         free_container(reslist, res);
+#if APR_HAS_THREADS
         apr_thread_mutex_unlock(reslist->listlock);
+#endif
         return rv;
     }
 }
@@ -370,12 +413,16 @@
 {
     apr_res_t *res;
 
+#if APR_HAS_THREADS
     apr_thread_mutex_lock(reslist->listlock);
+#endif
     res = get_container(reslist);
     res->opaque = resource;
     push_resource(reslist, res);
+#if APR_HAS_THREADS
     apr_thread_cond_signal(reslist->avail);
     apr_thread_mutex_unlock(reslist->listlock);
+#endif
 
     return reslist_maint(reslist);
 }
@@ -390,9 +437,13 @@
 {
     apr_uint32_t count;
 
+#if APR_HAS_THREADS
     apr_thread_mutex_lock(reslist->listlock);
+#endif
     count = reslist->ntotal - reslist->nidle;
+#if APR_HAS_THREADS
     apr_thread_mutex_unlock(reslist->listlock);
+#endif
 
     return count;
 }
@@ -401,12 +452,14 @@
                                                  void *resource)
 {
     apr_status_t ret;
+#if APR_HAS_THREADS
     apr_thread_mutex_lock(reslist->listlock);
+#endif
     ret = reslist->destructor(resource, reslist->params, reslist->pool);
     reslist->ntotal--;
+#if APR_HAS_THREADS
     apr_thread_cond_signal(reslist->avail);
     apr_thread_mutex_unlock(reslist->listlock);
+#endif
     return ret;
 }
-
-#endif  /* APR_HAS_THREADS */



Mime
View raw message