]> err.no Git - varnish/commitdiff
Store the current session in thread private data.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 20 Jul 2008 09:57:25 +0000 (09:57 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 20 Jul 2008 09:57:25 +0000 (09:57 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2969 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_main.c
varnish-cache/bin/varnishd/cache_pool.c

index b5a0901d3ecb4847f4e9f3b0279002802b028abd..7119095a41b91d7b8536081ce09b0774b4396b77 100644 (file)
@@ -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
index 533ae20f20ca1905e8e3a0ddadc6924ed565d629..19446bd8ce5de16d99c13eefc775f0d6c8c7e8d3 100644 (file)
 #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();
index ea09dbfc641476df77d8ebcd94ed29e3ecf27a2e..3b21ae8bc30e54c7949d395972128d141abcfcec 100644 (file)
@@ -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);
 }
 
 /*--------------------------------------------------------------------*/