MINOR: initcall: use initcalls for most post_{check,deinit} and per_thread*

Most calls to hap_register_post_check(), hap_register_post_deinit(),
hap_register_per_thread_init(), hap_register_per_thread_deinit() can
be done using initcalls and will not require a constructor anymore.
Let's create a set of simplified macros for this, called respectively
REGISTER_POST_CHECK, REGISTER_POST_DEINIT, REGISTER_PER_THREAD_INIT,
and REGISTER_PER_THREAD_DEINIT.

Some files were not modified because they wouldn't benefit from this
or because they conditionally register (e.g. the pollers).
This commit is contained in:
Willy Tarreau 2018-11-26 11:21:50 +01:00
parent 8071338c78
commit 172f5ce948
12 changed files with 43 additions and 41 deletions

View File

@ -251,6 +251,22 @@ void mworker_accept_wrapper(int fd);
#define REGISTER_BUILD_OPTS(str) \
INITCALL2(STG_REGISTER, hap_register_build_opts, (str), 0)
/* simplified way to declare a post-check callback in a file */
#define REGISTER_POST_CHECK(fct) \
INITCALL1(STG_REGISTER, hap_register_post_check, (fct))
/* simplified way to declare a post-deinit callback in a file */
#define REGISTER_POST_DEINIT(fct) \
INITCALL1(STG_REGISTER, hap_register_post_deinit, (fct))
/* simplified way to declare a per-thread init callback in a file */
#define REGISTER_PER_THREAD_INIT(fct) \
INITCALL1(STG_REGISTER, hap_register_per_thread_init, (fct))
/* simplified way to declare a per-thread deinit callback in a file */
#define REGISTER_PER_THREAD_DEINIT(fct) \
INITCALL1(STG_REGISTER, hap_register_per_thread_deinit, (fct))
#endif /* _TYPES_GLOBAL_H */
/*

View File

@ -687,11 +687,6 @@ static struct sample_conv_kw_list conv_kws = {ILH, {
INITCALL1(STG_REGISTER, sample_register_convs, &conv_kws);
__attribute__((constructor))
static void __51d_init(void)
{
hap_register_post_check(init_51degrees);
hap_register_post_deinit(deinit_51degrees);
}
REGISTER_POST_CHECK(init_51degrees);
REGISTER_POST_DEINIT(deinit_51degrees);
REGISTER_BUILD_OPTS("Built with 51Degrees support.");

View File

@ -3517,12 +3517,11 @@ int srv_check_healthcheck_port(struct check *chk)
__attribute__((constructor))
static void __check_init(void)
{
hap_register_post_check(start_checks);
pool_head_email_alert = create_pool("email_alert", sizeof(struct email_alert), MEM_F_SHARED);
pool_head_tcpcheck_rule = create_pool("tcpcheck_rule", sizeof(struct tcpcheck_rule), MEM_F_SHARED);
}
REGISTER_POST_CHECK(start_checks);
/*
* Local variables:

View File

@ -92,10 +92,6 @@ static void deinit_trash_buffers_per_thread()
/* Initialize the trash buffers. It returns 0 if an error occurred. */
int init_trash_buffers(int first)
{
if (!first) {
hap_register_per_thread_init(init_trash_buffers_per_thread);
hap_register_per_thread_deinit(deinit_trash_buffers_per_thread);
}
pool_destroy(pool_head_trash);
pool_head_trash = create_pool("trash",
sizeof(struct buffer) + global.tune.bufsize,
@ -320,6 +316,9 @@ int chunk_strcasecmp(const struct buffer *chk, const char *str)
return diff;
}
REGISTER_PER_THREAD_INIT(init_trash_buffers_per_thread);
REGISTER_PER_THREAD_DEINIT(deinit_trash_buffers_per_thread);
/*
* Local variables:
* c-indent-level: 8

View File

@ -396,11 +396,6 @@ static struct sample_conv_kw_list conv_kws = {ILH, {
INITCALL1(STG_REGISTER, sample_register_convs, &conv_kws);
__attribute__((constructor))
static void __da_init(void)
{
hap_register_post_check(init_deviceatlas);
hap_register_post_deinit(deinit_deviceatlas);
}
REGISTER_POST_CHECK(init_deviceatlas);
REGISTER_POST_DEINIT(deinit_deviceatlas);
REGISTER_BUILD_OPTS("Built with DeviceAtlas support.");

View File

@ -2060,5 +2060,6 @@ static void __dns_init(void)
dns_resolution_pool = create_pool("dns_resolution", sizeof(struct dns_resolution), MEM_F_SHARED);
cfg_register_postparser("dns runtime resolver", dns_finalize_config);
hap_register_post_deinit(dns_deinit);
}
REGISTER_POST_DEINIT(dns_deinit);

View File

@ -526,8 +526,6 @@ int init_pollers()
fd_cache.first = fd_cache.last = -1;
update_list.first = update_list.last = -1;
hap_register_per_thread_init(init_pollers_per_thread);
hap_register_per_thread_deinit(deinit_pollers_per_thread);
for (p = 0; p < global.maxsock; p++) {
HA_SPIN_INIT(&fdtab[p].lock);
@ -667,6 +665,9 @@ int fork_poller()
return 1;
}
REGISTER_PER_THREAD_INIT(init_pollers_per_thread);
REGISTER_PER_THREAD_DEINIT(deinit_pollers_per_thread);
/*
* Local variables:
* c-indent-level: 8

View File

@ -1197,9 +1197,6 @@ static void
__filters_init(void)
{
pool_head_filter = create_pool("filter", sizeof(struct filter), MEM_F_SHARED);
hap_register_post_check(flt_init_all);
hap_register_per_thread_init(flt_init_all_per_thread);
hap_register_per_thread_deinit(flt_deinit_all_per_thread);
}
__attribute__((destructor))
@ -1209,6 +1206,10 @@ __filters_deinit(void)
pool_destroy(pool_head_filter);
}
REGISTER_POST_CHECK(flt_init_all);
REGISTER_PER_THREAD_INIT(flt_init_all_per_thread);
REGISTER_PER_THREAD_DEINIT(flt_deinit_all_per_thread);
/*
* Local variables:
* c-indent-level: 8

View File

@ -2809,12 +2809,9 @@ static struct cli_kw_list cli_kws = {{ },{
INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
__attribute__((constructor))
static void __log_init(void)
{
hap_register_per_thread_init(init_log_buffers_per_thread);
hap_register_per_thread_deinit(deinit_log_buffers_per_thread);
}
REGISTER_PER_THREAD_INIT(init_log_buffers_per_thread);
REGISTER_PER_THREAD_DEINIT(deinit_log_buffers_per_thread);
/*
* Local variables:
* c-indent-level: 8

View File

@ -1835,10 +1835,12 @@ static void __h1_deinit(void)
__attribute__((constructor))
static void __h1_init(void)
{
hap_register_post_deinit(__h1_deinit);
pool_head_h1c = create_pool("h1c", sizeof(struct h1c), MEM_F_SHARED);
pool_head_h1s = create_pool("h1s", sizeof(struct h1s), MEM_F_SHARED);
}
REGISTER_POST_DEINIT(__h1_deinit);
/*
* Local variables:
* c-indent-level: 8

View File

@ -3854,7 +3854,8 @@ static void __h2_deinit(void)
__attribute__((constructor))
static void __h2_init(void)
{
hap_register_post_deinit(__h2_deinit);
pool_head_h2c = create_pool("h2c", sizeof(struct h2c), MEM_F_SHARED);
pool_head_h2s = create_pool("h2s", sizeof(struct h2s), MEM_F_SHARED);
}
REGISTER_POST_DEINIT(__h2_deinit);

View File

@ -691,13 +691,6 @@ static struct sample_conv_kw_list conv_kws = {ILH, {
INITCALL1(STG_REGISTER, sample_register_convs, &conv_kws);
__attribute__((constructor))
static void __wurfl_init(void)
{
hap_register_post_check(ha_wurfl_init);
hap_register_post_deinit(ha_wurfl_deinit);
}
// WURFL properties wrapper functions
static const char *ha_wurfl_get_wurfl_root_id (wurfl_handle wHandle, wurfl_device_handle dHandle)
{
@ -802,4 +795,6 @@ static const char *ha_wurfl_retrieve_header(const char *header_name, const void
return ((ha_wurfl_header_t *)wh)->header_value;
}
REGISTER_POST_CHECK(ha_wurfl_init);
REGISTER_POST_DEINIT(ha_wurfl_deinit);
REGISTER_BUILD_OPTS("Built with WURFL support.");