[ccan] [PATCH] tap: fix pthread uses

Rusty Russell rusty at rustcorp.com.au
Mon Jul 4 17:30:08 EST 2011


On Mon, 4 Jul 2011 09:07:12 +0300, "Kirill A. Shutemov" <kirill at shutemov.name> wrote:
> On Mon, Jul 04, 2011 at 08:44:19AM +0930, Rusty Russell wrote:
> > On Sun,  3 Jul 2011 20:36:48 +0300, "Kirill A. Shutemov" <kirill at shutemov.name> wrote:
> > > From: "Kirill A. Shutemov" <kirill at shutemov.name>
> > > 
> > > tap expects that HAVE_LIBPTHREAD will be defined, but configurator
> > > doesn't provide it:
> > > 
> > > ccan/tap/tap.c:49:5: warning: "HAVE_LIBPTHREAD" is not defined [-Wundef]
> > > 
> > > Lets check for <pthread.h> in configurator and provide HAVE_PTHREAD_H
> > > based on the results.
> > > 
> > > Signed-off-by: Kirill A. Shutemov <kirill at shutemov.name>
> > 
> > Hmm, this predates me taking over maintenance of tap.
> > 
> > I'm not entirely convinced that having multiple threads use tap at the
> > same time makes sense, nor sure that dragging in pthreads for every tap
> > user is desirable.
> > 
> > I'm tempted to change it to WANT_PTHREAD.  Do you actually need it?
> 
> No, I want clean build log ;)

Excellent!

Here's what I just committed:

commit 532feb88f516f0848ae0e3eaf3a89a1fc94db6c4
Author: Rusty Russell <rusty at rustcorp.com.au>
Date:   Mon Jul 4 16:57:03 2011 +0930

    tap: WANT_PTHREAD not HAVE_PTHREAD
    
    I'm not sure that a "pthread-safe" tap library is very useful; how many
    people have multiple threads calling ok()?
    
    Kirill Shutemov noted that it gives a warning with -Wundef; indeed, we
    should ask in this case whether they want pthread support, not whether the
    system has pthread support to offer.

diff --git a/ccan/tap/tap.c b/ccan/tap/tap.c
index b7a84ac..7c01e14 100644
--- a/ccan/tap/tap.c
+++ b/ccan/tap/tap.c
@@ -45,8 +45,13 @@ static int test_died = 0;
 static int test_pid;
 
 /* Encapsulate the pthread code in a conditional.  In the absence of
-   libpthread the code does nothing */
-#if HAVE_LIBPTHREAD
+   libpthread the code does nothing.
+
+   If you have multiple threads calling ok() etc. at the same time you would
+   need this, but in that case your test numbers will be random and I'm not
+   sure it makes sense. --RR
+*/
+#ifdef WANT_PTHREAD
 #include <pthread.h>
 static pthread_mutex_t M = PTHREAD_MUTEX_INITIALIZER;
 # define LOCK pthread_mutex_lock(&M)


More information about the ccan mailing list