mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MEDIUM: threads/chunks: Transform trash chunks in thread-local variables
So, per-thread init/deinit functions are registered to allocate/release them.
This commit is contained in:
parent
ba39f23a9d
commit
6adad11283
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
#include <common/standard.h>
|
#include <common/standard.h>
|
||||||
|
#include <common/hathreads.h>
|
||||||
|
|
||||||
#include <types/freq_ctr.h>
|
#include <types/freq_ctr.h>
|
||||||
#include <types/listener.h>
|
#include <types/listener.h>
|
||||||
#include <types/proxy.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 actconn; /* # of active sessions */
|
||||||
extern int listeners;
|
extern int listeners;
|
||||||
extern int jobs; /* # of active jobs (listeners, sessions, open devices) */
|
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 int nb_oldpids; /* contains the number of old pids found */
|
||||||
extern const int zero;
|
extern const int zero;
|
||||||
extern const int one;
|
extern const int one;
|
||||||
|
17
src/chunk.c
17
src/chunk.c
@ -22,20 +22,20 @@
|
|||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
|
|
||||||
/* trash chunks used for various conversions */
|
/* trash chunks used for various conversions */
|
||||||
static struct chunk *trash_chunk;
|
static THREAD_LOCAL struct chunk *trash_chunk;
|
||||||
static struct chunk trash_chunk1;
|
static THREAD_LOCAL struct chunk trash_chunk1;
|
||||||
static struct chunk trash_chunk2;
|
static THREAD_LOCAL struct chunk trash_chunk2;
|
||||||
|
|
||||||
/* trash buffers used for various conversions */
|
/* trash buffers used for various conversions */
|
||||||
static int trash_size;
|
static int trash_size;
|
||||||
static char *trash_buf1;
|
static THREAD_LOCAL char *trash_buf1;
|
||||||
static char *trash_buf2;
|
static THREAD_LOCAL char *trash_buf2;
|
||||||
|
|
||||||
/* the trash pool for reentrant allocations */
|
/* the trash pool for reentrant allocations */
|
||||||
struct pool_head *pool2_trash = NULL;
|
struct pool_head *pool2_trash = NULL;
|
||||||
|
|
||||||
/* this is used to drain data, and as a temporary buffer for sprintf()... */
|
/* 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
|
* 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. */
|
/* Initialize the trash buffers. It returns 0 if an error occurred. */
|
||||||
int init_trash_buffers()
|
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);
|
chunk_init(&trash, my_realloc2(trash.str, global.tune.bufsize), global.tune.bufsize);
|
||||||
if (!trash.str || !alloc_trash_buffers(global.tune.bufsize))
|
if (!trash.str || !alloc_trash_buffers(global.tune.bufsize))
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user