httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1482859 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c proxy_util.c
Date Wed, 15 May 2013 14:13:15 GMT
Author: minfrin
Date: Wed May 15 14:13:15 2013
New Revision: 1482859

URL: http://svn.apache.org/r1482859
Log:
mod_proxy: Use a global mutex for handling workers.

Modified:
    httpd/httpd/trunk/modules/proxy/mod_proxy.c
    httpd/httpd/trunk/modules/proxy/proxy_util.c

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.c?rev=1482859&r1=1482858&r2=1482859&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy.c Wed May 15 14:13:15 2013
@@ -36,6 +36,9 @@ APR_DECLARE_OPTIONAL_FN(char *, ssl_var_
 #define MAX(x,y) ((x) >= (y) ? (x) : (y))
 #endif
 
+static const char * const proxy_id = "proxy";
+apr_global_mutex_t *proxy_mutex = NULL;
+
 /*
  * A Web proxy module. Stages:
  *
@@ -1194,9 +1197,7 @@ static void * create_proxy_config(apr_po
     ps->source_address = NULL;
     ps->source_address_set = 0;
     apr_pool_create_ex(&ps->pool, p, NULL, NULL);
-    apr_global_mutex_create(&ps->mutex,
-                            "mod_proxy_config_mutex",
-                            APR_LOCK_DEFAULT, p);
+
     return ps;
 }
 
@@ -1258,7 +1259,6 @@ static void * merge_proxy_config(apr_poo
     ps->source_address = (overrides->source_address_set == 0) ? base->source_address
: overrides->source_address;
     ps->source_address_set = overrides->source_address_set || base->source_address_set;
     ps->pool = base->pool;
-    ps->mutex = base->mutex;
     return ps;
 }
 static const char *set_source_address(cmd_parms *parms, void *dummy,
@@ -2405,6 +2405,13 @@ PROXY_DECLARE(const char *) ap_proxy_ssl
 static int proxy_post_config(apr_pool_t *pconf, apr_pool_t *plog,
                              apr_pool_t *ptemp, server_rec *s)
 {
+    apr_status_t rv = ap_global_mutex_create(&proxy_mutex, NULL,
+            proxy_id, NULL, s, pconf, 0);
+    if (rv != APR_SUCCESS) {
+        ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, plog, APLOGNO()
+        "failed to create %s mutex", proxy_id);
+        return rv;
+    }
 
     proxy_ssl_enable = APR_RETRIEVE_OPTIONAL_FN(ssl_proxy_enable);
     proxy_ssl_disable = APR_RETRIEVE_OPTIONAL_FN(ssl_engine_disable);
@@ -2564,11 +2571,19 @@ static void child_init(apr_pool_t *p, se
 
 /*
  * This routine is called before the server processes the configuration
- * files.  There is no return value.
+ * files.
  */
 static int proxy_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
                             apr_pool_t *ptemp)
 {
+    apr_status_t rv = ap_mutex_register(pconf, proxy_id, NULL,
+            APR_LOCK_DEFAULT, 0);
+    if (rv != APR_SUCCESS) {
+        ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, plog, APLOGNO()
+                "failed to register %s mutex", proxy_id);
+        return 500; /* An HTTP status would be a misnomer! */
+    }
+
     APR_OPTIONAL_HOOK(ap, status_hook, proxy_status_hook, NULL, NULL,
                       APR_HOOK_MIDDLE);
     /* Reset workers count on gracefull restart */

Modified: httpd/httpd/trunk/modules/proxy/proxy_util.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/proxy_util.c?rev=1482859&r1=1482858&r2=1482859&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/proxy_util.c (original)
+++ httpd/httpd/trunk/modules/proxy/proxy_util.c Wed May 15 14:13:15 2013
@@ -76,6 +76,8 @@ static int lb_workers_limit = 0;
 const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_path;
 const apr_strmatch_pattern PROXY_DECLARE_DATA *ap_proxy_strmatch_domain;
 
+extern apr_global_mutex_t *proxy_mutex;
+
 static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
 static int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
 static int proxy_match_hostname(struct dirconn_entry *This, request_rec *r);
@@ -1681,7 +1683,6 @@ PROXY_DECLARE(apr_status_t) ap_proxy_ini
 {
     apr_status_t rv = APR_SUCCESS;
     int mpm_threads;
-    proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(s->module_config,
&proxy_module);
 
     if (worker->s->status & PROXY_WORKER_INITIALIZED) {
         /* The worker is already initialized */
@@ -1731,14 +1732,14 @@ PROXY_DECLARE(apr_status_t) ap_proxy_ini
     else {
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(00927)
                      "initializing worker %s local", worker->s->name);
-        apr_global_mutex_lock(conf->mutex);
+        apr_global_mutex_lock(proxy_mutex);
         /* Now init local worker data */
         if (worker->tmutex == NULL) {
             rv = apr_thread_mutex_create(&(worker->tmutex), APR_THREAD_MUTEX_DEFAULT,
p);
             if (rv != APR_SUCCESS) {
                 ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00928)
                              "can not create worker thread mutex");
-                apr_global_mutex_unlock(conf->mutex);
+                apr_global_mutex_unlock(proxy_mutex);
                 return rv;
             }
         }
@@ -1747,7 +1748,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_ini
         if (worker->cp == NULL) {
             ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00929)
                          "can not create connection pool");
-            apr_global_mutex_unlock(conf->mutex);
+            apr_global_mutex_unlock(proxy_mutex);
             return APR_EGENERAL;
         }
 
@@ -1783,7 +1784,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_ini
                  "initialized single connection worker in child %" APR_PID_T_FMT " for (%s)",
                  getpid(), worker->s->hostname);
         }
-        apr_global_mutex_unlock(conf->mutex);
+        apr_global_mutex_unlock(proxy_mutex);
 
     }
     if (rv == APR_SUCCESS) {



Mime
View raw message