From f2312262c77f4c2a5e35b984a9a012e8332690d4 Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Thu, 6 Sep 2001 21:16:35 +0000 Subject: Try moving the kill thread code into the thread_main() function so it can check if there are too many thread after it's finished with it's request. Needs to be cleaned up further (if this is the right idea) because of the locking around the servers_waiting variable. --- src/thread.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/thread.c b/src/thread.c index 8245928..b5dd39d 100644 --- a/src/thread.c +++ b/src/thread.c @@ -1,4 +1,4 @@ -/* $Id: thread.c,v 1.9 2001-09-06 19:00:47 rjkaes Exp $ +/* $Id: thread.c,v 1.10 2001-09-06 21:16:35 rjkaes Exp $ * * Handles the creation/destruction of the various threads required for * processing incoming connections. @@ -140,6 +140,16 @@ static void *thread_main(void *arg) } } + if (servers_waiting > thread_config.maxspareservers) { + /* + * There are too many spare threads, kill ourselves + * off. + */ + log_message(LOG_NOTICE, "Too many spare threads, killing ourself."); + ptr->status = T_EMPTY; + return NULL; + } + ptr->status = T_WAITING; SERVER_INC(); @@ -195,8 +205,8 @@ int thread_pool_create(void) } /* - * Keep the proper number of servers running. This is the birth and death - * of the servers. It monitors this at least once a second. + * Keep the proper number of servers running. This is the birth of the + * servers. It monitors this at least once a second. */ int thread_main_loop(void) { @@ -216,22 +226,6 @@ int thread_main_loop(void) break; } } - } else if (servers_waiting > thread_config.maxspareservers) { - DEBUG2("servers_waiting: %d MaxSpareServers: %d", servers_waiting, thread_config.maxspareservers); - for (i = 0; i < thread_config.maxclients; i++) { - if (thread_ptr[i].status == T_WAITING) { - pthread_join(thread_ptr[i].tid, NULL); - - SERVER_DEC(); - - thread_ptr[i].status = T_EMPTY; - thread_ptr[i].connects = 0; - - log_message(LOG_NOTICE, "Killed off a thread."); - break; - } - } - DEBUG1("finished killing threads"); } return 0; -- cgit v1.2.3