From 33a1a5142960f55425b893a126e96a3b67a27f62 Mon Sep 17 00:00:00 2001 From: Manoj Kasichainula Date: Wed, 11 Aug 1999 23:55:42 +0000 Subject: [PATCH] Move a little code around to shorten the worker_thread function a bit. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@83646 13f79535-47bb-0310-9956-ffa450edef68 --- server/mpm/dexter/dexter.c | 43 ++++++++++++++------------ server/mpm/mpmt_pthread/mpmt_pthread.c | 43 ++++++++++++++------------ 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/server/mpm/dexter/dexter.c b/server/mpm/dexter/dexter.c index 4cde4c99f8..f6c9335eba 100644 --- a/server/mpm/dexter/dexter.c +++ b/server/mpm/dexter/dexter.c @@ -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) { diff --git a/server/mpm/mpmt_pthread/mpmt_pthread.c b/server/mpm/mpmt_pthread/mpmt_pthread.c index 9c4c0b65d7..a60798ace1 100644 --- a/server/mpm/mpmt_pthread/mpmt_pthread.c +++ b/server/mpm/mpmt_pthread/mpmt_pthread.c @@ -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) { -- 2.50.1