From: chris mikkelson Date: Wed, 25 Mar 2009 03:56:48 +0000 (-0500) Subject: Fixed listener thread "starting gun" logic. X-Git-Url: https://git.mikk.net/?a=commitdiff_plain;h=db4f4a63dbe2709ace6b226800b013f25f16bb36;p=smtpsink Fixed listener thread "starting gun" logic. --- diff --git a/conn_pool.c b/conn_pool.c index 9a4392a..aca603f 100644 --- a/conn_pool.c +++ b/conn_pool.c @@ -15,6 +15,7 @@ #include "conn_queue.h" #include "smtpsink-int.h" + /* struct conn_pool should be private */ static struct conn_pool { pthread_mutex_t cpmtx; @@ -86,7 +87,7 @@ wait_conn(void) static pthread_cond_t lc; static pthread_mutex_t lmtx; -static int nl=0; +static int nl=0, lready = 0; static void * listener_loop(void *data) @@ -102,7 +103,8 @@ listener_loop(void *data) * before all queues are initialized. */ if (pthread_mutex_lock(&lmtx)) assert(0); - if (pthread_cond_wait(&lc, &lmtx)) assert(0); + if (!lready) + if (pthread_cond_wait(&lc, &lmtx)) assert(0); pthread_mutex_unlock(&lmtx); while (1) { @@ -179,8 +181,8 @@ new_listener(char *spec) void start_listeners(void) { - int i; - for (i = 0; i < nl; i++) { - pthread_cond_signal(&lc); - } + if (pthread_mutex_lock(&lmtx)) assert(0); + lready = 1; + pthread_mutex_unlock(&lmtx); + pthread_cond_broadcast(&lc); }