]> err.no Git - varnish/commitdiff
Move sessmtx to cache_vcl.c and call it vcl_mtx.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 12 Jul 2006 19:28:06 +0000 (19:28 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 12 Jul 2006 19:28:06 +0000 (19:28 +0000)
Clean up naming for consistency while here.

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

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/cache_expire.c
varnish-cache/bin/varnishd/cache_main.c
varnish-cache/bin/varnishd/cache_vcl.c

index 41e3a76b4155dcfb90d0fa7f4f63b318b6c453f8..2de78ad7cb555c794cf31186fc4cf3a439595edc 100644 (file)
@@ -257,9 +257,6 @@ enum http_build {
 };
 void http_BuildSbuf(int fd, enum http_build mode, struct sbuf *sb, struct http *hp);
 
-/* cache_main.c */
-extern pthread_mutex_t sessmtx;
-
 /* cache_pass.c */
 void PassSession(struct worker *w, struct sess *sp);
 void PassBody(struct worker *w, struct sess *sp);
@@ -288,9 +285,10 @@ void VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...);
 void RES_Error(struct worker *w, struct sess *sp, int error, const char *msg);
 
 /* cache_vcl.c */
-void RelVCL(struct VCL_conf *vc);
-struct VCL_conf *GetVCL(void);
-int CVCL_Load(const char *fn, const char *name, struct cli *cli);
+void VCL_Init(void);
+void VCL_Rel(struct VCL_conf *vc);
+struct VCL_conf *VCL_Get(void);
+int VCL_Load(const char *fn, const char *name, struct cli *cli);
 
 #define VCL_RET_MAC(l,u,b)
 #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *);
index 2895b91f68eb25eb2a932f440f16930705a90c15..7f8ad30ddcdf738e99d803be65eac0ace9d768a3 100644 (file)
@@ -522,9 +522,7 @@ CNT_Session(struct worker *w, struct sess *sp)
 {
 
        time(&sp->t0);
-       AZ(pthread_mutex_lock(&sessmtx));
-       sp->vcl = GetVCL();
-       AZ(pthread_mutex_unlock(&sessmtx));
+       sp->vcl = VCL_Get();
 
        for (sp->step = STP_RECV; sp->step != STP_DONE; ) {
                switch (sp->step) {
@@ -541,9 +539,7 @@ CNT_Session(struct worker *w, struct sess *sp)
 
        cnt_done(w, sp);        /* The loop doesn't do this */
 
-       AZ(pthread_mutex_lock(&sessmtx));
-       RelVCL(sp->vcl);
-       AZ(pthread_mutex_unlock(&sessmtx));
+       VCL_Rel(sp->vcl);
        sp->vcl = NULL;
 
        vca_return_session(sp);
index 6a8ac73f1ff892acefc214d28cca2cc2dd24b126..c355e1cfe4b8cba170b066ca5b395ae32c4ff183 100644 (file)
@@ -103,10 +103,10 @@ exp_prefetch(void *arg __unused)
                AZ(pthread_mutex_unlock(&exp_mtx));
                VSL(SLT_ExpPick, 0, "%u", o->xid);
 
-               sp.vcl = GetVCL();
+               sp.vcl = VCL_Get();
                sp.obj = o;
                VCL_timeout_method(&sp);
-               RelVCL(sp.vcl);
+               VCL_Rel(sp.vcl);
 
                if (sp.handling == VCL_RET_DISCARD) {
                        AZ(pthread_mutex_lock(&exp_mtx));
index 2701d6db121e18d0a09831a646c402cb2e86963a..4de75ded98f3f440fbf473235b13980c9c3ff397 100644 (file)
@@ -20,7 +20,6 @@ static struct event ev_keepalive;
 
 struct stevedore       *stevedore;
 
-pthread_mutex_t        sessmtx;
 struct varnish_stats *VSL_stats;
 
 /*--------------------------------------------------------------------*/
@@ -105,8 +104,9 @@ child_main(void)
        setbuf(stderr, NULL);
        printf("Child starts\n");
 
-       CVCL_Load(heritage.vcl_file, "boot", NULL);
-       AZ(pthread_mutex_init(&sessmtx, NULL));
+       VCL_Init();
+       VCL_Load(heritage.vcl_file, "boot", NULL);
+
        VBE_Init();
        VSL_Init();
        WRK_Init();
index b1bd2a625578b22afd6b0500de898450721c67ab..00ef97f0451f2e9d8966e36b041de88324dd854a 100644 (file)
@@ -20,6 +20,7 @@ struct vcls {
        const char              *name;
        void                    *dlh;
        struct VCL_conf         *conf;
+       unsigned                busy;
 };
 
 /*
@@ -30,36 +31,39 @@ static TAILQ_HEAD(, vcls)   vcl_head =
     TAILQ_HEAD_INITIALIZER(vcl_head);
 
 
-static struct vcls             *active_vcl; /* protected by sessmtx */
+static struct vcls             *vcl_active; /* protected by vcl_mtx */
 
+static pthread_mutex_t         vcl_mtx;
 
 /*--------------------------------------------------------------------*/
 
 struct VCL_conf *
-GetVCL(void)
+VCL_Get(void)
 {
        struct VCL_conf *vc;
 
-       /* XXX: assert sessmtx (procects active_vcl && ->busy) */
-       assert(active_vcl != NULL);
-       vc = active_vcl->conf;
+       AZ(pthread_mutex_lock(&vcl_mtx));
+       assert(vcl_active != NULL);
+       vc = vcl_active->conf;
        assert(vc != NULL);
        vc->busy++;
+       AZ(pthread_mutex_unlock(&vcl_mtx));
        return (vc);
 }
 
 void
-RelVCL(struct VCL_conf *vc)
+VCL_Rel(struct VCL_conf *vc)
 {
 
-       /* XXX: assert sessmtx (procects ->busy) */
+       AZ(pthread_mutex_lock(&vcl_mtx));
        vc->busy--;
+       AZ(pthread_mutex_unlock(&vcl_mtx));
 }
 
 /*--------------------------------------------------------------------*/
 
 static struct vcls *
-find_vcls(const char *name)
+vcl_find(const char *name)
 {
        struct vcls *vcl;
 
@@ -70,11 +74,11 @@ find_vcls(const char *name)
 }
 
 int
-CVCL_Load(const char *fn, const char *name, struct cli *cli)
+VCL_Load(const char *fn, const char *name, struct cli *cli)
 {
        struct vcls *vcl;
 
-       vcl = find_vcls(name);
+       vcl = vcl_find(name);
        if (vcl != NULL) {
                if (cli == NULL)
                        fprintf(stderr, "Config '%s' already loaded", name);
@@ -118,10 +122,10 @@ CVCL_Load(const char *fn, const char *name, struct cli *cli)
        vcl->name = strdup(name);
        assert(vcl->name != NULL);
        TAILQ_INSERT_TAIL(&vcl_head, vcl, list);
-       AZ(pthread_mutex_lock(&sessmtx));
-       if (active_vcl == NULL)
-               active_vcl = vcl;
-       AZ(pthread_mutex_unlock(&sessmtx));
+       AZ(pthread_mutex_lock(&vcl_mtx));
+       if (vcl_active == NULL)
+               vcl_active = vcl;
+       AZ(pthread_mutex_unlock(&vcl_mtx));
        if (cli == NULL)
                fprintf(stderr, "Loaded \"%s\" as \"%s\"\n", fn , name);
        else 
@@ -130,6 +134,8 @@ CVCL_Load(const char *fn, const char *name, struct cli *cli)
        return (0);
 }
 
+/*--------------------------------------------------------------------*/
+
 void
 cli_func_config_list(struct cli *cli, char **av __unused, void *priv __unused)
 {
@@ -137,7 +143,7 @@ cli_func_config_list(struct cli *cli, char **av __unused, void *priv __unused)
 
        TAILQ_FOREACH(vcl, &vcl_head, list) {
                cli_out(cli, "%s %6u %s\n",
-                   vcl == active_vcl ? "* " : "  ",
+                   vcl == vcl_active ? "* " : "  ",
                    vcl->conf->busy,
                    vcl->name);
        }
@@ -147,7 +153,7 @@ void
 cli_func_config_load(struct cli *cli, char **av, void *priv __unused)
 {
 
-       if (CVCL_Load(av[3], av[2], cli))
+       if (VCL_Load(av[3], av[2], cli))
                cli_result(cli, CLIS_PARAM);
        return;
 }
@@ -163,11 +169,11 @@ cli_func_config_use(struct cli *cli, char **av, void *priv __unused)
 {
        struct vcls *vcl;
 
-       vcl = find_vcls(av[2]);
+       vcl = vcl_find(av[2]);
        if (vcl != NULL) {
-               AZ(pthread_mutex_lock(&sessmtx));
-               active_vcl = vcl;
-               AZ(pthread_mutex_unlock(&sessmtx));
+               AZ(pthread_mutex_lock(&vcl_mtx));
+               vcl_active = vcl;
+               AZ(pthread_mutex_unlock(&vcl_mtx));
        } else {
                cli_out(cli, "No config named '%s' loaded", av[2]);
                cli_result(cli, CLIS_PARAM);
@@ -224,3 +230,12 @@ VCL_##func##_method(struct sess *sp)               \
 #include "vcl_returns.h"
 #undef VCL_MET_MAC
 #undef VCL_RET_MAC
+
+/*--------------------------------------------------------------------*/
+
+void
+VCL_Init()
+{
+
+       AZ(pthread_mutex_init(&vcl_mtx, NULL));
+}