Refcount backends

parent 383e68dc
......@@ -72,10 +72,13 @@ void
vdir_delete(struct vdir **vdp)
{
struct vdir *vd;
unsigned u;
TAKE_OBJ_NOTNULL(vd, vdp, VDIR_MAGIC);
AZ(vd->dir);
for (u = 0; u < vd->n_backend; u++)
VRT_Assign_Backend(&vd->backend[u], NULL);
free(vd->backend);
free(vd->weight);
AZ(pthread_rwlock_destroy(&vd->mtx));
......@@ -123,7 +126,7 @@ vdir_add_backend(VRT_CTX, struct vdir *vd, VCL_BACKEND be, double weight)
vdir_expand(vd, vd->l_backend + 16);
assert(vd->n_backend < vd->l_backend);
u = vd->n_backend++;
vd->backend[u] = be;
VRT_Assign_Backend(&vd->backend[u], be);
vd->weight[u] = weight;
vd->total_weight += weight;
vdir_unlock(vd);
......@@ -150,6 +153,7 @@ vdir_remove_backend(VRT_CTX, struct vdir *vd, VCL_BACKEND be, unsigned *cur)
vdir_unlock(vd);
return;
}
VRT_Assign_Backend(&vd->backend[u], NULL);
vd->total_weight -= vd->weight[u];
n = (vd->n_backend - u) - 1;
memmove(&vd->backend[u], &vd->backend[u+1], n * sizeof(vd->backend[0]));
......
......@@ -266,6 +266,7 @@ vmod_random_add_backend(VRT_CTX,
AZ(pthread_cond_init(&prop->wakeup.cv, NULL));
prop->vd = rr->vd;
prop->be = be;
VRT_Assign_Backend(&prop->dir, args->backend);
prop->vd_updates = &rr->extra.updates;
AN(args->weight_update);
prop->vre = args->weight_update;
......@@ -297,6 +298,7 @@ vmod_random_add_backend(VRT_CTX,
return;
err:
VRT_Assign_Backend(&prop->dir, NULL);
FREE_OBJ(prop);
}
......
......@@ -381,6 +381,7 @@ wadj_dir_fini(const struct wadj_prop_head *vd_props,
VTAILQ_FOREACH_SAFE(prop, vd_props, list_vd, save) {
VTAILQ_REMOVE(vcl_props, prop, list_vcl);
VRT_Assign_Backend(&prop->dir, NULL);
wadj_thr_stop(prop);
wadj_prop_fini(&prop);
AZ(prop);
......
......@@ -48,6 +48,7 @@ struct wadj_prop {
struct vdir *vd;
struct backend *be;
VCL_BACKEND dir;
int *vd_updates;
pthread_t thread;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment