manoj 99/07/21 15:18:32
Modified: mpm/src/modules/mpm/dexter dexter.c
Log:
Cleanups and fixes. Get rid of more stuff having to do with scoreboard
slots in the children. Also squashes a couple of bugs.
Revision Changes Path
1.3 +22 -40 apache-2.0/mpm/src/modules/mpm/dexter/dexter.c
Index: dexter.c
===================================================================
RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -u -r1.2 -r1.3
--- dexter.c 1999/07/21 20:44:41 1.2
+++ dexter.c 1999/07/21 22:18:30 1.3
@@ -89,14 +89,6 @@
static int num_listenfds = 0;
static struct pollfd *listenfds;
-/* The structure used to pass unique initialization info to each thread */
-typedef struct {
- int pid;
- int tid;
- int sd;
- pool *tpool; /* "pthread" would be confusing */
-} proc_info;
-
#if 0
#define SAFE_ACCEPT(stmt) do {if (ap_listeners->next != NULL) {stmt;}} while
(0)
#else
@@ -795,7 +787,7 @@
* Child process main loop.
*/
-static void process_socket(pool *p, struct sockaddr *sa_client, int csd, int
my_child_num, int my_thread_num)
+static void process_socket(pool *p, struct sockaddr *sa_client, int csd)
{
struct sockaddr sa_server; /* ZZZZ */
size_t len = sizeof(struct sockaddr);
@@ -833,17 +825,14 @@
current_conn = ap_new_connection(p, server_conf, conn_io,
(const struct sockaddr_in *) sa_client,
(const struct sockaddr_in *) &sa_server,
- my_child_num, my_thread_num);
+ 0, 0);
ap_process_connection(current_conn);
}
-static void * worker_thread(void * dummy)
+static void * worker_thread(void *thread_pool)
{
- proc_info * ti = dummy;
- int process_slot = ti->pid;
- int thread_slot = ti->tid;
- pool *tpool = ti->tpool;
+ pool *tpool = thread_pool;
struct sockaddr sa_client;
int csd = -1;
pool *ptrans; /* Pool for per-transaction stuff */
@@ -854,8 +843,6 @@
int curr_pollfd, last_pollfd = 0;
size_t len = sizeof(struct sockaddr);
- free(ti);
-
ptrans = ap_make_sub_pool(tpool);
pthread_mutex_lock(&worker_thread_count_mutex);
@@ -935,11 +922,17 @@
}
}
got_fd:
- SAFE_ACCEPT(accept_mutex_off(0));
- SAFE_ACCEPT(intra_mutex_off(0));
- if (workers_may_exit) break;
- csd = ap_accept(sd, &sa_client, &len);
- process_socket(ptrans, &sa_client, csd, process_slot, thread_slot);
+ if (!workers_may_exit) {
+ csd = ap_accept(sd, &sa_client, &len);
+ SAFE_ACCEPT(accept_mutex_off(0));
+ SAFE_ACCEPT(intra_mutex_off(0));
+ } else {
+ SAFE_ACCEPT(accept_mutex_off(0));
+ SAFE_ACCEPT(intra_mutex_off(0));
+ break;
+ }
+
+ process_socket(ptrans, &sa_client, csd);
ap_clear_pool(ptrans);
requests_this_child--;
}
@@ -957,15 +950,14 @@
return NULL;
}
-static void child_main(int child_num_arg)
+static void child_main(void)
{
sigset_t sig_mask;
int signal_received;
pthread_t thread;
pthread_attr_t thread_attr;
int i;
- int my_child_num = child_num_arg;
- proc_info *my_info = NULL;
+ pool *tpool;
ap_listen_rec *lr;
my_pid = getpid();
@@ -1012,20 +1004,10 @@
pthread_attr_init(&thread_attr);
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
for (i=0; i < ap_threads_per_child; i++) {
-
- my_info = (proc_info *)malloc(sizeof(proc_info));
- if (my_info == NULL) {
- ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf,
- "malloc: out of memory");
- clean_child_exit(APEXIT_CHILDFATAL);
- }
- my_info->pid = my_child_num;
- my_info->tid = i;
- my_info->sd = 0;
- my_info->tpool = ap_make_sub_pool(pchild);
+ tpool = ap_make_sub_pool(pchild);
/* We are creating threads right now */
- if (pthread_create(&thread, &thread_attr, worker_thread, my_info)) {
+ if (pthread_create(&thread, &thread_attr, worker_thread, tpool)) {
ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf,
"pthread_create: unable to create worker thread");
/* In case system resources are maxxed out, we don't want
@@ -1072,7 +1054,7 @@
if (one_process) {
set_signals();
ap_scoreboard_image[slot].pid = getpid();
- child_main(slot);
+ child_main();
}
if ((pid = fork()) == -1) {
@@ -1103,7 +1085,7 @@
/* XXX - For an unthreaded server, a signal handler will be necessary
signal(SIGTERM, just_die);
*/
- child_main(slot);
+ child_main();
return 0;
}
@@ -1118,7 +1100,7 @@
int i;
for (i = 0; number_to_start && i < ap_num_daemons; ++i) {
- if (ap_scoreboard_image[i].pid != 0) {
+ if (ap_scoreboard_image[i].status != SERVER_DEAD) {
continue;
}
if (make_child(server_conf, i, 0) < 0) {