[master] 467f44b Make the ban lurker sleep on a condvar so other code can wake it up.
Poul-Henning Kamp
phk at FreeBSD.org
Fri Oct 23 00:49:02 CEST 2015
commit 467f44b2afff70c177e8ad099816ae304cfddd36
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Oct 22 20:34:18 2015 +0000
Make the ban lurker sleep on a condvar so other code can wake it up.
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 95ca144..6d66999 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -756,6 +756,7 @@ BAN_Init(void)
bp = BAN_Build();
AN(bp);
AZ(BAN_Commit(bp));
+ AZ(pthread_cond_init(&ban_lurker_cond, NULL));
Lck_Lock(&ban_mtx);
ban_mark_completed(VTAILQ_FIRST(&ban_head));
Lck_Unlock(&ban_mtx);
@@ -774,9 +775,8 @@ BAN_Shutdown(void)
{
void *status;
- Lck_Lock(&ban_mtx);
ban_shutdown = 1;
- Lck_Unlock(&ban_mtx);
+ ban_kick_lurker();
AZ(pthread_join(ban_thread, &status));
AZ(status);
diff --git a/bin/varnishd/cache/cache_ban.h b/bin/varnishd/cache/cache_ban.h
index 047d0f9..100acee 100644
--- a/bin/varnishd/cache/cache_ban.h
+++ b/bin/varnishd/cache/cache_ban.h
@@ -105,6 +105,7 @@ extern struct lock ban_mtx;
extern int ban_shutdown;
extern struct banhead_s ban_head;
extern struct ban * volatile ban_start;
+extern pthread_cond_t ban_lurker_cond;
void ban_mark_completed(struct ban *b);
unsigned ban_len(const uint8_t *banspec);
@@ -114,3 +115,4 @@ int ban_evaluate(struct worker *wrk, const uint8_t *bs, struct objcore *oc,
double ban_time(const uint8_t *banspec);
int ban_equal(const uint8_t *bs1, const uint8_t *bs2);
void BAN_Free(struct ban *b);
+void ban_kick_lurker(void);
diff --git a/bin/varnishd/cache/cache_ban_lurker.c b/bin/varnishd/cache/cache_ban_lurker.c
index cfcdd26..821d8c8 100644
--- a/bin/varnishd/cache/cache_ban_lurker.c
+++ b/bin/varnishd/cache/cache_ban_lurker.c
@@ -38,6 +38,18 @@
static struct objcore oc_marker = { .magic = OBJCORE_MAGIC, };
static unsigned ban_batch;
+static unsigned ban_generation;
+
+pthread_cond_t ban_lurker_cond;
+
+void
+ban_kick_lurker(void)
+{
+ Lck_Lock(&ban_mtx);
+ ban_generation++;
+ AZ(pthread_cond_signal(&ban_lurker_cond));
+ Lck_Unlock(&ban_mtx);
+}
static void
ban_cleantail(void)
@@ -254,7 +266,10 @@ ban_lurker(struct worker *wrk, void *priv)
if (d <= 0.0 || !ban_lurker_work(wrk, &vsl))
d = 0.609; // Random, non-magic
ban_cleantail();
- VTIM_sleep(d);
+ d += VTIM_real();
+ Lck_Lock(&ban_mtx);
+ (void)Lck_CondWait(&ban_lurker_cond, &ban_mtx, d);
+ Lck_Unlock(&ban_mtx);
}
pthread_exit(0);
NEEDLESS_RETURN(NULL);
More information about the varnish-commit
mailing list