[PATCH 06/10] Signal the smp_thread() by condvar

Martin Blix Grydeland martin at varnish-software.com
Wed Oct 10 16:27:19 CEST 2012


---
 bin/varnishd/storage/storage_persistent.c      |    8 +++++---
 bin/varnishd/storage/storage_persistent.h      |    1 +
 bin/varnishd/storage/storage_persistent_silo.c |    4 ++--
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 0575c11..429cd45 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -429,9 +429,9 @@ smp_thread(struct worker *wrk, void *priv)
 		if (sc->flags & SMP_SC_SYNC)
 			smp_save_segs(sc);
 
-		Lck_Unlock(&sc->mtx);
-		VTIM_sleep(3.14159265359 - 2);
-		Lck_Lock(&sc->mtx);
+		if (!(sc->flags & (SMP_SC_SYNC | SMP_SC_STOP)))
+			/* Wait for something to do */
+			(void)Lck_CondWait(&sc->cond, &sc->mtx, NULL);
 	}
 
 	smp_save_segs(sc);
@@ -455,6 +455,7 @@ smp_open(const struct stevedore *st)
 
 	CAST_OBJ_NOTNULL(sc, st->priv, SMP_SC_MAGIC);
 
+	AZ(pthread_cond_init(&sc->cond, NULL));
 	Lck_New(&sc->mtx, lck_smp);
 	Lck_Lock(&sc->mtx);
 
@@ -523,6 +524,7 @@ smp_signal_close(const struct stevedore *st)
 		smp_close_seg(sc, sc->cur_seg);
 	AZ(sc->cur_seg);
 	sc->flags |= SMP_SC_STOP;
+	AZ(pthread_cond_signal(&sc->cond));
 	Lck_Unlock(&sc->mtx);
 }
 
diff --git a/bin/varnishd/storage/storage_persistent.h b/bin/varnishd/storage/storage_persistent.h
index 0c4e3a3..e716c51 100644
--- a/bin/varnishd/storage/storage_persistent.h
+++ b/bin/varnishd/storage/storage_persistent.h
@@ -142,6 +142,7 @@ struct smp_sc {
 	struct ban		*tailban;
 	uint64_t		ban1_offset;
 
+	pthread_cond_t		cond;
 	struct lock		mtx;
 
 	/* Cleaner metrics */
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index fb384ee..9dd827e 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -56,6 +56,7 @@ smp_sync_segs(struct smp_sc *sc)
 {
 	Lck_AssertHeld(&sc->mtx);
 	sc->flags |= SMP_SC_SYNC;
+	AZ(pthread_cond_signal(&sc->cond));
 }
 
 /*--------------------------------------------------------------------
@@ -269,7 +270,6 @@ smp_close_seg(struct smp_sc *sc, struct smp_seg *sg)
 	sc->free_offset = smp_segend(sg);
 }
 
-
 /*---------------------------------------------------------------------
  */
 
@@ -487,7 +487,7 @@ smp_oc_freeobj(struct objcore *oc)
 
 	if (sg->nobj == 0 && sg == VTAILQ_FIRST(&sg->sc->segments)) {
 		/* Sync segments to remove empty at start */
-		sg->sc->flags |= SMP_SC_SYNC;
+		smp_sync_segs(sg->sc);
 	}
 
 	Lck_Unlock(&sg->sc->mtx);
-- 
1.7.9.5




More information about the varnish-dev mailing list