httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@hyperreal.org
Subject cvs commit: apache-apr/pthreads/src/main http_main.c
Date Mon, 24 May 1999 03:07:03 GMT
manoj       99/05/23 20:07:03

  Modified:    pthreads/src/main http_main.c
  Log:
  Get rid of the last vestiges of SIGWINCH handling in child processes.
  Now, each worker thread knows when it's the last one to exit, and in
  that case, sends SIGTERM to kick the sigwait thread.
  
  Revision  Changes    Path
  1.82      +20 -26    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.81
  retrieving revision 1.82
  diff -u -u -r1.81 -r1.82
  --- http_main.c	1999/05/24 02:10:27	1.81
  +++ http_main.c	1999/05/24 03:07:02	1.82
  @@ -288,8 +288,10 @@
   static int my_pid; /* for hybridization, we need this.  Stupid to
   				 call getpid all the time */
   
  +/* Keep track of the number of worker threads currently active */
  +static int worker_thread_count;
  +static pthread_mutex_t worker_thread_count_mutex;
   
  -
   /*
    * Pieces for managing the contents of the Server response header
    * field.
  @@ -401,11 +403,6 @@
       exit(code);
   }
   
  -static void graceful_killer(void)
  -{
  -    stop_accepting_connections(pconf);
  -}
  -
   int ap_get_timeout(request_rec *r)
   {
   
  @@ -991,11 +988,6 @@
       }
   }
   
  -static void graceful_sig_handler(int sig)
  -{
  -    ap_max_requests_per_child = 1;
  -}
  -
   /*****************************************************************
    * Connection structures and accounting...
    */
  @@ -1730,7 +1722,6 @@
   #endif
   }
   
  -
   static void * worker_thread(void * dummy)
   {
       proc_info * ti = dummy;
  @@ -1745,6 +1736,10 @@
   
       ptrans = ap_make_sub_pool(tpool);
   
  +    pthread_mutex_lock(&worker_thread_count_mutex);
  +    worker_thread_count++;
  +    pthread_mutex_unlock(&worker_thread_count_mutex);
  +
       while (1) {
           (void) ap_update_child_status(process_slot, thread_slot, SERVER_READY, 
   				  (request_rec *) NULL);
  @@ -1757,9 +1752,17 @@
       }
   
       ap_destroy_pool(tpool);
  -    kill(ap_scoreboard_image->parent[process_slot].pid, SIGWINCH);
       ap_update_child_status(process_slot, thread_slot, SERVER_DEAD,
           (request_rec *) NULL);
  +    pthread_mutex_lock(&worker_thread_count_mutex);
  +    worker_thread_count--;
  +    if (worker_thread_count == 0) {
  +        /* All the threads have exited, now finish the shutdown process
  +         * by signalling the sigwait thread */
  +        kill(my_pid, SIGTERM);
  +    }
  +    pthread_mutex_unlock(&worker_thread_count_mutex);
  +
       return NULL;
   }
   
  @@ -1891,7 +1894,7 @@
       sigset_t sig_mask;
       int signal_received;
       pthread_t thread;
  -    int i, j;
  +    int i;
       int my_child_num = child_num_arg;
       proc_info *my_info = NULL;
   
  @@ -1923,6 +1926,9 @@
       }
   
       /* Setup worker threads */
  +
  +    worker_thread_count = 0;
  +    pthread_mutex_init(&worker_thread_count_mutex, NULL);
       for (i=0; i < ap_threads_per_child; i++) {
   
           my_info = NULL;
  @@ -1957,23 +1963,11 @@
   
       /* This thread will be the one responsible for handling signals */
       sigemptyset(&sig_mask);
  -    sigaddset(&sig_mask, SIGWINCH);
       sigaddset(&sig_mask, SIGTERM);
       sigaddset(&sig_mask, SIGINT);
       sigwait(&sig_mask, &signal_received);
       /* XXX - Do the appropriate thing for each signal */
       switch (signal_received) {
  -        case SIGWINCH:
  -  	    for (j = 0; j < ap_threads_per_child + ap_acceptors_per_child; 
  -		 j++) { 
  -                /* Useful for debugging */
  -                if (ap_scoreboard_image->servers[child_num_arg][j].status != SERVER_DEAD)
{
  -                    ap_scoreboard_image->servers[child_num_arg][j].status = SERVER_GRACEFUL;
  -                }
  -	    } 
  -            graceful_killer();
  -            clean_child_exit(0);
  -    	    break;
           case SIGTERM:
               just_die(SIGTERM);
       	    break;
  
  
  

Mime
View raw message