Return-Path: Delivered-To: apmail-apache-cvs-archive@apache.org Received: (qmail 16761 invoked by uid 500); 1 Dec 2000 21:31:51 -0000 Mailing-List: contact apache-cvs-help@apache.org; run by ezmlm Precedence: bulk Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list apache-cvs@apache.org Received: (qmail 16750 invoked by uid 500); 1 Dec 2000 21:31:50 -0000 Delivered-To: apmail-apache-2.0-cvs@apache.org Date: 1 Dec 2000 21:31:49 -0000 Message-ID: <20001201213149.16746.qmail@locus.apache.org> From: gregames@locus.apache.org To: apache-2.0-cvs@apache.org Subject: cvs commit: apache-2.0/src/modules/mpm/mpmt_pthread mpmt_pthread.c gregames 00/12/01 13:31:49 Modified: src/modules/mpm/dexter dexter.c src/modules/mpm/mpmt_pthread mpmt_pthread.c Log: Use APR_LOCKALL in dexter and mpmt_pthread to serialize poll and accept. This allows APR to optimize when a platform has locks that work for both threads and processes. Revision Changes Path 1.131 +8 -16 apache-2.0/src/modules/mpm/dexter/dexter.c Index: dexter.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/mpm/dexter/dexter.c,v retrieving revision 1.130 retrieving revision 1.131 diff -u -r1.130 -r1.131 --- dexter.c 2000/11/10 19:01:31 1.130 +++ dexter.c 2000/12/01 21:31:44 1.131 @@ -168,10 +168,9 @@ #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 @@ 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 @@ 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 @@ 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 @@ 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 @@ /*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 @@ 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"); 1.126 +8 -16 apache-2.0/src/modules/mpm/mpmt_pthread/mpmt_pthread.c Index: mpmt_pthread.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/mpm/mpmt_pthread/mpmt_pthread.c,v retrieving revision 1.125 retrieving revision 1.126 diff -u -r1.125 -r1.126 --- mpmt_pthread.c 2000/11/10 19:01:31 1.125 +++ mpmt_pthread.c 2000/12/01 21:31:47 1.126 @@ -158,8 +158,7 @@ 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 @@ /* 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 @@ 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 @@ /*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 @@ 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; }