]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: threads/chunks: Transform trash chunks in thread-local variables
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 21 Apr 2017 14:47:03 +0000 (16:47 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 12:58:30 +0000 (13:58 +0100)
So, per-thread init/deinit functions are registered to allocate/release them.

include/types/global.h
src/chunk.c

index 1b2148bf90204d69e9baa75144f303af418ad04a..817c09ba69b5f229b2de64cd756724d58eb2a0b4 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <common/config.h>
 #include <common/standard.h>
+#include <common/hathreads.h>
+
 #include <types/freq_ctr.h>
 #include <types/listener.h>
 #include <types/proxy.h>
@@ -172,7 +174,7 @@ extern int  relative_pid;       /* process id starting at 1 */
 extern int  actconn;            /* # of active sessions */
 extern int  listeners;
 extern int  jobs;               /* # of active jobs (listeners, sessions, open devices) */
-extern struct chunk trash;
+extern THREAD_LOCAL struct chunk trash;
 extern int nb_oldpids;          /* contains the number of old pids found */
 extern const int zero;
 extern const int one;
index e99535a438293a6ef2d443ec81431814d3b6c730..1fdcebb0389f0092b40eeea0efe2148e9c962b4a 100644 (file)
 #include <types/global.h>
 
 /* trash chunks used for various conversions */
-static struct chunk *trash_chunk;
-static struct chunk trash_chunk1;
-static struct chunk trash_chunk2;
+static THREAD_LOCAL struct chunk *trash_chunk;
+static THREAD_LOCAL struct chunk trash_chunk1;
+static THREAD_LOCAL struct chunk trash_chunk2;
 
 /* trash buffers used for various conversions */
 static int trash_size;
-static char *trash_buf1;
-static char *trash_buf2;
+static THREAD_LOCAL char *trash_buf1;
+static THREAD_LOCAL char *trash_buf2;
 
 /* the trash pool for reentrant allocations */
 struct pool_head *pool2_trash = NULL;
 
 /* this is used to drain data, and as a temporary buffer for sprintf()... */
-struct chunk trash = { .str = NULL };
+THREAD_LOCAL struct chunk trash = { .str = NULL };
 
 /*
 * Returns a pre-allocated and initialized trash chunk that can be used for any
@@ -78,6 +78,11 @@ static int alloc_trash_buffers(int bufsize)
 /* Initialize the trash buffers. It returns 0 if an error occurred. */
 int init_trash_buffers()
 {
+       if (global.nbthread > 1 && tid == (unsigned int)(-1)) {
+               hap_register_per_thread_init(init_trash_buffers);
+               hap_register_per_thread_deinit(deinit_trash_buffers);
+       }
+
        chunk_init(&trash, my_realloc2(trash.str, global.tune.bufsize), global.tune.bufsize);
        if (!trash.str || !alloc_trash_buffers(global.tune.bufsize))
                return 0;