From 88ebd4050e93a6b4bce6eac8d0b90f7b818e1c21 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 19 Aug 2019 15:55:34 +0200 Subject: [PATCH] MINOR: trace: add allocation of buffer-sized trace buffers This will be needed so that we can implement protocol decoders which will have to emit their contents into such a buffer. --- include/proto/trace.h | 1 + src/trace.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/proto/trace.h b/include/proto/trace.h index 0838551e52..a299237962 100644 --- a/include/proto/trace.h +++ b/include/proto/trace.h @@ -32,6 +32,7 @@ #include extern struct list trace_sources; +extern THREAD_LOCAL struct buffer trace_buf; /* registers trace source . Modifies the list element! * The {start,pause,stop,report} events are not changed so the source may diff --git a/src/trace.c b/src/trace.c index 97bd1b541f..e77c3080eb 100644 --- a/src/trace.c +++ b/src/trace.c @@ -27,7 +27,24 @@ #include struct list trace_sources = LIST_HEAD_INIT(trace_sources); +THREAD_LOCAL struct buffer trace_buf = { }; +/* allocates the trace buffers. Returns 0 in case of failure. It is safe to + * call to call this function multiple times if the size changes. + */ +static int alloc_trace_buffers_per_thread() +{ + chunk_init(&trace_buf, my_realloc2(trace_buf.area, global.tune.bufsize), global.tune.bufsize); + return !!trash.area; +} + +static void free_trace_buffers_per_thread() +{ + chunk_destroy(&trace_buf); +} + +REGISTER_PER_THREAD_ALLOC(alloc_trace_buffers_per_thread); +REGISTER_PER_THREAD_FREE(free_trace_buffers_per_thread); /* * Local variables: * c-indent-level: 8 -- 2.39.5