From: Christopher Faulet Date: Fri, 21 Apr 2017 14:47:03 +0000 (+0200) Subject: MEDIUM: threads/chunks: Transform trash chunks in thread-local variables X-Git-Tag: v1.8-rc1~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6adad11283458f7dafc0b52008840b788072eac6;p=thirdparty%2Fhaproxy.git MEDIUM: threads/chunks: Transform trash chunks in thread-local variables So, per-thread init/deinit functions are registered to allocate/release them. --- diff --git a/include/types/global.h b/include/types/global.h index 1b2148bf90..817c09ba69 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -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; diff --git a/src/chunk.c b/src/chunk.c index e99535a438..1fdcebb038 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -22,20 +22,20 @@ #include /* 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;