Attached ia a patch for the Worker MPM that uses APR Atomics to change the value of requests_this_child.

I changed it around to count *up*, instead of counting down... So I would like someone else to look at it before I commit it.

Thanks,

-Paul
Index: server/mpm/worker/worker.c
===================================================================
--- server/mpm/worker/worker.c  (revision 126227)
+++ server/mpm/worker/worker.c  (working copy)
@@ -29,6 +29,7 @@
 #include "apr_thread_mutex.h"
 #include "apr_proc_mutex.h"
 #include "apr_poll.h"
+#include "apr_atomic.h"
 #define APR_WANT_STRFUNC
 #include "apr_want.h"
 
@@ -127,7 +128,8 @@
 static int workers_may_exit = 0;
 static int start_thread_may_exit = 0;
 static int listener_may_exit = 0;
-static int requests_this_child;
+static apr_uint32_t max_requests_this_child;
+static apr_uint32_t requests_this_child;
 static int num_listensocks = 0;
 static int resource_shortage = 0;
 static fd_queue_t *worker_queue;
@@ -542,7 +544,7 @@
          * for the latter case, you probably deserve a beer too.   Greg Ames
          */
             
-        requests_this_child = INT_MAX;      /* keep going */ 
+        apr_atomic_set32(&requests_this_child, 0);    /* keep going */
     }
 }
 
@@ -606,8 +608,7 @@
     /* TODO: Switch to a system where threads reuse the results from earlier
        poll calls - manoj */
     while (1) {
-        /* TODO: requests_this_child should be synchronized - aaron */
-        if (requests_this_child <= 0) {
+        if (apr_atomic_read32(&requests_this_child) > max_requests_this_child) 
{
             check_infinite_requests();
         }
         if (listener_may_exit) break;
@@ -855,7 +856,8 @@
         bucket_alloc = apr_bucket_alloc_create(ptrans);
         process_socket(ptrans, csd, process_slot, thread_slot, bucket_alloc);
         worker_sockets[thread_slot] = NULL;
-        requests_this_child--; /* FIXME: should be synchronized - aaron */
+        rv = apr_atomic_inc32(&requests_this_child);
+        AP_DEBUG_ASSERT(rv == APR_SUCCESS);
         apr_pool_clear(ptrans);
         last_ptrans = ptrans;
     }
@@ -1137,12 +1139,19 @@
         clean_child_exit(APEXIT_CHILDFATAL);
     }
 
-    if (ap_max_requests_per_child) {
-        requests_this_child = ap_max_requests_per_child;
+    rv = apr_atomic_init(pchild);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
+                     "Couldn't initialize APR Atomics");
+        clean_child_exit(APEXIT_CHILDFATAL);
     }
+    
+    requests_this_child = 0;
+    if(ap_max_requests_per_child) {
+        max_requests_this_child = ap_max_requests_per_child;
+    }
     else {
-        /* coding a value of zero means infinity */
-        requests_this_child = INT_MAX;
+        max_requests_this_child = INT_MAX;
     }
     
     /* Setup worker threads */

Reply via email to