r460 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Wed Jul 12 21:28:06 CEST 2006
Author: phk
Date: 2006-07-12 21:28:06 +0200 (Wed, 12 Jul 2006)
New Revision: 460
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/cache_expire.c
trunk/varnish-cache/bin/varnishd/cache_main.c
trunk/varnish-cache/bin/varnishd/cache_vcl.c
Log:
Move sessmtx to cache_vcl.c and call it vcl_mtx.
Clean up naming for consistency while here.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-07-12 15:07:42 UTC (rev 459)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-07-12 19:28:06 UTC (rev 460)
@@ -257,9 +257,6 @@
};
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 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 *);
Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2006-07-12 15:07:42 UTC (rev 459)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2006-07-12 19:28:06 UTC (rev 460)
@@ -522,9 +522,7 @@
{
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_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);
Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c 2006-07-12 15:07:42 UTC (rev 459)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2006-07-12 19:28:06 UTC (rev 460)
@@ -103,10 +103,10 @@
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));
Modified: trunk/varnish-cache/bin/varnishd/cache_main.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_main.c 2006-07-12 15:07:42 UTC (rev 459)
+++ trunk/varnish-cache/bin/varnishd/cache_main.c 2006-07-12 19:28:06 UTC (rev 460)
@@ -20,7 +20,6 @@
struct stevedore *stevedore;
-pthread_mutex_t sessmtx;
struct varnish_stats *VSL_stats;
/*--------------------------------------------------------------------*/
@@ -105,8 +104,9 @@
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();
Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vcl.c 2006-07-12 15:07:42 UTC (rev 459)
+++ trunk/varnish-cache/bin/varnishd/cache_vcl.c 2006-07-12 19:28:06 UTC (rev 460)
@@ -20,6 +20,7 @@
const char *name;
void *dlh;
struct VCL_conf *conf;
+ unsigned busy;
};
/*
@@ -30,36 +31,39 @@
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 @@
}
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 @@
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 @@
return (0);
}
+/*--------------------------------------------------------------------*/
+
void
cli_func_config_list(struct cli *cli, char **av __unused, void *priv __unused)
{
@@ -137,7 +143,7 @@
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 @@
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 @@
{
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 @@
#include "vcl_returns.h"
#undef VCL_MET_MAC
#undef VCL_RET_MAC
+
+/*--------------------------------------------------------------------*/
+
+void
+VCL_Init()
+{
+
+ AZ(pthread_mutex_init(&vcl_mtx, NULL));
+}
More information about the varnish-commit
mailing list