From: phk Date: Sun, 20 Jul 2008 09:57:25 +0000 (+0000) Subject: Store the current session in thread private data. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99bed161d2880ad774db3d501799155bd59bd153;p=varnish Store the current session in thread private data. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2969 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index b5a0901d..7119095a 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -511,6 +511,8 @@ int HTC_Complete(struct http_conn *htc); /* cache_main.c */ void THR_Name(const char *name); +void THR_SetSession(const struct sess *sp); +const struct sess * THR_GetSession(void); /* cache_pipe.c */ void PipeSession(struct sess *sp); @@ -708,8 +710,6 @@ Tadd(txt *t, const char *p, int l) #ifdef WITHOUT_ASSERTS #define spassert(cond) ((void)(cond)) -#define SPAZ(val) ((void)(val) == 0) -#define SPAN(val) ((void)(val) != 0) #else void panic(const char *, int, const char *, const struct sess *, const char *, ...); @@ -720,6 +720,6 @@ void panic(const char *, int, const char *, panic(__FILE__, __LINE__, __func__, sp, \ "assertion failed: %s\n", #cond); \ } while (0) +#endif #define SPAZ(val) spassert((val) == 0) #define SPAN(val) spassert((val) != 0) -#endif diff --git a/varnish-cache/bin/varnishd/cache_main.c b/varnish-cache/bin/varnishd/cache_main.c index 533ae20f..19446bd8 100644 --- a/varnish-cache/bin/varnishd/cache_main.c +++ b/varnish-cache/bin/varnishd/cache_main.c @@ -40,6 +40,27 @@ #include "cache.h" #include "stevedore.h" +/*-------------------------------------------------------------------- + * Per thread storage for the session currently being processed by + * the thread. This is used for panic messages. + */ + +static pthread_key_t sp_key; + +void +THR_SetSession(const struct sess *sp) +{ + + AZ(pthread_setspecific(sp_key, sp)); +} + +const struct sess * +THR_GetSession(void) +{ + + return (pthread_getspecific(sp_key)); +} + /*-------------------------------------------------------------------- * Name threads if our pthreads implementation supports it. */ @@ -69,6 +90,8 @@ child_main(void) setbuf(stderr, NULL); printf("Child starts\n"); + AZ(pthread_key_create(&sp_key, NULL)); + THR_Name("cache-main"); CLI_Init(); diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index ea09dbfc..3b21ae8b 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -323,6 +323,7 @@ wrk_do_cnt_sess(struct worker *w, void *priv) struct sess *sess; CAST_OBJ_NOTNULL(sess, priv, SESS_MAGIC); + THR_SetSession(sess); sess->wrk = w; CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC); CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC); @@ -331,6 +332,7 @@ wrk_do_cnt_sess(struct worker *w, void *priv) assert(!isnan(w->used)); CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC); CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC); + THR_SetSession(NULL); } /*--------------------------------------------------------------------*/