diff options
author | Robert James Kaes <rjkaes@users.sourceforge.net> | 2001-09-06 21:16:35 +0000 |
---|---|---|
committer | Robert James Kaes <rjkaes@users.sourceforge.net> | 2001-09-06 21:16:35 +0000 |
commit | f2312262c77f4c2a5e35b984a9a012e8332690d4 (patch) | |
tree | a369d0d2c8cc8314c18e926c1f49049f3bedd0c8 | |
parent | 445aaca53e0964f3243e4641b556c79493d8bb14 (diff) | |
download | tinyproxy-f2312262c77f4c2a5e35b984a9a012e8332690d4.tar.gz tinyproxy-f2312262c77f4c2a5e35b984a9a012e8332690d4.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/thread.c | 32 |
1 files changed, 13 insertions, 19 deletions
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; |