#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>
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;
#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
/* 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;