From db4f4a63dbe2709ace6b226800b013f25f16bb36 Mon Sep 17 00:00:00 2001 From: chris mikkelson Date: Tue, 24 Mar 2009 22:56:48 -0500 Subject: [PATCH] Fixed listener thread "starting gun" logic. --- conn_pool.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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); } -- 2.50.1