[master] 4e7516a Add new waiters under lock to prevent races with the timer thread.

Poul-Henning Kamp phk at FreeBSD.org
Thu Jan 15 17:12:15 CET 2015


commit 4e7516af86029eb12c0953c4243a69d75172d05a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jan 15 16:11:54 2015 +0000

    Add new waiters under lock to prevent races with the timer thread.

diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c
index 88b61c2..4f71f96 100644
--- a/bin/varnishd/waiter/cache_waiter.c
+++ b/bin/varnishd/waiter/cache_waiter.c
@@ -109,14 +109,11 @@ Wait_New(waiter_handle_f *func, volatile double *tmo)
 	waiter->init(w);
 	AN(w->impl->pass || w->pipes[1] >= 0);
 
-	if (w->pipes[1] >= 0 && VTAILQ_EMPTY(&waiters)) {
-		/* Start timer poker thread */
-		AZ(pthread_create(&wait_thr, NULL, wait_poker_thread, NULL));
-	}
-
 	Lck_Lock(&wait_mtx);
 	VTAILQ_INSERT_TAIL(&waiters, w, list);
 	nwaiters++;
+	if (w->pipes[1] >= 0 && nwaiters == 1)
+		AZ(pthread_create(&wait_thr, NULL, wait_poker_thread, NULL));
 	Lck_Unlock(&wait_mtx);
 	return (w);
 }



More information about the varnish-commit mailing list