]> git.mikk.net Git - smtpsink/commitdiff
Fixed listener thread "starting gun" logic.
authorchris mikkelson <chris@mikk.net>
Wed, 25 Mar 2009 03:56:48 +0000 (22:56 -0500)
committerchris mikkelson <chris@mikk.net>
Wed, 25 Mar 2009 03:56:48 +0000 (22:56 -0500)
conn_pool.c

index 9a4392a1d418cbd5d23de895083bae36df59c433..aca603f05b6d5e4c8dcde6169533f0bc9b943c50 100644 (file)
@@ -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);
 }