diff options
author | Robert James Kaes <rjkaes@users.sourceforge.net> | 2002-04-28 02:37:01 +0000 |
---|---|---|
committer | Robert James Kaes <rjkaes@users.sourceforge.net> | 2002-04-28 02:37:01 +0000 |
commit | 577f3cebbf1caf7b07c635721949884672ce2c94 (patch) | |
tree | 40e7020fe6e33e6f94dcab7b3ad597502adcba76 /src/thread.c | |
parent | 1a8c914dd2872ea29bd656d54a63e5ddab2c082b (diff) |
Fixed up the error detection code when relating the pthread functions.
They return 0 if OK, and a positive error code.
Cleaned up the status setting code in thread_main().
Thanks to Hans-Georg Bork for fixing the problem in thread_pool_create()
where the status wasn't set early enough to allow all the threads to be
created.
Added additional logging information to let the admin know what is
happening with the thread creation.
Diffstat (limited to 'src/thread.c')
-rw-r--r-- | src/thread.c | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/src/thread.c b/src/thread.c index b55f8e8..7c61689 100644 --- a/src/thread.c +++ b/src/thread.c @@ -1,4 +1,4 @@ -/* $Id: thread.c,v 1.26 2002-04-22 19:41:17 rjkaes Exp $ +/* $Id: thread.c,v 1.27 2002-04-28 02:37:01 rjkaes Exp $ * * Handles the creation/destruction of the various threads required for * processing incoming connections. @@ -66,7 +66,7 @@ static struct thread_config_s { unsigned int maxspareservers, minspareservers, startservers; } thread_config; -static unsigned int servers_waiting; /* servers waiting for a connection */ +static int servers_waiting = 0; /* servers waiting for a connection */ static pthread_mutex_t servers_mutex; #define SERVER_COUNT_LOCK() do { \ @@ -80,7 +80,7 @@ assert(servers_mutex_ret == 0); \ #define SERVER_INC() do { \ SERVER_COUNT_LOCK(); \ - DEBUG2("INC: servers_waiting: %u", servers_waiting); \ + DEBUG2("INC: servers_waiting: %d", servers_waiting); \ ++servers_waiting; \ SERVER_COUNT_UNLOCK(); \ } while (0) @@ -88,7 +88,7 @@ assert(servers_mutex_ret == 0); \ #define SERVER_DEC() do { \ SERVER_COUNT_LOCK(); \ --servers_waiting; \ - DEBUG2("DEC: servers_waiting: %u", servers_waiting); \ + DEBUG2("DEC: servers_waiting: %d", servers_waiting); \ SERVER_COUNT_UNLOCK(); \ } while (0) @@ -144,7 +144,11 @@ thread_main(void *arg) if (!cliaddr) return NULL; + ptr->connects = 0; + while (!config.quit) { + ptr->status = T_WAITING; + clilen = addrlen; /* @@ -190,8 +194,6 @@ thread_main(void *arg) ptr->connects, thread_config.maxrequestsperchild); - ptr->status = T_EMPTY; - break; } } @@ -207,17 +209,15 @@ thread_main(void *arg) log_message(LOG_NOTICE, "Waiting servers exceeds MaxSpareServers. Killing thread."); - ptr->status = T_EMPTY; - break; } SERVER_COUNT_UNLOCK(); - ptr->status = T_WAITING; - SERVER_INC(); } + ptr->status = T_EMPTY; + safefree(cliaddr); return NULL; } @@ -270,23 +270,29 @@ thread_pool_create(void) thread_config.startservers = thread_config.maxclients; } + for (i = thread_config.startservers; i < thread_config.maxclients; i++) { + thread_ptr[i].status = T_EMPTY; + thread_ptr[i].connects = 0; + } + for (i = 0; i < thread_config.startservers; i++) { + DEBUG2("Trying to create thread %d of %d", i + 1, thread_config.startservers); + thread_ptr[i].status = T_WAITING; pthread_ret = pthread_create(&thread_ptr[i].tid, &thread_attr, &thread_main, &thread_ptr[i]); - if (pthread_ret < 0) { - log_message(LOG_WARNING, "Could not create thread number %d of %d: %s", - i, thread_config.startservers, strerror(errno)); + if (pthread_ret != 0) { + log_message(LOG_WARNING, + "Could not create thread number %d of %d: %s", + i, thread_config.startservers, + strerror(pthread_ret)); return -1; } else { - thread_ptr[i].status = T_WAITING; + log_message(LOG_INFO, "Creating thread number %d of %d ...", i + 1, thread_config.startservers); + servers_waiting++; } } - servers_waiting = thread_config.startservers; - for (i = thread_config.startservers; i < thread_config.maxclients; i++) { - thread_ptr[i].status = T_EMPTY; - thread_ptr[i].connects = 0; - } + log_message(LOG_INFO, "Finished creating all threads."); return 0; } @@ -316,10 +322,10 @@ thread_main_loop(void) &thread_attr, &thread_main, &thread_ptr[i]); - if (pthread_ret < 0) { + if (pthread_ret != 0) { log_message(LOG_NOTICE, "Could not create thread: %s", - strerror(errno)); + strerror(pthread_ret)); break; } |