mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MINOR: threads: Add mechanism to register per-thread init/deinit functions
hap_register_per_thread_init and hap_register_per_thread_deinit functions has been added to register functions to do, for each thread, respectively, some initialization and deinitialization. These functions are added in the global lists per_thread_init_list and per_thread_deinit_list. These functions are called only when HAProxy is started with more than 1 thread (global.nbthread > 1).
This commit is contained in:
parent
1a2b56ea8e
commit
415f611ff4
@ -206,6 +206,9 @@ void hap_register_build_opts(const char *str, int must_free);
|
||||
void hap_register_post_check(int (*fct)());
|
||||
void hap_register_post_deinit(void (*fct)());
|
||||
|
||||
void hap_register_per_thread_init(int (*fct)());
|
||||
void hap_register_per_thread_deinit(void (*fct)());
|
||||
|
||||
#endif /* _TYPES_GLOBAL_H */
|
||||
|
||||
/*
|
||||
|
@ -244,6 +244,25 @@ struct post_deinit_fct {
|
||||
void (*fct)();
|
||||
};
|
||||
|
||||
/* These functions are called for each thread just after the thread creation
|
||||
* and before running the scheduler. They should be used to do per-thread
|
||||
* initializations. They must return 0 if an error occurred. */
|
||||
struct list per_thread_init_list = LIST_HEAD_INIT(per_thread_init_list);
|
||||
struct per_thread_init_fct {
|
||||
struct list list;
|
||||
int (*fct)();
|
||||
};
|
||||
|
||||
/* These functions are called for each thread just after the scheduler loop and
|
||||
* before exiting the thread. They don't return anything and, as for post-deinit
|
||||
* functions, they work in best effort mode as their sole goal is to make
|
||||
* valgrind mostly happy. */
|
||||
struct list per_thread_deinit_list = LIST_HEAD_INIT(per_thread_deinit_list);
|
||||
struct per_thread_deinit_fct {
|
||||
struct list list;
|
||||
void (*fct)();
|
||||
};
|
||||
|
||||
/*********************************************************************/
|
||||
/* general purpose functions ***************************************/
|
||||
/*********************************************************************/
|
||||
@ -295,6 +314,34 @@ void hap_register_post_deinit(void (*fct)())
|
||||
LIST_ADDQ(&post_deinit_list, &b->list);
|
||||
}
|
||||
|
||||
/* used to register some initialization functions to call for each thread. */
|
||||
void hap_register_per_thread_init(int (*fct)())
|
||||
{
|
||||
struct per_thread_init_fct *b;
|
||||
|
||||
b = calloc(1, sizeof(*b));
|
||||
if (!b) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
b->fct = fct;
|
||||
LIST_ADDQ(&per_thread_init_list, &b->list);
|
||||
}
|
||||
|
||||
/* used to register some de-initialization functions to call for each thread. */
|
||||
void hap_register_per_thread_deinit(void (*fct)())
|
||||
{
|
||||
struct per_thread_deinit_fct *b;
|
||||
|
||||
b = calloc(1, sizeof(*b));
|
||||
if (!b) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
b->fct = fct;
|
||||
LIST_ADDQ(&per_thread_deinit_list, &b->list);
|
||||
}
|
||||
|
||||
static void display_version()
|
||||
{
|
||||
printf("HA-Proxy version " HAPROXY_VERSION " " HAPROXY_DATE"\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user