Fixed a problem with polling for the number of active threads. No longer
polls. :)
This commit is contained in:
parent
068b0337c5
commit
0051208777
28
src/thread.c
28
src/thread.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: thread.c,v 1.1 2000-09-12 00:07:44 rjkaes Exp $
|
/* $Id: thread.c,v 1.2 2000-12-08 03:35:07 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* Handles the creation/destruction of the various threads required for
|
* Handles the creation/destruction of the various threads required for
|
||||||
* processing incoming connections.
|
* processing incoming connections.
|
||||||
@ -39,7 +39,6 @@ struct thread_config_s {
|
|||||||
|
|
||||||
static unsigned int servers_waiting; /* servers waiting for a connection */
|
static unsigned int servers_waiting; /* servers waiting for a connection */
|
||||||
static pthread_mutex_t servers_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t servers_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static pthread_cond_t servers_cond = PTHREAD_COND_INITIALIZER;
|
|
||||||
|
|
||||||
#define LOCK_SERVERS() pthread_mutex_lock(&servers_mutex)
|
#define LOCK_SERVERS() pthread_mutex_lock(&servers_mutex)
|
||||||
#define UNLOCK_SERVERS() pthread_mutex_unlock(&servers_mutex)
|
#define UNLOCK_SERVERS() pthread_mutex_unlock(&servers_mutex)
|
||||||
@ -155,27 +154,10 @@ int thread_pool_create(void)
|
|||||||
int thread_main_loop(void)
|
int thread_main_loop(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct timeval tv;
|
|
||||||
struct timespec ts;
|
|
||||||
|
|
||||||
while (config.quit == FALSE) {
|
|
||||||
/* Wait for one of the threads to signal */
|
|
||||||
pthread_mutex_lock(&servers_mutex);
|
|
||||||
while (config.quit == FALSE
|
|
||||||
&& servers_waiting < thread_config.maxspareservers
|
|
||||||
&& servers_waiting > thread_config.minspareservers) {
|
|
||||||
if (gettimeofday(&tv, NULL) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ts.tv_sec = tv.tv_sec + 1;
|
|
||||||
ts.tv_nsec = tv.tv_usec * 1000;
|
|
||||||
pthread_cond_timedwait(&servers_cond, &servers_mutex, &ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.quit == TRUE)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* If there are not enough spare servers, create more */
|
/* If there are not enough spare servers, create more */
|
||||||
|
LOCK_SERVERS();
|
||||||
|
|
||||||
if (servers_waiting < thread_config.minspareservers) {
|
if (servers_waiting < thread_config.minspareservers) {
|
||||||
for (i = 0; i < thread_config.maxclients; i++) {
|
for (i = 0; i < thread_config.maxclients; i++) {
|
||||||
if (thread_ptr[i].status == T_EMPTY) {
|
if (thread_ptr[i].status == T_EMPTY) {
|
||||||
@ -197,8 +179,8 @@ int thread_main_loop(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&servers_mutex);
|
|
||||||
}
|
UNLOCK_SERVERS();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tinyproxy.c,v 1.7 2000-11-23 04:46:48 rjkaes Exp $
|
/* $Id: tinyproxy.c,v 1.8 2000-12-08 03:35:07 rjkaes Exp $
|
||||||
*
|
*
|
||||||
* The initialise routine. Basically sets up all the initial stuff (logfile,
|
* The initialise routine. Basically sets up all the initial stuff (logfile,
|
||||||
* listening socket, config options, etc.) and then sits there and loops
|
* listening socket, config options, etc.) and then sits there and loops
|
||||||
@ -82,6 +82,7 @@ void takesig(int sig)
|
|||||||
log(LOG_INFO, "SIGTERM received.");
|
log(LOG_INFO, "SIGTERM received.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sig != SIGTERM)
|
if (sig != SIGTERM)
|
||||||
signal(sig, takesig);
|
signal(sig, takesig);
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
@ -326,7 +327,10 @@ int main(int argc, char **argv)
|
|||||||
* Start the main loop.
|
* Start the main loop.
|
||||||
*/
|
*/
|
||||||
log(LOG_INFO, "Starting main loop. Accepting connections.");
|
log(LOG_INFO, "Starting main loop. Accepting connections.");
|
||||||
|
do {
|
||||||
thread_main_loop();
|
thread_main_loop();
|
||||||
|
sleep(1);
|
||||||
|
} while (!config.quit);
|
||||||
|
|
||||||
log(LOG_INFO, "Shutting down.");
|
log(LOG_INFO, "Shutting down.");
|
||||||
thread_close_sock();
|
thread_close_sock();
|
||||||
|
Loading…
Reference in New Issue
Block a user