]> granicus.if.org Git - apache/commitdiff
Move a little code around to shorten the worker_thread function a bit.
authorManoj Kasichainula <manoj@apache.org>
Wed, 11 Aug 1999 23:55:42 +0000 (23:55 +0000)
committerManoj Kasichainula <manoj@apache.org>
Wed, 11 Aug 1999 23:55:42 +0000 (23:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@83646 13f79535-47bb-0310-9956-ffa450edef68

server/mpm/dexter/dexter.c
server/mpm/mpmt_pthread/mpmt_pthread.c

index 4cde4c99f8f0b56008c5c202b0b50ad6a2d32d86..f6c9335eba1078dd6e5d1045eba8471f206d3e38 100644 (file)
@@ -930,6 +930,27 @@ static int start_thread(worker_thread_info *thread_info)
     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 @@ static void *worker_thread(void *arg)
     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 @@ static void *worker_thread(void *arg)
             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) {
index 9c4c0b65d7a7f0fee446c8dd08c1f52142e152d6..a60798ace1d06dc59c313c81d7d381d1414fd15e 100644 (file)
@@ -900,6 +900,27 @@ static void process_socket(pool *p, struct sockaddr *sa_client, int csd, int my_
 
     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 @@ static void * worker_thread(void * dummy)
     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 @@ static void * worker_thread(void * dummy)
             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) {