rbb 99/02/16 10:31:58
Modified: pthreads/src/main http_main.c Log: Code to properly finish a child process. This makes sure the child process calls the proper module functions, and sets the scoreboard to SERVER_DEAD for all threads. Submitted by: Manoj Kasichainula and Ryan Bloom Revision Changes Path 1.32 +32 -25 apache-apr/pthreads/src/main/http_main.c Index: http_main.c =================================================================== RCS file: /home/cvs/apache-apr/pthreads/src/main/http_main.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- http_main.c 1999/02/16 16:00:48 1.31 +++ http_main.c 1999/02/16 18:31:53 1.32 @@ -380,23 +380,6 @@ } } -void graceful_killer(void) -{ - listen_rec *lr; - int i; - - for (i = 0; i < ap_threads_per_child; i++) { - pthread_cond_signal(&(csd_queue.not_empty)); - } - /* Setup acceptor threads */ - - lr = ap_listeners; - while (lr->next != NULL) { - ap_pclosesocket(pconf, lr->fd); - lr= lr->next; - } -} - /* a clean exit from the parent with proper cleanup */ static void clean_parent_exit(int code) __attribute__((noreturn)); static void clean_parent_exit(int code) @@ -413,6 +396,7 @@ int child_num = find_child_by_pid(getpid()); int i; listen_rec *lr; + parent_score *ss = &ap_scoreboard_image->parent[child_num]; for (i = 0; i < ap_threads_per_child + ap_acceptors_per_child; i++) ap_update_child_status(child_num, i, SERVER_DEAD, (request_rec *) NULL); @@ -422,9 +406,40 @@ ap_destroy_pool(pchild); } + for (i = 0; i < ss->worker_threads + ss->acceptor_threads; i++) { + if (ap_scoreboard_image->servers[child_num][i].status != SERVER_DEAD) { + pthread_cancel(ap_scoreboard_image->servers[child_num][i].tid); + } + } + exit(code); } +void graceful_killer(void) +{ + listen_rec *lr; + int i; + int index = find_child_by_pid(getpid()); + parent_score *ss = &ap_scoreboard_image->parent[index]; + + for (i = 0; i < ap_threads_per_child; i++) { + pthread_cond_signal(&(csd_queue.not_empty)); + } + /* Setup acceptor threads */ + + lr = ap_listeners; + while (lr->next != NULL) { + ap_pclosesocket(pconf, lr->fd); + lr= lr->next; + } + + for (i = 0; i < ss->worker_threads + ss->acceptor_threads; i++) { + if (ap_scoreboard_image->servers[index][i].status != SERVER_DEAD) { + pthread_join(ap_scoreboard_image->servers[index][i].tid, NULL); + } + } + clean_child_exit(0); +} /****** ZZZ this should probably be abstracted to it's own file. ****/ @@ -2451,15 +2466,12 @@ proc_info *my_info = NULL; sigset_t sig_mask; int ret; - pthread_attr_t thread_attr; my_pid = getpid(); requests_this_child = ap_max_requests_per_child; pchild = ap_make_sub_pool(pconf); - pthread_detach(pthread_self()); - /*stuff to do before we switch id's, so we have permissions.*/ reopen_scoreboard(pchild); SAFE_ACCEPT(accept_mutex_child_init(pchild)); @@ -2477,11 +2489,6 @@ /*done with init critical section */ queue_init(&csd_queue, ap_threads_per_child, pchild); - - pthread_attr_init(&thread_attr); - - /* We don't want to have to pthread_wait on these threads */ - pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); /* Setup worker threads */ for (i=0; i < ap_threads_per_child; i++) {