[master] 2d927b1 Don't protect the barriers list with a lock

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Mar 8 20:28:05 CET 2017


commit 2d927b1219da282b0d4594859461180bf827773d
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Mar 8 20:21:12 2017 +0100

    Don't protect the barriers list with a lock
    
    A command like `barrier r1` would fail while holding the lock because of
    the invalid name, but the reset of the test case would then deadlock. It
    leads to a timeout like we see sometimes on VTEST so getting rid of them
    may just require to review when `vtc_fatal` is called while locking.
    
    In this very case we can only create barriers in the top thread so the
    lock is useless.

diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index 518635d..76f5706 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -828,7 +828,6 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
 	AN(vltop);
 
 	init_macro();
-	init_barrier();
 	init_server();
 
 	/* Move into our tmpdir */
diff --git a/bin/varnishtest/vtc_barrier.c b/bin/varnishtest/vtc_barrier.c
index 41cbf20..d621f68 100644
--- a/bin/varnishtest/vtc_barrier.c
+++ b/bin/varnishtest/vtc_barrier.c
@@ -67,7 +67,6 @@ struct barrier {
 	volatile unsigned	need_join;
 };
 
-static pthread_mutex_t		barrier_mtx;
 static VTAILQ_HEAD(, barrier)	barriers = VTAILQ_HEAD_INITIALIZER(barriers);
 
 static struct barrier *
@@ -412,7 +411,6 @@ cmd_barrier(CMD_ARGS)
 	(void)cmd;
 
 	if (av == NULL) {
-		AZ(pthread_mutex_lock(&barrier_mtx));
 		/* Reset and free */
 		VTAILQ_FOREACH_SAFE(b, &barriers, list, b2) {
 			r = pthread_mutex_trylock(&b->mtx);
@@ -432,23 +430,20 @@ cmd_barrier(CMD_ARGS)
 			}
 			AZ(pthread_mutex_unlock(&b->mtx));
 		}
-		AZ(pthread_mutex_unlock(&barrier_mtx));
 		return;
 	}
 
 	AZ(strcmp(av[0], "barrier"));
 	av++;
 
-	AZ(pthread_mutex_lock(&barrier_mtx));
 	VTAILQ_FOREACH(b, &barriers, list)
 		if (!strcmp(b->name, av[0]))
 			break;
 	if (b == NULL)
 		b = barrier_new(av[0], vl);
 	av++;
-	AZ(pthread_mutex_lock(&b->mtx));
-	AZ(pthread_mutex_unlock(&barrier_mtx));
 
+	AZ(pthread_mutex_lock(&b->mtx));
 	for (; *av != NULL; av++) {
 		if (!strcmp(*av, "cond")) {
 			av++;
@@ -474,10 +469,3 @@ cmd_barrier(CMD_ARGS)
 	}
 	AZ(pthread_mutex_unlock(&b->mtx));
 }
-
-void
-init_barrier(void)
-{
-
-	AZ(pthread_mutex_init(&barrier_mtx, NULL));
-}



More information about the varnish-commit mailing list