[master] d486144 Point the vbc at the cond-var, rather than the worker while it's stolen. This should make it less tempting to do illadvised things.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Jun 24 22:45:12 CEST 2015
commit d486144aaf900f44d394923817a3a21a5682a186
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Jun 24 16:35:52 2015 +0000
Point the vbc at the cond-var, rather than the worker while it's
stolen. This should make it less tempting to do illadvised things.
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index 37ce9ce..bd812ab 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -100,7 +100,7 @@ struct vbc {
struct tcp_pool *tcp_pool;
struct backend *backend;
- struct worker *wrk;
+ pthread_cond_t *cond;
};
/* cache_backend.c */
@@ -128,5 +128,5 @@ void VBT_Recycle(const struct worker *, struct tcp_pool *, struct vbc **);
void VBT_Close(struct tcp_pool *tp, struct vbc **vbc);
struct vbc *VBT_Get(struct tcp_pool *, double tmo, struct backend *,
struct worker *);
-void VBT_Wait(struct worker *wrk, const struct vbc *vbc);
+void VBT_Wait(struct worker *, struct vbc *);
diff --git a/bin/varnishd/cache/cache_backend_tcp.c b/bin/varnishd/cache/cache_backend_tcp.c
index 9a658dd..a307e71 100644
--- a/bin/varnishd/cache/cache_backend_tcp.c
+++ b/bin/varnishd/cache/cache_backend_tcp.c
@@ -96,8 +96,8 @@ tcp_handle(struct waited *w, enum wait_event ev, double now)
vbc->state = VBC_STATE_USED;
VTAILQ_REMOVE(&tp->connlist, vbc, list);
CHECK_OBJ_NOTNULL(vbc->backend, BACKEND_MAGIC);
- CHECK_OBJ_NOTNULL(vbc->wrk, WORKER_MAGIC);
- AZ(pthread_cond_signal(&vbc->wrk->cond));
+ AN(vbc->cond);
+ AZ(pthread_cond_signal(vbc->cond));
break;
case VBC_STATE_AVAIL:
VTCP_close(&vbc->fd);
@@ -366,7 +366,7 @@ VBT_Get(struct tcp_pool *tp, double tmo, struct backend *be, struct worker *wrk)
VSC_C_main->backend_reuse += 1;
vbc->state = VBC_STATE_STOLEN;
vbc->backend = be;
- vbc->wrk = wrk;
+ vbc->cond = &wrk->cond;
}
tp->n_used++; // Opening mostly works
Lck_Unlock(&tp->mtx);
@@ -395,7 +395,7 @@ VBT_Get(struct tcp_pool *tp, double tmo, struct backend *be, struct worker *wrk)
*/
void
-VBT_Wait(struct worker *wrk, const struct vbc *vbc)
+VBT_Wait(struct worker *wrk, struct vbc *vbc)
{
struct tcp_pool *tp;
@@ -404,10 +404,11 @@ VBT_Wait(struct worker *wrk, const struct vbc *vbc)
CHECK_OBJ_NOTNULL(vbc->backend, BACKEND_MAGIC);
tp = vbc->tcp_pool;
CHECK_OBJ_NOTNULL(tp, TCP_POOL_MAGIC);
- assert(vbc->wrk == wrk);
+ assert(vbc->cond == &wrk->cond);
Lck_Lock(&tp->mtx);
while (vbc->state == VBC_STATE_STOLEN)
AZ(Lck_CondWait(&wrk->cond, &tp->mtx, 0));
assert(vbc->state == VBC_STATE_USED);
+ vbc->cond = NULL;
Lck_Unlock(&tp->mtx);
}
More information about the varnish-commit
mailing list