From 172f5ce9485cddd2619fa6b87d8b4015812b9fd7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 26 Nov 2018 11:21:50 +0100 Subject: [PATCH] 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). --- include/types/global.h | 16 ++++++++++++++++ src/51d.c | 9 ++------- src/checks.c | 3 +-- src/chunk.c | 7 +++---- src/da.c | 9 ++------- src/dns.c | 3 ++- src/fd.c | 5 +++-- src/filters.c | 7 ++++--- src/log.c | 9 +++------ src/mux_h1.c | 4 +++- src/mux_h2.c | 3 ++- src/wurfl.c | 9 ++------- 12 files changed, 43 insertions(+), 41 deletions(-) diff --git a/include/types/global.h b/include/types/global.h index 85f5d25c0..74ebf14e9 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -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 */ /* diff --git a/src/51d.c b/src/51d.c index d709ec0e7..2a9786771 100644 --- a/src/51d.c +++ b/src/51d.c @@ -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."); diff --git a/src/checks.c b/src/checks.c index 53950932d..55efb8066 100644 --- a/src/checks.c +++ b/src/checks.c @@ -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: diff --git a/src/chunk.c b/src/chunk.c index 303d3fdc9..fa3fb71df 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -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 diff --git a/src/da.c b/src/da.c index ee3d9af5d..61d6422e9 100644 --- a/src/da.c +++ b/src/da.c @@ -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."); diff --git a/src/dns.c b/src/dns.c index 2dfbdd587..255f15a96 100644 --- a/src/dns.c +++ b/src/dns.c @@ -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); diff --git a/src/fd.c b/src/fd.c index c46748986..a787a0957 100644 --- a/src/fd.c +++ b/src/fd.c @@ -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 diff --git a/src/filters.c b/src/filters.c index edce60380..1c4725604 100644 --- a/src/filters.c +++ b/src/filters.c @@ -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 diff --git a/src/log.c b/src/log.c index 5c6b8dfa9..77d58e2fe 100644 --- a/src/log.c +++ b/src/log.c @@ -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 diff --git a/src/mux_h1.c b/src/mux_h1.c index c9bfaa392..252395f09 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -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 diff --git a/src/mux_h2.c b/src/mux_h2.c index c3cd1e12d..e4005a2c3 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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); diff --git a/src/wurfl.c b/src/wurfl.c index cd6abef36..75dcf0045 100644 --- a/src/wurfl.c +++ b/src/wurfl.c @@ -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.");