manoj 99/11/15 13:22:50
Modified: src/modules/mpm/dexter Makefile.tmpl dexter.c Removed: src/modules/mpm/dexter acceptlock.c acceptlock.h Log: Eliminate acceptlock.{c,h} in dexter. They mostly duplicated code in APR. Revision Changes Path 1.7 +4 -27 apache-2.0/src/modules/mpm/dexter/Makefile.tmpl Index: Makefile.tmpl =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/mpm/dexter/Makefile.tmpl,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -u -r1.6 -r1.7 --- Makefile.tmpl 1999/10/30 05:59:27 1.6 +++ Makefile.tmpl 1999/11/15 21:22:42 1.7 @@ -2,9 +2,9 @@ LIB=libdexter.$(LIBEXT) OBJS=\ - dexter.o acceptlock.o scoreboard.o + dexter.o scoreboard.o OBJS_PIC=\ - dexter.lo acceptlock.lo scoreboard.lo + dexter.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 dexter.h $(OSDIR)/unixd.h dexter.o: dexter.c ../../../lib/apr/include/apr_portable.h \ ../../../lib/apr/include/apr_config.h \ ../../../lib/apr/include/apr_general.h \ @@ -99,8 +76,8 @@ $(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 acceptlock.h mpm_default.h dexter.h \ - scoreboard.h $(INCDIR)/mpm_status.h + $(INCDIR)/ap_listen.h mpm_default.h dexter.h scoreboard.h \ + $(INCDIR)/mpm_status.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.53 +52 -20 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.52 retrieving revision 1.53 diff -u -d -u -r1.52 -r1.53 --- dexter.c 1999/11/15 19:50:05 1.52 +++ dexter.c 1999/11/15 21:22:47 1.53 @@ -68,7 +68,6 @@ #include "unixd.h" #include "iol_socket.h" #include "ap_listen.h" -#include "acceptlock.h" #include "mpm_default.h" #include "dexter.h" #include "scoreboard.h" @@ -103,11 +102,7 @@ unsigned char status; } child_table[HARD_SERVER_LIMIT]; -#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 @@ -119,7 +114,6 @@ */ int max_daemons_limit = -1; - static char ap_coredump_dir[MAX_STRING_LEN]; static int pipe_of_death[2]; @@ -177,6 +171,11 @@ static int idle_thread_count; static pthread_mutex_t idle_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; + /* Global, alas, so http_core can talk to us */ enum server_token_type ap_server_tokens = SrvTk_FULL; @@ -851,6 +850,7 @@ int thread_just_started = 1; int thread_num = *((int *) arg); long conn_id = child_num * HARD_THREAD_LIMIT + thread_num; + ap_status_t rv; pthread_mutex_lock(&thread_pool_parent_mutex); ap_create_context(&tpool, thread_pool_parent); @@ -874,12 +874,18 @@ else { thread_just_started = 0; } - 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 = 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) { srv = poll(listenfds, num_listenfds + 1, -1); @@ -927,13 +933,16 @@ } got_fd: if (!workers_may_exit) { - ap_status_t rv; - if ((rv = ap_accept(&csd, sd, ptrans)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "ap_accept"); } - SAFE_ACCEPT(accept_mutex_off(0)); - SAFE_ACCEPT(intra_mutex_off(0)); + if ((rv = 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); pthread_mutex_lock(&idle_thread_count_mutex); if (idle_thread_count > min_spare_threads) { idle_thread_count--; @@ -947,8 +956,13 @@ process_socket(ptrans, csd, conn_id); requests_this_child--; } else { - SAFE_ACCEPT(accept_mutex_off(0)); - SAFE_ACCEPT(intra_mutex_off(0)); + if ((rv = 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); pthread_mutex_lock(&idle_thread_count_mutex); idle_thread_count--; pthread_mutex_unlock(&idle_thread_count_mutex); @@ -979,6 +993,7 @@ int signal_received; int i; ap_listen_rec *lr; + ap_status_t rv; my_pid = getpid(); child_num = child_num_arg; @@ -986,8 +1001,12 @@ /*stuff to do before we switch id's, so we have permissions.*/ - SAFE_ACCEPT(intra_mutex_init(pchild, 1)); - SAFE_ACCEPT(accept_mutex_child_init(pchild)); + rv = 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"); + ap_clean_child_exit(APEXIT_CHILDFATAL); + } if (unixd_setup_child()) { ap_clean_child_exit(APEXIT_CHILDFATAL); @@ -1285,6 +1304,7 @@ { int remaining_children_to_start; int i; + ap_status_t rv; pconf = _pconf; server_conf = s; @@ -1310,7 +1330,19 @@ 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); } @@ -1452,7 +1484,7 @@ max_spare_threads = DEFAULT_MAX_SPARE_THREAD; max_threads = HARD_THREAD_LIMIT; ap_pid_fname = DEFAULT_PIDLOG; - ap_lock_fname = DEFAULT_LOCKFILE; + lock_fname = DEFAULT_LOCKFILE; max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD; ap_dexter_set_maintain_connection_status(1); @@ -1487,7 +1519,7 @@ return err; } - ap_lock_fname = arg; + lock_fname = arg; return NULL; } static const char *set_num_daemons (cmd_parms *cmd, void *dummy, char *arg)