]> granicus.if.org Git - apache/commitdiff
Use APR_LOCKALL in dexter and mpmt_pthread to serialize poll and accept. This
authorGreg Ames <gregames@apache.org>
Fri, 1 Dec 2000 21:31:47 +0000 (21:31 +0000)
committerGreg Ames <gregames@apache.org>
Fri, 1 Dec 2000 21:31:47 +0000 (21:31 +0000)
allows APR to optimize when a platform has locks that work for both threads and
processes.

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

server/mpm/dexter/dexter.c
server/mpm/mpmt_pthread/mpmt_pthread.c

index 535db9ce899f58a19e70b0f203d9b466f5d61bf0..cf11a0ab7032835481b95e9ebb61629fa01b0df7 100644 (file)
@@ -168,10 +168,9 @@ static pthread_mutex_t idle_thread_count_mutex;
 #define SAFE_ACCEPT(stmt) APR_SUCCESS
 #else
 #define SAFE_ACCEPT(stmt) (stmt)
-static apr_lock_t *process_accept_mutex;
+static apr_lock_t *accept_mutex;
 #endif /* NO_SERIALIZED_ACCEPT */
 static const char *lock_fname;
-static pthread_mutex_t thread_accept_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 AP_DECLARE(int) ap_get_max_daemons(void)
 {
@@ -516,7 +515,7 @@ static void *worker_thread(void *arg)
     for(n=0 ; n <= num_listenfds ; ++n)
         apr_add_poll_socket(pollset, listenfds[n], APR_POLLIN);
 
-    while (!workers_may_exit) {
+    while (1) {
         workers_may_exit |= (max_requests_per_child != 0) && (requests_this_child <= 0);
         if (workers_may_exit) break;
         if (!thread_just_started) {
@@ -533,12 +532,7 @@ static void *worker_thread(void *arg)
         else {
             thread_just_started = 0;
         }
-        pthread_mutex_lock(&thread_accept_mutex);
-        if (workers_may_exit) {
-            pthread_mutex_unlock(&thread_accept_mutex);
-            break;
-        }
-        if ((rv = SAFE_ACCEPT(apr_lock(process_accept_mutex)))
+        if ((rv = SAFE_ACCEPT(apr_lock(accept_mutex)))
             != APR_SUCCESS) {
             ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
                          "apr_lock failed. Attempting to shutdown "
@@ -599,14 +593,13 @@ static void *worker_thread(void *arg)
                 csd = NULL;
                 ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, "apr_accept");
             }
-            if ((rv = SAFE_ACCEPT(apr_unlock(process_accept_mutex)))
+            if ((rv = SAFE_ACCEPT(apr_unlock(accept_mutex)))
                 != APR_SUCCESS) {
                 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
                              "apr_unlock failed. Attempting to shutdown "
                              "process gracefully.");
                 workers_may_exit = 1;
             }
-            pthread_mutex_unlock(&thread_accept_mutex);
            pthread_mutex_lock(&idle_thread_count_mutex);
             if (idle_thread_count > min_spare_threads) {
                 idle_thread_count--;
@@ -622,14 +615,13 @@ static void *worker_thread(void *arg)
                 requests_this_child--;
             }
        } else {
-            if ((rv = SAFE_ACCEPT(apr_unlock(process_accept_mutex)))
+            if ((rv = SAFE_ACCEPT(apr_unlock(accept_mutex)))
                 != APR_SUCCESS) {
                 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
                              "apr_unlock failed. Attempting to shutdown "
                              "process gracefully.");
                 workers_may_exit = 1;
             }
-            pthread_mutex_unlock(&thread_accept_mutex);
            pthread_mutex_lock(&idle_thread_count_mutex);
             idle_thread_count--;
             pthread_mutex_unlock(&idle_thread_count_mutex);
@@ -668,7 +660,7 @@ static void child_main(int child_num_arg)
 
     /*stuff to do before we switch id's, so we have permissions.*/
 
-    rv = SAFE_ACCEPT(apr_child_init_lock(&process_accept_mutex, lock_fname,
+    rv = SAFE_ACCEPT(apr_child_init_lock(&accept_mutex, lock_fname,
                                         pchild));
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
@@ -1007,8 +999,8 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
     lock_fname = apr_psprintf(_pconf, "%s.%u",
                              ap_server_root_relative(_pconf, lock_fname),
                              my_pid);
-    rv = SAFE_ACCEPT(apr_create_lock(&process_accept_mutex, APR_MUTEX,
-                                    APR_CROSS_PROCESS, lock_fname, _pconf));
+    rv = SAFE_ACCEPT(apr_create_lock(&accept_mutex, APR_MUTEX,
+                                    APR_LOCKALL, lock_fname, _pconf));
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
                      "Couldn't create cross-process lock");
index 240307f499f34bb1eaf94fd34f065ca030264c47..1a37e9bd1d2fd7f7bfb0a7bec0401aa2bd8f4969 100644 (file)
@@ -158,8 +158,7 @@ static int worker_thread_count;
 static pthread_mutex_t worker_thread_count_mutex;
 
 /* Locks for accept serialization */
-static pthread_mutex_t thread_accept_mutex = PTHREAD_MUTEX_INITIALIZER;
-static apr_lock_t *process_accept_mutex;
+static apr_lock_t *accept_mutex;
 static const char *lock_fname;
 
 #ifdef NO_SERIALIZED_ACCEPT
@@ -470,18 +469,13 @@ static void * worker_thread(void * dummy)
 
     /* TODO: Switch to a system where threads reuse the results from earlier
        poll calls - manoj */
-    while (!workers_may_exit) {
+    while (1) {
         workers_may_exit |= (ap_max_requests_per_child != 0) && (requests_this_child <= 0);
         if (workers_may_exit) break;
 
         (void) ap_update_child_status(process_slot, thread_slot, SERVER_READY, 
                                       (request_rec *) NULL);
-        pthread_mutex_lock(&thread_accept_mutex);
-        if (workers_may_exit) {
-            pthread_mutex_unlock(&thread_accept_mutex);
-            break;
-        }
-        if ((rv = SAFE_ACCEPT(apr_lock(process_accept_mutex)))
+        if ((rv = SAFE_ACCEPT(apr_lock(accept_mutex)))
             != APR_SUCCESS) {
             ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
                          "apr_lock failed. Attempting to shutdown "
@@ -545,28 +539,26 @@ static void * worker_thread(void * dummy)
                 ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, 
                              "apr_accept");
             }
-            if ((rv = SAFE_ACCEPT(apr_unlock(process_accept_mutex)))
+            if ((rv = SAFE_ACCEPT(apr_unlock(accept_mutex)))
                 != APR_SUCCESS) {
                 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
                              "apr_unlock failed. Attempting to shutdown "
                              "process gracefully.");
                 workers_may_exit = 1;
             }
-            pthread_mutex_unlock(&thread_accept_mutex);
             if (csd != NULL) {
                 process_socket(ptrans, csd, process_slot, thread_slot);
                 requests_this_child--;
             }
         }
         else {
-            if ((rv = SAFE_ACCEPT(apr_unlock(process_accept_mutex)))
+            if ((rv = SAFE_ACCEPT(apr_unlock(accept_mutex)))
                 != APR_SUCCESS) {
                 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
                              "apr_unlock failed. Attempting to shutdown "
                              "process gracefully.");
                 workers_may_exit = 1;
             }
-            pthread_mutex_unlock(&thread_accept_mutex);
             break;
         }
         apr_clear_pool(ptrans);
@@ -607,7 +599,7 @@ static void child_main(int child_num_arg)
     /*stuff to do before we switch id's, so we have permissions.*/
     reopen_scoreboard(pchild);
 
-    rv = SAFE_ACCEPT(apr_child_init_lock(&process_accept_mutex, lock_fname,
+    rv = SAFE_ACCEPT(apr_child_init_lock(&accept_mutex, lock_fname,
                      pchild));
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
@@ -1029,11 +1021,11 @@ int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
     lock_fname = apr_psprintf(_pconf, "%s.%u",
                              ap_server_root_relative(_pconf, lock_fname),
                              ap_my_pid);
-    rv = apr_create_lock(&process_accept_mutex, APR_MUTEX, APR_CROSS_PROCESS,
+    rv = apr_create_lock(&accept_mutex, APR_MUTEX, APR_LOCKALL,
                    lock_fname, _pconf);
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
-                     "Couldn't create cross-process lock");
+                     "Couldn't create accept lock");
         return 1;
     }