manoj       99/08/11 16:55:44

  Modified:    mpm/src/modules/mpm/dexter dexter.c
               mpm/src/modules/mpm/mpmt_pthread mpmt_pthread.c
  Log:
  Move a little code around to shorten the worker_thread function a bit.
  
  Revision  Changes    Path
  1.20      +23 -20    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.19
  retrieving revision 1.20
  diff -u -d -u -r1.19 -r1.20
  --- dexter.c  1999/08/10 21:18:37     1.19
  +++ dexter.c  1999/08/11 23:55:38     1.20
  @@ -930,6 +930,27 @@
       return 1;
   
   }
  +/* Sets workers_may_exit if we received a character on the pipe_of_death */
  +static void check_pipe_of_death(void)
  +{
  +    pthread_mutex_lock(&pipe_of_death_mutex);
  +    if (!workers_may_exit) {
  +        int ret;
  +        char pipe_read_char;
  +
  +        ret = read(listenfds[0].fd, &pipe_read_char, 1);
  +        if (ret == -1 && errno == EAGAIN) {
  +            /* It lost the lottery. It must continue to suffer
  +             * through a life of servitude. */
  +        }
  +        else {
  +            /* It won the lottery (or something else is very
  +             * wrong). Embrace death with open arms. */
  +            workers_may_exit = 1;
  +        }
  +    }
  +    pthread_mutex_unlock(&pipe_of_death_mutex);
  +}
   
   /* idle_thread_count should be incremented before starting a worker_thread */
   
  @@ -941,8 +962,6 @@
       pool *ptrans;            /* Pool for per-transaction stuff */
       int sd = -1;
       int srv;
  -    int ret;
  -    char pipe_read_char;
       int curr_pollfd, last_pollfd = 0;
       size_t len = sizeof(struct sockaddr);
       worker_thread_info *thread_info = arg;
  @@ -997,24 +1016,8 @@
               if (listenfds[0].revents & POLLIN) {
                   /* A process got a signal on the shutdown pipe. Check if 
we're
                    * the lucky process to die. */
  -                pthread_mutex_lock(&pipe_of_death_mutex);
  -                if (!workers_may_exit) {
  -                    ret = read(listenfds[0].fd, &pipe_read_char, 1);
  -                    if (ret == -1 && errno == EAGAIN) {
  -                        /* It lost the lottery. It must continue to suffer
  -                         * through a life of servitude. */
  -                        pthread_mutex_unlock(&pipe_of_death_mutex);
  -                        continue;
  -                    }
  -                    else {
  -                        /* It won the lottery (or something else is very
  -                         * wrong). Embrace death with open arms. */
  -                        workers_may_exit = 1;
  -                        pthread_mutex_unlock(&pipe_of_death_mutex);
  -                        break;
  -                    }
  -                }
  -                pthread_mutex_unlock(&pipe_of_death_mutex);
  +                check_pipe_of_death();
  +                continue;
               }
   
               if (num_listenfds == 1) {
  
  
  
  1.25      +23 -20    
apache-2.0/mpm/src/modules/mpm/mpmt_pthread/mpmt_pthread.c
  
  Index: mpmt_pthread.c
  ===================================================================
  RCS file: 
/home/cvs/apache-2.0/mpm/src/modules/mpm/mpmt_pthread/mpmt_pthread.c,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -d -u -r1.24 -r1.25
  --- mpmt_pthread.c    1999/08/10 21:18:43     1.24
  +++ mpmt_pthread.c    1999/08/11 23:55:42     1.25
  @@ -900,6 +900,27 @@
   
       ap_process_connection(current_conn);
   }
  +/* Sets workers_may_exit if we received a character on the pipe_of_death */
  +static void check_pipe_of_death(void)
  +{
  +    pthread_mutex_lock(&pipe_of_death_mutex);
  +    if (!workers_may_exit) {
  +        int ret;
  +        char pipe_read_char;
  +
  +        ret = read(listenfds[0].fd, &pipe_read_char, 1);
  +        if (ret == -1 && errno == EAGAIN) {
  +            /* It lost the lottery. It must continue to suffer
  +             * through a life of servitude. */
  +        }
  +        else {
  +            /* It won the lottery (or something else is very
  +             * wrong). Embrace death with open arms. */
  +            workers_may_exit = 1;
  +        }
  +    }
  +    pthread_mutex_unlock(&pipe_of_death_mutex);
  +}
   
   static void * worker_thread(void * dummy)
   {
  @@ -912,8 +933,6 @@
       pool *ptrans;            /* Pool for per-transaction stuff */
       int sd = -1;
       int srv;
  -    int ret;
  -    char pipe_read_char;
       int curr_pollfd, last_pollfd = 0;
       size_t len = sizeof(struct sockaddr);
   
  @@ -958,24 +977,8 @@
               if (listenfds[0].revents & POLLIN) {
                   /* A process got a signal on the shutdown pipe. Check if 
we're
                    * the lucky process to die. */
  -                pthread_mutex_lock(&pipe_of_death_mutex);
  -                if (!workers_may_exit) {
  -                    ret = read(listenfds[0].fd, &pipe_read_char, 1);
  -                    if (ret == -1 && errno == EAGAIN) {
  -                        /* It lost the lottery. It must continue to suffer
  -                         * through a life of servitude. */
  -                        pthread_mutex_unlock(&pipe_of_death_mutex);
  -                        continue;
  -                    }
  -                    else {
  -                        /* It won the lottery (or something else is very
  -                         * wrong). Embrace death with open arms. */
  -                        workers_may_exit = 1;
  -                        pthread_mutex_unlock(&pipe_of_death_mutex);
  -                        break;
  -                    }
  -                }
  -                pthread_mutex_unlock(&pipe_of_death_mutex);
  +                check_pipe_of_death();
  +                continue;
               }
   
               if (num_listenfds == 1) {
  
  
  

Reply via email to