]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: initcall: use initcalls for most post_{check,deinit} and per_thread*
authorWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 10:21:50 +0000 (11:21 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 18:50:32 +0000 (19:50 +0100)
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).

12 files changed:
include/types/global.h
src/51d.c
src/checks.c
src/chunk.c
src/da.c
src/dns.c
src/fd.c
src/filters.c
src/log.c
src/mux_h1.c
src/mux_h2.c
src/wurfl.c

index 85f5d25c02a3bda50d7ad2bda2f467b514c37b72..74ebf14e96045637ae43712348caf7496e2dffbc 100644 (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 */
 
 /*
index d709ec0e7c2db4ed050f78567940796cec18e062..2a97867712177018e60bde1d81dae9448e4124db 100644 (file)
--- 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.");
index 53950932d27b4ae595252e83b511aafbdf6f92df..55efb8066598969236b604b7b77896d30b3207b4 100644 (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:
index 303d3fdc9575313b02102c4f356dd37cb34cd243..fa3fb71dfa2953c589b43245330b6fad4a80dac8 100644 (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
index ee3d9af5d9ec1c5489612ddfb4484def10574c0d..61d6422e96bc84ec296671d1e9972bb083b4830c 100644 (file)
--- 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.");
index 2dfbdd58782dc430e930879fef4cfc92dd5fc739..255f15a96cf5be19e32557c87c8f5ead81032283 100644 (file)
--- 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);
index c467489861e9ef734e5ce3443b9e1496fd981cf3..a787a0957b9df5004fda550cb7778f2322e90598 100644 (file)
--- 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
index edce6038032eb74920480f08cee261fea74d64b5..1c47256040b47a6d0b860846e392b083606ad617 100644 (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
index 5c6b8dfa9838f1891f0ca090ab3193f16e0d9c83..77d58e2fee10effdde4201247f34408747c683f7 100644 (file)
--- 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
index c9bfaa3921033a85d1504a4ddee842e438c7106b..252395f09defab6175251503d80cfb0ee80c9152 100644 (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
index c3cd1e12d5258510b67ca0071a7b820f4050d957..e4005a2c366a3947d7f4bc925fdbd6f4d91619f1 100644 (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);
index cd6abef3698c259dc9bce96c940e7349f63530c0..75dcf0045f3e83c194a079487ec5c7f2b18b96d1 100644 (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.");