]> err.no Git - varnish/commitdiff
A bit of cleanup while I ponder ticket 412:
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 18 Dec 2008 10:04:15 +0000 (10:04 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 18 Dec 2008 10:04:15 +0000 (10:04 +0000)
make VBE_free_bereq() and HSH_Deref() null their argument pointer.

Add HSH_Drop() for deorbiting unwanted busy objects.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3464 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_backend.c
varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/cache_expire.c
varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/cache_hash.c
varnish-cache/bin/varnishd/cache_pipe.c
varnish-cache/bin/varnishd/hash_slinger.h

index 8803dba5a7cd8895cad7573b2fb1346341d3f271..aeee3d55b2f62ad42930ce70ef5f460a4fb5969c 100644 (file)
@@ -407,7 +407,7 @@ void VBE_GetFd(struct sess *sp);
 void VBE_ClosedFd(struct sess *sp);
 void VBE_RecycleFd(struct sess *sp);
 struct bereq * VBE_new_bereq(void);
-void VBE_free_bereq(struct bereq *bereq);
+void VBE_free_bereq(struct bereq **bereq);
 void VBE_AddHostHeader(const struct sess *sp);
 void VBE_Poll(void);
 
index ee6eb207dbd0e0f2a8e111ea29b0dda72d78cd56..e691b5340cbbe34a1f9e36effaf0f76b83d6df55 100644 (file)
@@ -172,8 +172,13 @@ VBE_new_bereq(void)
  */
 
 void
-VBE_free_bereq(struct bereq *bereq)
+VBE_free_bereq(struct bereq **bereqp)
 {
+       struct bereq *bereq;
+
+       AN(bereqp);
+       bereq = *bereqp;
+       *bereqp = NULL;
 
        CHECK_OBJ_NOTNULL(bereq, BEREQ_MAGIC);
        WS_Reset(bereq->ws, NULL);
index 8a5a07c9b3ad1be82e838f871d7eed7721b3afd1..e16ecc3694486256e5dc1cdee38aff05487baafe 100644 (file)
@@ -177,8 +177,7 @@ cnt_deliver(struct sess *sp)
 
        RES_WriteObj(sp);
        AZ(sp->wrk->wfd);
-       HSH_Deref(sp->obj);
-       sp->obj = NULL;
+       HSH_Deref(&sp->obj);
        sp->step = STP_DONE;
        return (0);
 }
@@ -391,13 +390,9 @@ cnt_fetch(struct sess *sp)
        if (i) {
                sp->err_code = 503;
                sp->step = STP_ERROR;
-               VBE_free_bereq(sp->bereq);
-               sp->bereq = NULL;
-               sp->obj->ttl = 0;
-               sp->obj->cacheable = 0;
-               HSH_Unbusy(sp);
-               HSH_Deref(sp->obj);
-               sp->obj = NULL;
+               VBE_free_bereq(&sp->bereq);
+               HSH_Drop(sp);
+               AZ(sp->obj);
                return (0);
        }
 
@@ -406,16 +401,11 @@ cnt_fetch(struct sess *sp)
        sp->err_code = http_GetStatus(sp->obj->http);
        VCL_fetch_method(sp);
 
-       VBE_free_bereq(sp->bereq);
-       sp->bereq = NULL;
+       VBE_free_bereq(&sp->bereq);
 
        switch (sp->handling) {
        case VCL_RET_RESTART:
-               sp->obj->ttl = 0;
-               sp->obj->cacheable = 0;
-               HSH_Unbusy(sp);
-               HSH_Deref(sp->obj);
-               sp->obj = NULL;
+               HSH_Drop(sp);
                sp->director = NULL;
                sp->restarts++;
                sp->step = STP_RECV;
@@ -427,11 +417,7 @@ cnt_fetch(struct sess *sp)
                break;
        case VCL_RET_ERROR:
                sp->step = STP_ERROR;
-               sp->obj->ttl = 0;
-               sp->obj->cacheable = 0;
-               HSH_Unbusy(sp);
-               HSH_Deref(sp->obj);
-               sp->obj = NULL;
+               HSH_Drop(sp);
                return (0);
        default:
                WRONG("Illegal action in vcl_fetch{}");
@@ -535,8 +521,7 @@ cnt_hit(struct sess *sp)
        }
 
        /* Drop our object, we won't need it */
-       HSH_Deref(sp->obj);
-       sp->obj = NULL;
+       HSH_Deref(&sp->obj);
 
        switch(sp->handling) {
        case VCL_RET_PASS:
@@ -625,8 +610,7 @@ cnt_lookup(struct sess *sp)
        if (sp->obj->pass) {
                VSL_stats->cache_hitpass++;
                WSP(sp, SLT_HitPass, "%u", sp->obj->xid);
-               HSH_Deref(sp->obj);
-               sp->obj = NULL;
+               HSH_Deref(&sp->obj);
                sp->step = STP_PASS;
                return (0);
        }
@@ -670,24 +654,17 @@ cnt_miss(struct sess *sp)
 
        http_FilterHeader(sp, HTTPH_R_FETCH);
        VCL_miss_method(sp);
+       AZ(sp->obj->cacheable);
        switch(sp->handling) {
        case VCL_RET_ERROR:
-               sp->obj->cacheable = 0;
-               HSH_Unbusy(sp);
-               HSH_Deref(sp->obj);
-               sp->obj = NULL;
-               VBE_free_bereq(sp->bereq);
-               sp->bereq = NULL;
+               HSH_Drop(sp);
+               VBE_free_bereq(&sp->bereq);
                sp->step = STP_ERROR;
                return (0);
        case VCL_RET_PASS:
-               sp->obj->cacheable = 0;
-               HSH_Unbusy(sp);
-               HSH_Deref(sp->obj);
-               sp->obj = NULL;
+               HSH_Drop(sp);
+               VBE_free_bereq(&sp->bereq);
                sp->step = STP_PASS;
-               VBE_free_bereq(sp->bereq);
-               sp->bereq = NULL;
                return (0);
        case VCL_RET_FETCH:
                sp->step = STP_FETCH;
index 4fa9b067d464a145d32662845d7026b4efd4250b..458ba74ef12d92bd2e2f2bd50a6a3fd5de83230a 100644 (file)
@@ -337,7 +337,7 @@ exp_timer(void *arg)
                        VSL_stats->n_expired++;
                        Lck_Unlock(&exp_mtx);
                        del_objexp(o);
-                       HSH_Deref(o);
+                       HSH_Deref(&o);
                }
        }
 }
@@ -406,7 +406,7 @@ EXP_NukeOne(struct sess *sp)
        if (sp->handling == VCL_RET_DISCARD) {
                WSL(sp->wrk, SLT_ExpKill, 0, "%u LRU", o->xid);
                del_objexp(o);
-               HSH_Deref(o);
+               HSH_Deref(&o);
                return (1);
        }
 
index 83fbbda358a96f86827b2eef4d950c341d6e7cc8..7d90c5f1c488ca08a87152b7cc86c6eac233c93d 100644 (file)
@@ -322,7 +322,7 @@ Fetch(struct sess *sp)
        CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
        CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC);
        AN(sp->director);
-       assert(sp->obj->busy != 0);
+       AN(sp->obj->busy);
        w = sp->wrk;
        bereq = sp->bereq;
        hp = bereq->http;
index 083027fbdfb56e3349383f719f5b6f150f40d2de..9f49c4652f9b9fd40c8e61952d6457f1b9f4140e 100644 (file)
@@ -378,6 +378,22 @@ hsh_rush(struct objhead *oh)
        }
 }
 
+void
+HSH_Drop(struct sess *sp)
+{
+       struct object *o;
+
+       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+       o = sp->obj;
+       CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
+       assert(o->busy);
+       assert(o->refcnt > 0);
+       o->ttl = 0;
+       o->cacheable = 0;
+       HSH_Unbusy(sp);
+       HSH_Deref(&sp->obj);
+}
+
 void
 HSH_Unbusy(const struct sess *sp)
 {
@@ -411,7 +427,7 @@ HSH_Unbusy(const struct sess *sp)
        if (oh != NULL)
                Lck_Unlock(&oh->mtx);
        if (parent != NULL)
-               HSH_Deref(parent);
+               HSH_Deref(&parent);
 }
 
 void
@@ -429,11 +445,15 @@ HSH_Ref(struct object *o)
 }
 
 void
-HSH_Deref(struct object *o)
+HSH_Deref(struct object **oo)
 {
+       struct object *o;
        struct objhead *oh;
        unsigned r;
 
+       AN(oo);
+       o = *oo;
+       *oo = NULL;
        CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
        oh = o->objhead;
        if (oh != NULL) {
index 6be1dd1d4824c20b083c91b8795e141395474dbf..5ed25ff292cb29184f7d70d12184b0143070b061 100644 (file)
@@ -96,8 +96,7 @@ PipeSession(struct sess *sp)
                return;
        }
 
-       VBE_free_bereq(bereq);
-       bereq = NULL;
+       VBE_free_bereq(&bereq);
 
        sp->t_resp = TIM_real();
 
index 81dfcf1fdbef5bdee261514b26e76fb47afe850b..4ae04b5d59eb6b4ebfecc7fc9bfbcc4c9447d03e 100644 (file)
@@ -56,7 +56,8 @@ void HSH_Copy(const struct sess *sp, struct objhead *o);
 struct object *HSH_Lookup(struct sess *sp);
 void HSH_Unbusy(const struct sess *sp);
 void HSH_Ref(struct object *o);
-void HSH_Deref(struct object *o);
+void HSH_Deref(struct object **o);
+void HSH_Drop(struct sess *sp);
 double HSH_Grace(double g);
 void HSH_Init(void);
 void HSH_AddString(struct sess *sp, const char *str);