Return-Path: Delivered-To: apache-cvs-archive@hyperreal.org Received: (qmail 16212 invoked by uid 6000); 15 Nov 1999 23:30:16 -0000 Received: (qmail 16104 invoked by uid 2016); 15 Nov 1999 23:30:10 -0000 Delivered-To: apcore-apache-2.0-cvs@apache.org Received: (qmail 15952 invoked by uid 216); 15 Nov 1999 23:30:06 -0000 Date: 15 Nov 1999 23:30:06 -0000 Message-ID: <19991115233006.15951.qmail@hyperreal.org> From: manoj@hyperreal.org To: apache-2.0-cvs@apache.org Subject: cvs commit: apache-2.0/src/modules/mpm/mpmt_pthread Makefile.tmpl mpmt_pthread.c acceptlock.c acceptlock.h Sender: apache-cvs-owner@apache.org Precedence: bulk Reply-To: new-httpd@apache.org Status: O manoj 99/11/15 15:30:03 Modified: src/modules/mpm/mpmt_pthread Makefile.tmpl mpmt_pthread.c Removed: src/modules/mpm/mpmt_pthread acceptlock.c acceptlock.h Log: Eliminate acceptlock.c from mpmt_pthread. Use an APR type for the cross-process lock instead. Revision Changes Path 1.11 +3 -26 apache-2.0/src/modules/mpm/mpmt_pthread/Makefile.tmpl Index: Makefile.tmpl =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/mpm/mpmt_pthread/Makefile.tmpl,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -u -r1.10 -r1.11 --- Makefile.tmpl 1999/10/30 05:59:28 1.10 +++ Makefile.tmpl 1999/11/15 23:28:47 1.11 @@ -2,9 +2,9 @@ LIB=libmpmt_pthread.$(LIBEXT) OBJS=\ - mpmt_pthread.o acceptlock.o scoreboard.o + mpmt_pthread.o scoreboard.o OBJS_PIC=\ - mpmt_pthread.lo acceptlock.lo scoreboard.lo + mpmt_pthread.lo scoreboard.lo all: lib @@ -55,29 +55,6 @@ $(OBJS) $(OBJS_PIC): Makefile # DO NOT REMOVE -acceptlock.o: acceptlock.c $(INCDIR)/httpd.h \ - $(INCDIR)/ap_config.h $(INCDIR)/ap_mmn.h \ - $(INCDIR)/ap_config_auto.h $(OSDIR)/os.h \ - $(OSDIR)/os-inline.c $(INCDIR)/ap_ctype.h \ - $(INCDIR)/hsregex.h ../../../lib/apr/include/apr_general.h \ - ../../../lib/apr/include/apr_config.h \ - ../../../lib/apr/include/apr_errno.h \ - ../../../lib/apr/include/apr_lib.h \ - ../../../lib/apr/include/apr_file_io.h $(INCDIR)/buff.h \ - $(INCDIR)/ap_iol.h $(INCDIR)/ap.h \ - $(INCDIR)/apr.h $(INCDIR)/util_uri.h \ - $(INCDIR)/http_main.h $(INCDIR)/http_log.h \ - $(INCDIR)/http_config.h $(INCDIR)/ap_hooks.h \ - $(INCDIR)/http_protocol.h \ - ../../../lib/apr/include/apr_portable.h \ - ../../../lib/apr/include/apr_thread_proc.h \ - ../../../lib/apr/include/apr_win.h \ - ../../../lib/apr/include/apr_network_io.h \ - ../../../lib/apr/include/apr_lock.h \ - ../../../lib/apr/include/apr_time.h $(INCDIR)/http_request.h \ - $(INCDIR)/http_conf_globals.h $(INCDIR)/http_core.h \ - $(INCDIR)/http_vhost.h $(INCDIR)/util_script.h \ - acceptlock.h mpmt_pthread.h $(OSDIR)/unixd.h mpmt_pthread.o: mpmt_pthread.c ../../../lib/apr/include/apr_portable.h \ ../../../lib/apr/include/apr_config.h \ ../../../lib/apr/include/apr_general.h \ @@ -99,7 +76,7 @@ $(INCDIR)/ap_hooks.h $(INCDIR)/http_core.h \ $(INCDIR)/http_connection.h $(INCDIR)/ap_mpm.h \ $(OSDIR)/unixd.h $(OSDIR)/iol_socket.h \ - $(INCDIR)/ap_listen.h scoreboard.h mpm_default.h acceptlock.h + $(INCDIR)/ap_listen.h scoreboard.h mpm_default.h scoreboard.o: scoreboard.c $(INCDIR)/httpd.h \ $(INCDIR)/ap_config.h $(INCDIR)/ap_mmn.h \ $(INCDIR)/ap_config_auto.h $(OSDIR)/os.h \ 1.45 +65 -19 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.44 retrieving revision 1.45 diff -u -d -u -r1.44 -r1.45 --- mpmt_pthread.c 1999/11/15 19:50:11 1.44 +++ mpmt_pthread.c 1999/11/15 23:29:47 1.45 @@ -69,7 +69,6 @@ #include "iol_socket.h" #include "ap_listen.h" #include "scoreboard.h" -#include "acceptlock.h" #include #include @@ -101,12 +100,6 @@ ap_context_t *tpool; /* "pthread" would be confusing */ } proc_info; -#if 0 -#define SAFE_ACCEPT(stmt) do {if (ap_listeners->next != NULL) {stmt;}} while (0) -#else -#define SAFE_ACCEPT(stmt) do {stmt;} while (0) -#endif - /* * The max child slot ever assigned, preserved across restarts. Necessary * to deal with MaxClients changes across SIGWINCH restarts. We use this @@ -162,6 +155,18 @@ 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 ap_lock_t *process_accept_mutex; +static char *lock_fname; + +#ifdef NO_SERIALIZED_ACCEPT +#define SAFE_ACCEPT(stmt) APR_SUCCESS +#else +#define SAFE_ACCEPT(stmt) (stmt) +#endif + + /* Global, alas, so http_core can talk to us */ enum server_token_type ap_server_tokens = SrvTk_FULL; @@ -798,6 +803,7 @@ int n; int curr_pollfd, last_pollfd = 0; ap_pollfd_t *pollset; + ap_status_t rv; free(ti); @@ -819,12 +825,19 @@ (void) ap_update_child_status(process_slot, thread_slot, SERVER_READY, (request_rec *) NULL); - SAFE_ACCEPT(intra_mutex_on(0)); + pthread_mutex_lock(&thread_accept_mutex); if (workers_may_exit) { - SAFE_ACCEPT(intra_mutex_off(0)); + pthread_mutex_unlock(&thread_accept_mutex); break; } - SAFE_ACCEPT(accept_mutex_on(0)); + if ((rv = SAFE_ACCEPT(ap_lock(process_accept_mutex))) + != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, server_conf, + "ap_lock failed. Attempting to shutdown " + "process gracefully."); + workers_may_exit = 1; + } + while (!workers_may_exit) { ap_status_t ret; ap_int16_t event; @@ -877,14 +890,26 @@ got_fd: if (!workers_may_exit) { ap_accept(&csd, sd, ptrans); - SAFE_ACCEPT(accept_mutex_off(0)); - SAFE_ACCEPT(intra_mutex_off(0)); + if ((rv = SAFE_ACCEPT(ap_unlock(process_accept_mutex))) + != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, server_conf, + "ap_unlock failed. Attempting to shutdown " + "process gracefully."); + workers_may_exit = 1; + } + pthread_mutex_unlock(&thread_accept_mutex); process_socket(ptrans, csd, process_slot, thread_slot); requests_this_child--; } else { - SAFE_ACCEPT(accept_mutex_off(0)); - SAFE_ACCEPT(intra_mutex_off(0)); + if ((rv = SAFE_ACCEPT(ap_unlock(process_accept_mutex))) + != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, server_conf, + "ap_unlock failed. Attempting to shutdown " + "process gracefully."); + workers_may_exit = 1; + } + pthread_mutex_unlock(&thread_accept_mutex); break; } ap_clear_pool(ptrans); @@ -916,6 +941,8 @@ int my_child_num = child_num_arg; proc_info *my_info = NULL; ap_listen_rec *lr; + ap_status_t rv; + my_pid = getpid(); ap_create_context(&pchild, pconf); @@ -923,8 +950,13 @@ /*stuff to do before we switch id's, so we have permissions.*/ reopen_scoreboard(pchild); - SAFE_ACCEPT(intra_mutex_init(pchild, 1)); - SAFE_ACCEPT(accept_mutex_child_init(pchild)); + rv = SAFE_ACCEPT(ap_child_init_lock(&process_accept_mutex, lock_fname, + pchild)); + if (rv != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, server_conf, + "Couldn't initialize cross-process lock in child"); + clean_child_exit(APEXIT_CHILDFATAL); + } if (unixd_setup_child()) { clean_child_exit(APEXIT_CHILDFATAL); @@ -1287,6 +1319,7 @@ int ap_mpm_run(ap_context_t *_pconf, ap_context_t *plog, server_rec *s) { int remaining_children_to_start; + ap_status_t rv; pconf = _pconf; server_conf = s; @@ -1317,7 +1350,20 @@ return 1; } ap_log_pid(pconf, ap_pid_fname); - SAFE_ACCEPT(accept_mutex_init(pconf, 1)); + + /* Initialize cross-process accept lock */ + lock_fname = ap_psprintf(_pconf, "%s.%lu", + ap_server_root_relative(_pconf, lock_fname), + my_pid); + rv = ap_create_lock(&process_accept_mutex, APR_MUTEX, APR_CROSS_PROCESS, + lock_fname, _pconf); + if (rv != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, + "Couldn't create cross-process lock"); + return 1; + } + + if (!is_graceful) { reinit_scoreboard(pconf); } @@ -1472,7 +1518,7 @@ ap_threads_per_child = DEFAULT_THREADS_PER_CHILD; ap_pid_fname = DEFAULT_PIDLOG; ap_scoreboard_fname = DEFAULT_SCOREBOARD; - ap_lock_fname = DEFAULT_LOCKFILE; + lock_fname = DEFAULT_LOCKFILE; ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD; ap_extended_status = 0; @@ -1519,7 +1565,7 @@ return err; } - ap_lock_fname = arg; + lock_fname = arg; return NULL; }