Commit bafb3c3f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Hold a mutex for each log destination



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2774 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 5b0a1987
...@@ -49,6 +49,7 @@ struct vtclog { ...@@ -49,6 +49,7 @@ struct vtclog {
#define VTCLOG_MAGIC 0x82731202 #define VTCLOG_MAGIC 0x82731202
const char *id; const char *id;
struct vsb *vsb; struct vsb *vsb;
pthread_mutex_t mtx;
}; };
struct vtclog * struct vtclog *
...@@ -60,6 +61,7 @@ vtc_logopen(const char *id) ...@@ -60,6 +61,7 @@ vtc_logopen(const char *id)
AN(vl); AN(vl);
vl->id = id; vl->id = id;
vl->vsb = vsb_newauto(); vl->vsb = vsb_newauto();
AZ(pthread_mutex_init(&vl->mtx, NULL));
return (vl); return (vl);
} }
...@@ -80,6 +82,7 @@ vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...) ...@@ -80,6 +82,7 @@ vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...)
assert(lvl < NLEAD); assert(lvl < NLEAD);
if (lvl > vtc_verbosity) if (lvl > vtc_verbosity)
return; return;
AZ(pthread_mutex_lock(&vl->mtx));
vsb_printf(vl->vsb, "%s %-4s ", lead[lvl], vl->id); vsb_printf(vl->vsb, "%s %-4s ", lead[lvl], vl->id);
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
...@@ -90,6 +93,7 @@ vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...) ...@@ -90,6 +93,7 @@ vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...)
AZ(vsb_overflowed(vl->vsb)); AZ(vsb_overflowed(vl->vsb));
(void)fputs(vsb_data(vl->vsb), stdout); (void)fputs(vsb_data(vl->vsb), stdout);
vsb_clear(vl->vsb); vsb_clear(vl->vsb);
AZ(pthread_mutex_unlock(&vl->mtx));
if (lvl == 0) if (lvl == 0)
exit (1); exit (1);
} }
...@@ -108,6 +112,7 @@ vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, const char *str) ...@@ -108,6 +112,7 @@ vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, const char *str)
return; return;
if (pfx == NULL) if (pfx == NULL)
pfx = ""; pfx = "";
AZ(pthread_mutex_lock(&vl->mtx));
if (str == NULL) if (str == NULL)
vsb_printf(vl->vsb, "%s %-4s %s(null)\n", vsb_printf(vl->vsb, "%s %-4s %s(null)\n",
lead[lvl], vl->id, pfx); lead[lvl], vl->id, pfx);
...@@ -136,6 +141,7 @@ vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, const char *str) ...@@ -136,6 +141,7 @@ vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, const char *str)
AZ(vsb_overflowed(vl->vsb)); AZ(vsb_overflowed(vl->vsb));
(void)fputs(vsb_data(vl->vsb), stdout); (void)fputs(vsb_data(vl->vsb), stdout);
vsb_clear(vl->vsb); vsb_clear(vl->vsb);
AZ(pthread_mutex_unlock(&vl->mtx));
if (lvl == 0) if (lvl == 0)
exit (1); exit (1);
} }
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