]> granicus.if.org Git - apache/commitdiff
mpm_event(opt), mpm_worker: follow up to r1635521.
authorYann Ylavic <ylavic@apache.org>
Mon, 17 Nov 2014 13:59:36 +0000 (13:59 +0000)
committerYann Ylavic <ylavic@apache.org>
Mon, 17 Nov 2014 13:59:36 +0000 (13:59 +0000)
Allocate retained idle_spawn_rate vector on the process pool.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1640161 13f79535-47bb-0310-9956-ffa450edef68

server/mpm/event/event.c
server/mpm/eventopt/eventopt.c
server/mpm/worker/worker.c

index 6d5bdbf56630bfb748a3194918a89109a034f2f1..a5e312491b7db070d741b311a25414370c323580 100644 (file)
@@ -353,7 +353,8 @@ typedef struct event_retained_data {
      * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
      * without the need to spawn.
      */
-    int *idle_spawn_rate;
+    int *idle_spawn_rate,
+         idle_spawn_rate_len;
 #ifndef MAX_SPAWN_RATE
 #define MAX_SPAWN_RATE        (32)
 #endif
@@ -3223,6 +3224,22 @@ static int event_open_logs(apr_pool_t * p, apr_pool_t * plog,
         all_buckets[i].listeners = listen_buckets[i];
     }
 
+    if (retained->idle_spawn_rate_len < num_buckets) {
+        int *new_ptr, new_len;
+        new_len = retained->idle_spawn_rate_len * 2;
+        if (new_len < num_buckets) {
+            new_len = num_buckets;
+        }
+        new_ptr = (int *)apr_palloc(ap_pglobal, new_len * sizeof(int));
+        memcpy(new_ptr, retained->idle_spawn_rate,
+               retained->idle_spawn_rate_len * sizeof(int));
+        for (i = retained->idle_spawn_rate_len; i < new_len; i++) {
+            new_ptr[i] = 1;
+        }
+        retained->idle_spawn_rate_len = new_len;
+        retained->idle_spawn_rate = new_ptr;
+    }
+
     /* for skiplist */
     srand((unsigned int)apr_time_now());
     return OK;
@@ -3234,7 +3251,6 @@ static int event_pre_config(apr_pool_t * pconf, apr_pool_t * plog,
     int no_detach, debug, foreground;
     apr_status_t rv;
     const char *userdata_key = "mpm_event_module";
-    int i;
 
     mpm_state = AP_MPMQ_STARTING;
 
@@ -3268,10 +3284,7 @@ static int event_pre_config(apr_pool_t * pconf, apr_pool_t * plog,
                          "atomics not working as expected - add32 of negative number");
             return HTTP_INTERNAL_SERVER_ERROR;
         }
-        retained->idle_spawn_rate = apr_palloc(pconf, sizeof(int) * num_buckets);
-        for (i = 0; i< num_buckets; i++) {
-            retained->idle_spawn_rate[i] = 1;
-        }
+
         rv = apr_pollset_create(&event_pollset, 1, plog,
                                 APR_POLLSET_THREADSAFE | APR_POLLSET_NOCOPY);
         if (rv != APR_SUCCESS) {
index 56239a563dabcb38747414aaec20398dc52808cb..dd002ac831e3274711221229f9d979f03670fa01 100644 (file)
@@ -338,7 +338,8 @@ typedef struct event_retained_data {
      * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
      * without the need to spawn.
      */
-    int *idle_spawn_rate;
+    int *idle_spawn_rate,
+         idle_spawn_rate_len;
 #ifndef MAX_SPAWN_RATE
 #define MAX_SPAWN_RATE        (32)
 #endif
@@ -3042,6 +3043,22 @@ static int event_open_logs(apr_pool_t * p, apr_pool_t * plog,
         all_buckets[i].listeners = listen_buckets[i];
     }
 
+    if (retained->idle_spawn_rate_len < num_buckets) {
+        int *new_ptr, new_len;
+        new_len = retained->idle_spawn_rate_len * 2;
+        if (new_len < num_buckets) {
+            new_len = num_buckets;
+        }
+        new_ptr = (int *)apr_palloc(ap_pglobal, new_len * sizeof(int));
+        memcpy(new_ptr, retained->idle_spawn_rate,
+               retained->idle_spawn_rate_len * sizeof(int));
+        for (i = retained->idle_spawn_rate_len; i < new_len; i++) {
+            new_ptr[i] = 1;
+        }
+        retained->idle_spawn_rate_len = new_len;
+        retained->idle_spawn_rate = new_ptr;
+    }
+
     /* for skiplist */
     srand((unsigned int)apr_time_now());
     return OK;
@@ -3053,7 +3070,6 @@ static int event_pre_config(apr_pool_t * pconf, apr_pool_t * plog,
     int no_detach, debug, foreground;
     apr_status_t rv;
     const char *userdata_key = "mpm_eventopt_module";
-    int i;
 
     mpm_state = AP_MPMQ_STARTING;
 
@@ -3087,10 +3103,7 @@ static int event_pre_config(apr_pool_t * pconf, apr_pool_t * plog,
                          "atomics not working as expected - add32 of negative number");
             return HTTP_INTERNAL_SERVER_ERROR;
         }
-        retained->idle_spawn_rate = apr_palloc(pconf, sizeof(int) * num_buckets);
-        for (i = 0; i< num_buckets; i++) {
-            retained->idle_spawn_rate[i] = 1;
-        }
+
         rv = apr_pollset_create(&event_pollset, 1, plog,
                                 APR_POLLSET_WAKEABLE|APR_POLLSET_NOCOPY);
         if (rv != APR_SUCCESS) {
index 890c825b31113cb36ada2c5c8720258fbe22de69..0351c066d2330ce3b90b72160500c9d86ab0b732 100644 (file)
@@ -163,7 +163,8 @@ typedef struct worker_retained_data {
      * doubled up to MAX_SPAWN_RATE, and reset only when a cycle goes by
      * without the need to spawn.
      */
-    int *idle_spawn_rate;
+    int *idle_spawn_rate,
+         idle_spawn_rate_len;
 #ifndef MAX_SPAWN_RATE
 #define MAX_SPAWN_RATE        (32)
 #endif
@@ -2057,6 +2058,22 @@ static int worker_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
         all_buckets[i].listeners = listen_buckets[i];
     }
 
+    if (retained->idle_spawn_rate_len < num_buckets) {
+        int *new_ptr, new_len;
+        new_len = retained->idle_spawn_rate_len * 2;
+        if (new_len < num_buckets) {
+            new_len = num_buckets;
+        }
+        new_ptr = (int *)apr_palloc(ap_pglobal, new_len * sizeof(int));
+        memcpy(new_ptr, retained->idle_spawn_rate,
+               retained->idle_spawn_rate_len * sizeof(int));
+        for (i = retained->idle_spawn_rate_len; i < new_len; i++) {
+            new_ptr[i] = 1;
+        }
+        retained->idle_spawn_rate_len = new_len;
+        retained->idle_spawn_rate = new_ptr;
+    }
+
     return OK;
 }
 
@@ -2066,7 +2083,6 @@ static int worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
     int no_detach, debug, foreground;
     apr_status_t rv;
     const char *userdata_key = "mpm_worker_module";
-    int i;
 
     mpm_state = AP_MPMQ_STARTING;
 
@@ -2103,10 +2119,6 @@ static int worker_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
                 return HTTP_INTERNAL_SERVER_ERROR;
             }
         }
-        retained->idle_spawn_rate = apr_palloc(pconf, sizeof(int) * num_buckets);
-        for (i = 0; i< num_buckets; i++) {
-            retained->idle_spawn_rate[i] = 1;
-        }
     }
 
     parent_pid = ap_my_pid = getpid();