Commit 3c177933 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Store the current session in thread private data.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2969 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent fc84f4a8
......@@ -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
......@@ -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();
......
......@@ -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);
}
/*--------------------------------------------------------------------*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment